Repeat a Command Every Few Seconds with watch

By | 2013/11/07

watch is a cool command that I need to use more often. Check it out!

Running watch < command > will by default keep repeating that command every two seconds. This is good for seeing the progress of a running process, viewing memory or disk usage, or checking various things from /proc. Here are some quick examples:

Memory usage:

$ watch free

Every 2.0s: free                                                             Thu Nov  7 20:31:06 2013

             total       used       free     shared    buffers     cached
Mem:       7891844    2899944    4991900          0     236708    1042052
-/+ buffers/cache:    1621184    6270660
Swap:      5105660          0    5105660

View the progress of a raid array being rebuilt:

$ watch cat /proc/mdstat

Every 2.0s: cat /proc/mdstat                                                        Thu Nov  7 09:47:46 2013

Personalities : [raid1]
md0 : active raid1 sda[2] sdb[1]
      976758841 blocks super 1.2 [2/1] [_U]
      [==================>..]  recovery = 92.4% (902988416/976758841) finish=102.3min speed=12012K/sec

Monitor disk usage:

$ watch du -h

Every 2.0s: df -h                                                            Thu Nov  7 17:54:16 2013

Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda        95G   29G   65G  31% /
none            202M  208K  202M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none           1007M     0 1007M   0% /run/shm

Clock for your terminal:

$ watch -n1 date


Rock on,

One thought on “Repeat a Command Every Few Seconds with watch


    the ‘-d‘ argument to `watch` is nice too. it will highlight the differences between successive updates. for example:

    # watch -d -n1 free -m


    # watch -n1 -d ps auwfx --sort=+%cpu

    nice stuff 😉


Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.