Sep
9
The watch command (Unix/Linux)
While attending a training class recently, I saw the instructor use the ‘watch’ command. What is does is clear the screen, echo the date/time, and execute the command you pass it. Very nice. For example:
watch ls /usr/local/pgsql/data/pg_xlog
lets you watch that directory for files to appear. If you need to pipe two commands together, put them together in quotes:
watch "ps auxww | grep postgres"
This is a very convenient replacement for how I USED to do this:
while (/bin/true)
do
clear
ps auxww | grep postgres
sleep 2
done
If you want to use it, check out the man page; there are some cool features for highlighting changes, either per execution or cumulatively from the start.