Watch (Unix)
Encyclopedia
watch is a GNU command-line tool that runs the specified command
Command (computing)
In computing, a command is a directive to a computer program acting as an interpreter of some kind, in order to perform a specific task. Most commonly a command is a directive to some kind of command line interface, such as a shell....

 repeatedly and displays the output on stdout so you can watch it change over time. By default, the command is run every 2 seconds, although this is adjustable with the -n secs argument. Since the command is passed to sh -c, you may need to encase it in quotes for it to run correctly.

Example

watch "ps
Ps (Unix)
In most Unix-like operating systems, the ps program displays the currently-running processes. A related Unix utility named top provides a real-time view of the running processes....

 aux | grep php"
This will generate a list of process
Process (computing)
In computing, a process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system , a process may be made up of multiple threads of execution that execute instructions concurrently.A computer program is a...

es every 2 seconds, filter for all lines that contain the word "php", and display the results on the screen. The output might look something like this:

Every 2s: ps aux | grep php Tue Jan 30 14:56:33 2007

reconst 30028 0.0 0.0 7044 2596 ? S Jan23 0:00 vim -r core/html_api.php
cinonet 28009 0.0 0.2 20708 11064 ? SN Jan25 0:30 php5.cgi
donoiz 23810 0.0 0.2 22740 10996 ? SN Jan27 0:30 php.cgi 43/pdf

The watch command is useful for viewing changes over time, like repeatedly running the ls
Ls
In computing, ls is a command to list files in Unix and Unix-like operating systems. ls is specified by POSIX and the Single UNIX Specification.- History :An ls utility appeared in the original version of AT&T UNIX...

-l
command to watch a file's size change, or running ps as in the above example to monitor certain processes continuously.

Arguments

  • -d – Highlights differences between iterations
  • -h – Displays a help message, then exits
  • -n secs – Specifies the interval between executions of the command in seconds
  • -t – Tells watch not to display the header
  • -v – Prints version information, then exits
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK