Home > linux > Linux watch command – an alternative to at/cron/while?

Linux watch command – an alternative to at/cron/while?

November 15th, 2010 Leave a comment Go to comments

So I just found out there is a command line binary called watch on Linux and well it’s surprisingly helpful, especially if you’re looking to run a command at regular intervals.

Normally, when I want to check a status of a directory or periodically check the netstat table, I write something like the following:

$ while true; do netstat -an | grep ; done

Now that I know about the watch command, I can simply do this instead:

$ watch netstat -an | grep 

The above command runs every 2 seconds, refreshing your screen.

Type man watch to see more examples and what else you can use it for.

Categories: linux Tags: ,