Use of Linux watch command

Use of Linux watch command

1. Command Introduction

The watch command executes the given command in a periodic manner and displays the execution results on the full screen.

watch is a very useful command that comes with almost all Linux distributions. As the name suggests, watch can help monitor the running results of a command, saving us from running it manually over and over again. For example, tail a log file, ls monitors the size change of a file, etc. By default, the program runs every 2 seconds. You can use -n or --interval to specify the interval.

2. Command format

watch [OPTIONS] COMMAND

3. Option Description

-d, --differences [PERMANENT]
 Highlights the differences between the two most recent updates. -d cumulative option will highlight the changes (regardless of whether the most recent one has changed) -n, --interval SECONDS
 Specify the monitoring interval in seconds. The default value is 2s and cannot be lower than 0.1s
-p, --precise
 Try to monitor the command exactly at the specified interval -t, --no-title
 Turn off the output of the watch command at the top of the interval, command, and current time -b, --beep
 Beep when the exit code of the monitored command is non-zero -e, --errexit
 When an error occurs in the monitored command, watch stops updating and exits after pressing the key -g, --chgexit
 Exit watch when the monitored command output changes
-c, --color
 Interpret ANSI color and style sequences -x, --exec
 Pass the command to exec(2) instead of sh -c
-h, --help
 Display help information and exit -v, --version
 Display version information and exit

4. Common Examples

(1) Repeat the uptime command, by default it is executed every 2 seconds.

watch uptime

(2) Check the changes in the current directory file log.

watch -d "ls -l | grep log"

Note that when the monitored command contains a pipe, it needs to be enclosed in quotes.

(3) Check the average load of the system every 10 seconds.

watch -n10 cat /proc/loadavg

(4) Highlight the changes in the number of network connections every 1 second.

watch -n1 -d netstat -ant

References
[1] watch(1) manual

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Logwatch Command in Linux
  • Introduction to Linux software watchdog watchdog
  • Simple and efficient: Linux log analysis with Swatch

<<:  MySQL index usage monitoring skills (worth collecting!)

>>:  How to implement the Vue mouse wheel scrolling switching routing effect

Recommend

Detailed explanation of for loop and double for loop in JavaScript

for loop The for loop loops through the elements ...

How to add sudo permissions to a user in Linux environment

sudo configuration file The default configuration...

Use CSS to create 3D photo wall effect

Use CSS to create a 3D photo wall. The specific c...

25 fresh useful icon sets for download abroad

1. E-Commerce Icons 2. Icon Sweets 2 3. Mobile Ph...

Summary of MySQL Undo Log and Redo Log

Table of contents Undo Log Undo Log Generation an...

How to remove the dotted border when clicking a link in FireFox

I encountered several browser compatibility issue...

MYSQL Left Join optimization (10 seconds to 20 milliseconds)

Table of contents 【Function Background】 [Raw SQL]...

33 ice and snow fonts recommended for download (personal and commercial)

01 Winter Flakes (Individual only) 02 Snowtop Cap...

Write a publish-subscribe model with JS

Table of contents 1. Scene introduction 2 Code Op...

Use jQuery to fix the invalid page anchor point problem under iframe

The application scenario is: the iframe page has n...

Detailed explanation of MYSQL large-scale write problem optimization

Abstract: When people talk about MySQL performanc...

The phenomenon of margin-top collapse and the specific solution

What is margin-top collapse Margin-top collapse i...

How to change mysql password under Centos

1. Modify MySQL login settings: # vim /etc/my.cnf...