How to Use the watch Command for Real-Time Command Monitoring

July 15, 2025 / Command Line

One of Linux’s most useful tools is the watch command, which lets users run a command repeatedly at fixed intervals and see the results in real time. It’s beneficial for keeping an eye on resource use, system status, or script results without having to manually rerun tasks.
This tutorial will describe the operation of the watch command, provide real-world examples, and cover helpful settings for more efficient monitoring.

The following explains when you need to use the watch command:

  1. To monitor disk space, CPU or memory usage.
  2. To track changes in files or directories.
  3. To continuously check system performance.
  4. To observe output from custom scripts or tools.

Simply, as an alternative to pressing the up-arrow and re-running the same command, “watch” automates the procedure and updates the output in real time.

Basic Syntax:
watch [options] command

  • command: The command you want to run continually.
  • options: Optional flags to change the behaviour of watch.

Common use cases of the watch command:

  1. Monitor disk space
    watch df -h

    Runs the “df -h” command every 2 seconds by default, showing real-time disk usage in a human-readable format.

  2. Check logged-in users
    watch who

    Continuously displays a live view of users currently logged into the system.

  3. Track the number of files in a directory
    watch “ls -1 /path/to/directory | wc -l”

    Useful for monitoring file activity, such as uploads or deletions, in a specific folder.

  4. Monitor system memory usage:
    watch free -m

    Displays the system’s memory usage in megabytes, updating every 2 seconds to reflect real-time changes.

Helpful watch Command Options:

  1. -n: Sets how often the command runs (default is every 2 seconds)
  2. -d: highlights change between updates for easy tracking
  3. -t: Suppresses the header (timestamp and command details)
  4. -c: Enables colour output if the command being run supports it.
Let's take an example: Monitor Disk Usage Every 5 Seconds with Highlighting
watch -n 5 -d df -h

Best Practices:

  • Use quotes when running complex or piped commands:
    watch “ps aux | grep apache”
  • Avoid short intervals for resource-heavy commands to prevent system load.
  • Enhance output monitoring by combining watch with tools like grep, awk, or cut for more precise and filtered results.

Troubleshooting:
watch: command not found

If the watch utility isn’t installed, you can add it using:

  • Ubuntu/Debian:
    sudo apt install procps
  • CentOS/RHEL:
    sudo yum install procps-ng

This is how you can effectively use the watch command for real-time command monitoring. If you need further assistance, don’t hesitate to reach out to our support team.

Want to monitor file changes too? Learn How to watch a directory for new file creation in Linux

Spread the love