We're an ISO27001:2013 Certified Supplier


With a long-running command, perhaps running in the background, it can be helpful to keep an eye on progress. That’s where the  Linux watch command comes in useful.

watch takes a command as an argument, and every two seconds (by default) it clears the screen, prints a header line that includes the command and the current date and time, and prints the output of the command.

A Simple Example

Let’s say we’re copying all files from one partition to another. We know that the df command will show how full each partition is, so the command

$ watch df

will show us both how full the source partition is (presumably this won’t change), and how full the destination partition is, and thus we can see what progress is being made.

A Little More Complex

Let’s keep an eye on memory usage:

$ watch -d -n 10 free -m

This will run the free -m command every 10 seconds (-n 10), and any changes in the output will be highlighted for ten seconds (-d). Here’s what it looks like in action:

watch command

You can run piped commands as an argument to watch, but the argument must be single-quoted. The following will show the ten newest files in a directory:

$ watch 'ls -lt | head'

Was This Linux Tip Useful?

Let us know in the comments below.

Secure. Reliable. Scalable.

If that doesn't describe your current Linux systems, check out our FREE Linux Survival Guide to help you get your systems up to scratch today!
  • This field is for validation purposes and should be left unchanged.