Ever wanted to monitor a directory every second and see differences in filesizes per second? Or for that matter, run any program once a second and highlight differences in time? Well you can, and you have been able to since forever as it’s installed by default on the majority of Linux distributions. watch is part of the procps package, available in Debian and Ubuntu.
Here is an example for checking a directory:
watch ls -l
To highlight changes in each program run, you can use the -d flag:
watch -d ls -l
And to run the command every N seconds, use -nN (by default, watch runs every 2 seconds):
watch -n1 -d ls -l
Finally, to make the diff highlighting “sticky” (i.e. stay on permanently after a change is detected), use: -d=cumulative
- Watch your log directory for changes
watch -d=cumulative -n1 ls -lt /var/log
- Watch for new email
watch -n60 from
- Monitor free memory
watch -n10 free -m
- Monitor established connections
watch -n1 -d 'netstat -an | grep ESTABLISHED'
… you get the point. If you’re a system administrator, or just maintain Linux machines in general you’ll probably spot a bunch of places where you can use this straight away.