Watch (Unix)
From DssWiki
{{DISPLAYTITLE:{{#if:|:|}}watch (Unix)}}
In Unix, watch runs the specified command 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.
Contents |
[edit] Syntax
watch [options] command [command options]
[edit] Example
watch "ps aux | grep php"
This will generate a list of processes 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 -l command to watch a file's size change, or running ps as in the above example to monitor certain processes continuously.
[edit] 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
[edit] See also
[edit] External links
||default}}|1|watch|url}} watch{{#if:{{Man/{{#if: ||default}}|1|watch|display_section}}|({{Man/{{#if: ||default}}|1|watch|display_section}})}}]{{#if:execute a program periodically, showing output fullscreen|: execute a program periodically, showing output fullscreen}}{{#if:{{#ifeq: |inline||{{Man/{{#if: ||default}}|1|watch|attrib}}}}| – {{#ifeq: |inline||{{Man/{{#if: ||default}}|1|watch|attrib}}}}}}
{{#if: |
Unix command line programs and builtins (more) | |||
| File and file system management: | cat | chattr | cd | chmod | chown | chgrp | cksum | cmp | cp | du | df | file | fsck | fuser | ln | ls | lsof | mkdir | mount | mv | pwd | rm | rmdir | split | touch | ||
| Process management: | at | chroot | crontab | exit | kill | killall | nice | pgrep | pidof | pkill | ps | sleep | time | top | wait | watch | ||
| User Management/Environment: | env | finger | id | mesg | passwd | su | sudo | uname | uptime | w | wall | who | whoami | write | ||
| Text processing: | awk | comm | cut | ed | ex | fmt | head | iconv | join | less | more | paste | pg | sed | sort | tac | tail | tr | uniq | wc | xargs | ||
| Shell programming: | basename | echo | expr | false | printf | test | true | unset | Printing: | lp |
| Communications: inetd | netstat | ping | rlogin | traceroute | Searching: find | grep | strings | Miscellaneous: banner | bc | cal | dd | man | size | yes | |
