Watch
The watch
command is a utility that allows you to run a command repeatedly over time, displaying its output each time it runs. It’s often used to monitor system processes, network traffic, or file system activity.
Use cases:
- Monitoring a specific process: You can use
watch
to runps aux
every few seconds to see the list of running processes change. - Watching log files: Run
watch tail -f /var/log/syslog
to see new log messages as they appear. - Observing system resource usage: Use
watch top
orwatch htop
to monitor CPU, memory, and other resources in real-time.
Special hacks:
- To only run the command every 10 seconds when the screen is not updated (e.g., when the output doesn’t change), use
watch -n 10
. This can help save system resources. - Use
watch -d
to highlight any changes in the output, making it easier to spot differences.
Experience level:
The watch
command is suitable for users at an intermediate level (2-3 on a scale of 1-5). While beginners might find it useful, they may not fully understand its power and flexibility. More advanced users will appreciate the ability to combine watch
with other commands and filters.
Tips for beginners:
- Start by using simple commands like
watch ps aux
orwatch top
. - Experiment with different intervals (e.g.,
-n 5
,-n 10
) to find the right balance between update frequency and system resource usage. - Use
man watch
and explore online resources for more examples and use cases.