watch command
monitors changes in command output
Typical usage: diagnosing problems, monitoring, troubleshootingIntroduction into watch
The watch command is one of those small Linux utilities that come in handy at times. It runs a command with a specified interval and shows its output. This is useful during troubleshooting, for example when you are interested in monitoring a directory for changes. Although you can define a ‘watch’ with the Linux Audit Framework, it is quicker to run this command instead.
Installation
When watch is not installed by default, it can be added to the system using the relevant software package.
Package information for watch
Operating system | Package name | Installation |
---|---|---|
AlmaLinux | procps-ng |
|
Arch Linux | procps-ng |
|
Debian | procps |
|
Fedora | procps-ng |
|
Red Hat Enterprise Linux | procps-ng |
|
Rocky Linux | procps-ng |
|
openSUSE | procps |
|
Ubuntu | procps |
|
Your Linux distribution using a different package? Share your feedback.
Usage
Available options
Long option | Short option | Description |
---|---|---|
--beep | -b | Beep on error (based on exit code) |
--differences[=permanent] | -d | Show the differences in output. When using the optional '=permanent', the differences between the original output and last refresh will stay marked. |
--no-title | -t | Don't use header with title, refresh interval, so only command output remains |
--no-wrap | -w | No wrapping of lines that are too long |
--version | -v | Show version information |
Missing an option in this overview? Share your feedback.
Examples using watch
File systems and directories
Show differences within a directory, mark items that changes
watch --differences=permanent ls -l
Monitor directory with most recently changed files on top
watch ls -alt
Monitor available disk space, especially useful during batch operations
watch df -h
Monitor current directory size (in megabytes)
watch du -sm
Monitor if a mount point is still in use
watch fuser --verbose --mount /mnt/backups
Networking
Show network connection statistics with a refresh every second
watch --interval=1 ss -s
Hardware
Monitor temperature changes (requires sensors command)
watch sensors
Frequently Asked Questions
What is the watch command and its purpose?
The watch command is a command-line tool to watch changes in the output of commands to assist with monitoring and troubleshooting.
Which package provides the watch command?
The command watch is provided by the procps or procps-ng package.
Related and similar commands
Linux has a lot of tools and commands available and sometimes you just need that little other tool. Here is a list of commands that are similar or related to watch:
Command | Category | Summary |
---|---|---|
basename | files | Strips directory and file name suffix from a given path |
chrt | processes | Sets Linux scheduler policy and priority for a process or command |
fuser | files and sockets | Show processes using a file or socket |
kill | processes | Sending signals to processes |
lsfd | files | Shows open file descriptors for processes |
nice | processes | Runs commands with specified priority |
numactl | processes | Controls NUMA policy for processes and shared memory |
peekfd | processes | Tracks a process and show file descriptor activity |
pidof | processes | Returns process IDs for a process name |
pidstat | monitoring | Monitoring CPU, memory, and disk activity |
pidwait | processes | Wait for process to stop |
pmap | processes | Shows memory mapping of process |
prtstat | processes | Shows process details for selected process like state, CPU and memory usage |
pscap | capabilities | Display available capabilities for running processes |
pslog | logging | Shows which log files a process has opened |
pstree | processes | Show active processes and children like a tree |
pwdx | processes | Shows current working directory of a process |
renice | processes | Changes the priority of running processes |
slabtop | memory | Shows slab usage of kernel |
smem | memory | Show memory usage including swap |
strace | process inspection | Inspects running process |
units | data conversion | Converts a unit into another one, like from Celcius to Fahrenheit |