HowTo: Monitor Linux / BSD System Over Time Without Scrolling Output

by on March 27, 2006 · 3 comments· LAST UPDATED June 5, 2012

in

You can use the watch command to execute a program or shell script periodically, display its output on screen repeatedly. This allows you to watch the program output change over time. By default, the program is run every 2 seconds. This is useful to monitor memory utilization or disk space usage over time without having to look at scrolling output.

Say hello to watch command

The watch command execute a program periodically, showing output in fullscreen mode. It runs command repeatedly, displaying its output. You can install gnuwatch under OpenBSD or cmdwatch under FreeBSD (see the comments for more information) to get the same result.

watch command examples

To watch memory usage, enter:
watch free -m
To run free –m program every 5 seconds, enter:
watch -n 5 free -m
To watch disk space usage:
watch df -h
To watch the contents of a directory change, you could use
watch -d ls –l
Where,

  • The -d flag will highlight the differences between successive updates.
  • The –n {SECOND} flag use to specify a different interval.
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 3 comments… read them below or add one }

1 Anonymous September 22, 2006 at 7:48 pm

that doesnt work in bsd. im searching for the solution right now, just letting you know that watch in open and freebsd does something else than it does in linux

Reply

2 John February 27, 2007 at 6:35 am

For FreeBSD:

cd /usr/ports/sysutils/cmdwatch && make install clean

then substitute cmdwatch for watch as listed above.

The other BSD’s should be very similar.
The stock BSD watch is for snooping on other tty’s (which can be rather useful too :-D ).

But thx for this, it’s helpful to keep an eye on httpd errors, during web development, as well as busloads of other tasks.

Reply

3 David February 23, 2009 at 4:48 pm

In OpenBSD it’s the gnuwatch command. It can be installed as a package or through the ports system (misc/gnuwatch).

Reply

Leave a Comment

Tagged as: , , , , , , , , , ,

Previous post:

Next post: