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

Posted on in Categories Linux, UNIX last updated June 5, 2012

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

  • The -d flag will highlight the differences between successive updates.
  • The –n {SECOND} flag use to specify a different interval.

3 comment

  1. 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

  2. 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.

Leave a Comment