Thursday, April 7, 2016

Linux Watch Command Example

Linux Watch Command Example

Watch is a simple command, with a few options. The basic syntax of watch command:

watch [-dhvt] [-n <seconds>] [--differences[=cumulative]] [--help] [--interval=<seconds>] [--no-title] [--version] <command>

Display errors/notices/warning being generated at run time every couple of seconds:
# watch tail /var/log/messages

Display disk usage after specified time interval.
# watch df -h

Display on server load and uptime at runtime.
# watch uptime

Let’s experience in difference between two successive outputs of “uptime” command repeated by watch.
#watch -n 20 -d uptime

Run free command for every 1/10 second
# watch -n 0.1 free

Display changes in output of a command with -d option of watch command.
# watch -d -n 1 free

Dont want to see time ticking at the start at watch screen, we can use -t to suppress it.
# watch -t free

Iteration delay
# watch [-n <seconds>] <command>

The default interval between the commands can be changed with -n switch. The following command will run the tail command after 5 seconds:
# watch -n 5 date

Successive output comparison

If you use -d option with watch command, it will highlight the differences between the first command output to every next command output cumulatively.

watch [-d or --differences[=cumulative]] <command>

Example
Let’s see the successive time outputs extracted using following watch command and observe how the difference is highlighted.
# watch -n 15 -d date
Output without title

If you don’t want to display extra details about the iteration delay and actual command run by watch then –t switch can be used.

watch [-t or --no-title] <command>

Let’s see the output of following command as an example.
# watch -t date

How can I find mounted partitions in my machine

Use below commands to know more about the mount points
cat /etc/mtab
df -h

No comments:

Post a Comment