watch

The output results of the command can be output to the standard output device, which is mostly used to execute commands periodically/scheduledly.

Supplementary instructions

watch command executes the given instruction in a periodic manner, and the instruction output is displayed in full screen mode. Watch is a very practical command. Basically all Linux distributions come with this small tool. As the name suggests, watch can help you monitor the running results of a command, saving you from having to run it manually over and over again.

grammar

watch(option)(parameter)

Options

-n # or --interval watch runs the program every 2 seconds by default. You can use -n or -interval to specify the interval time.
-d # or --differences Using the -d or --differences option watch will highlight the changed areas. The -d=cumulative option will highlight changes (regardless of whether there were changes in the most recent one).
-t # or -no-title will turn off the time interval, command, and current time output of the watch command at the top.
-h, --help # View help documentation

Parameters

Instructions: Instructions that need to be executed periodically.

Example

watch -n 1 -d netstat -ant # Command: Highlight changes in the number of network links every second
watch -n 1 -d 'pstree|grep http' # Highlight changes in the number of http links every second. If the following command contains a pipe character, you need to add '' to organize the command area.
watch 'netstat -an | grep:21 | \ grep<IP of the simulated attack client>| wc -l' # View the number of connections established by the simulated attack client in real time
watch -d 'ls -l|grep scf' # Monitor changes in the files of scf' in the current directory
watch -n 10 'cat /proc/loadavg' # Output the average load of the system every 10 seconds
watch uptime
watch -t uptime
watch -d -n 1 netstat -ntlp
watch -d 'ls -l | fgrep goface' # Monitor goface files
watch -t -differences=cumulative uptime
watch -n 60 from # Monitor mail
watch -n 1 "df -i;df" # Monitor changes in the number of disk inodes and blocks

The difference between the watch command under FreeBSD and Linux is that under Linux, watch periodically executes the next program and displays the execution results in full screen, such as: watch -n 1 -d netstat -ant, while the watch command under FreeBSD It is to view the running operations of other users. watch allows you to peek at what other terminals are doing. This command can only be used by super users.