QA
Intermediate LevelLinux Commands & SysAdmin

How does the watch command execute commands repeatedly at fixed intervals (watch -n 2 df -h)?

❓ Interview Prompt: Explain watch command, execution interval (-n), highlighting changes (-d), and monitoring system state.

The 'watch' command executes a specified CLI command periodically at fixed time intervals, displaying the output on a full-screen terminal window:

Options:

•
'-n 2': Set update interval in seconds (default is 2 seconds).
•
'-d': Highlight differences between consecutive updates.

Code Implementation Example

bash
# Monitor free memory and highlighting changes every 1 second
watch -n 1 -d free -h

# Monitor active network connections on port 80
watch -n 2 "ss -tulpn | grep :80"
💡Periodically executing CLI commands using watch -n.
🎯 Interview Key Takeaway

Use watch -n <sec> -d to monitor changing command outputs (memory, disk, connections) in real-time.

#watch#CLI Monitoring#SysAdmin#Intermediate
Back to all Linux Commands & SysAdmin Questions→

More Linux Commands & SysAdmin Interview Questions

Beginner LevelLinux Commands & SysAdmin

How do Linux File Permissions (chmod, chown, chgrp) work in Octal and Symbolic notation?

Beginner LevelLinux Commands & SysAdmin

What is the Linux Filesystem Hierarchy Standard (/bin, /etc, /var, /usr, /opt, /tmp)?

Beginner LevelLinux Commands & SysAdmin

What are File Descriptors (0=stdin, 1=stdout, 2=stderr) and Redirection (>, >>, 2>&1)?