ISO27001:2013
Certified Supplier

FIND OUT MORE

We're an ISO27001:2013 Certified Supplier

blog-post-featured-image

With a long-running command, perhaps running in the background, it’s sometimes helpful to keep an eye on progress. For this, the watch command can be 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:

…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:

This will run the free -m command every 10 seconds (-n 10), and any differences in the output changes it will be highlighted for ten seconds (-d).

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:

Built In

Some Linux administrators cobble together quick bash scripts to keep an eye on the output of a command, but watch does that more efficiently. A good tool for the toolbox.

Photo by Paul Gilmore on Unsplash

Leave a Reply

Your email address will not be published. Required fields are marked *