Mr Dk.'s BlogMr Dk.'s Blog
  • 🦆 About Me
  • ⛏️ Technology Stack
  • 🔗 Links
  • 🗒️ About Blog
  • Algorithm
  • C++
  • Compiler
  • Cryptography
  • DevOps
  • Docker
  • Git
  • Java
  • Linux
  • MS Office
  • MySQL
  • Network
  • Operating System
  • Performance
  • PostgreSQL
  • Productivity
  • Solidity
  • Vue.js
  • Web
  • Wireless
  • 🐧 How Linux Works (notes)
  • 🐧 Linux Kernel Comments (notes)
  • 🐧 Linux Kernel Development (notes)
  • 🐤 μc/OS-II Source Code (notes)
  • ☕ Understanding the JVM (notes)
  • ⛸️ Redis Implementation (notes)
  • 🗜️ Understanding Nginx (notes)
  • ⚙️ Netty in Action (notes)
  • ☁️ Spring Microservices (notes)
  • ⚒️ The Annotated STL Sources (notes)
  • ☕ Java Development Kit 8
GitHub
  • 🦆 About Me
  • ⛏️ Technology Stack
  • 🔗 Links
  • 🗒️ About Blog
  • Algorithm
  • C++
  • Compiler
  • Cryptography
  • DevOps
  • Docker
  • Git
  • Java
  • Linux
  • MS Office
  • MySQL
  • Network
  • Operating System
  • Performance
  • PostgreSQL
  • Productivity
  • Solidity
  • Vue.js
  • Web
  • Wireless
  • 🐧 How Linux Works (notes)
  • 🐧 Linux Kernel Comments (notes)
  • 🐧 Linux Kernel Development (notes)
  • 🐤 μc/OS-II Source Code (notes)
  • ☕ Understanding the JVM (notes)
  • ⛸️ Redis Implementation (notes)
  • 🗜️ Understanding Nginx (notes)
  • ⚙️ Netty in Action (notes)
  • ☁️ Spring Microservices (notes)
  • ⚒️ The Annotated STL Sources (notes)
  • ☕ Java Development Kit 8
GitHub
  • 📝 Notes
    • Algorithm
      • Algorithm - Bloom Filter
      • Algorithm - Disjoint Set
      • Algorithm - Fast Power
      • Algorithm - KMP
      • Algorithm - Monotonic Stack
      • Algorithm - RB-Tree
      • Algorithm - Regular Expression
      • Algorithm - Sliding Window
      • Online Judge - I/O
    • C++
      • C++ - Const
      • C++ File I/O
      • C++ - Object Layout
      • C++ - Operator Overload
      • C++ - Polymorphism
      • C++ STL algorithm
      • C++ STL map
      • C++ STL multimap
      • C++ STL priority_queue
      • C++ STL set
      • C++ STL string
      • C++ STL unordered_map
      • C++ STL vector
      • C++ - Smart Pointer
      • C++ - Template & Genericity
    • Compiler
      • ANTLR - Basic
      • Compiler - LLVM Architecture
      • Compiler - Multi-version GCC
    • Cryptography
      • Cryptography - Certbot
      • Cryptography - Digital Signature & PKCS #7
      • Cryptography - GPG
      • Cryptography - JWT
      • Cryptography - Keystore & Certificates
      • Cryptography - OAuth 2.0
      • Cryptography - Java 实现对称与非对称加密算法
      • Cryptography - TLS
    • DevOps
      • DevOps - Travis CI
    • Docker
      • Docker - Image & Storage Management
      • Docker - Image
      • Docker - Libcontainer
      • Docker - Multi-Arch Image
      • Docker - Multi-Stage Build
      • Docker - Network
      • Docker - Orchestration & Deployment
      • Docker - Overview
      • Docker - Service Building
      • Docker - Volume & Network Usage
      • Docker - Volume
      • Linux - Control Group
      • Linux - Namespace
    • Git
      • Git - Branch & Merge
      • Git - Cached
      • Git - Cherry Pick
      • Git - Commit
      • Git - Patch
      • Git - Proxy
      • Git - Rebase
      • Git - Reset
      • Git - Stash
      • Git - Theme for Git-Bash
    • Java
      • JVM - Synchronized
      • JVM - Volatile
      • Java - Annotation 注解
      • Java - BIO & NIO
      • Java - Class Path
      • Java - Condition and LockSupport
      • Java - Current Timestamp
      • Java - Deep Copy
      • Java - 运行环境配置
      • Java - Equals
      • Java - Exporting JAR
      • Java - Javadoc
      • Java - Lock
      • Java - Maven 项目构建工具
      • Java - References
      • Java - Reflection Mechanism
      • Java - String Split
      • Java - Thread Pool
      • Java - Thread
      • Tomcat - Class Loader
      • Tomcat - Container
    • Linux
      • addr2line
      • cut
      • df
      • du
      • fallocate
      • find
      • fio
      • grep
      • groupadd
      • gzip
      • head / tail
      • hexdump
      • iostat
      • iotop
      • kill
      • ldd
      • lsof
      • ltrace / strace
      • mpstat
      • netstat
      • nm
      • pidstat
      • pmap
      • readlink
      • readlink
      • rpm2cpio / rpm2archive
      • sort
      • tee
      • uniq
      • useradd
      • usermod
      • watch
      • wc
      • which
      • xargs
    • MS Office
      • MS Office - Add-in Dev
      • MS Office - Application
    • MySQL
      • InnoDB - Architecture
      • InnoDB - Backup
      • InnoDB - Checkpoint
      • InnoDB - Critical Features
      • InnoDB - Files
      • InnoDB - Index
      • InnoDB - Insert Buffer
      • InnoDB - Lock
      • InnoDB - Partition Table
      • InnoDB - Table Storage
      • MySQL - Server Configuration
      • MySQL - Storage Engine
    • Network
      • Network - ARP
      • Network - FTP
      • Network - GitHub Accelerating
      • HTTP - Message Format
      • HTTP - POST 提交表单的两种方式
      • Network - Proxy Server
      • Network - SCP
      • Network - SSH
      • Network - TCP Congestion Control
      • Network - TCP Connection Management
      • Network - TCP Flow Control
      • Network - TCP Retransmission
      • Network - Traceroute
      • Network - V2Ray
      • Network - WebSocket
      • Network - Windows 10 Mail APP
      • Network - frp
    • Operating System
      • Linux - Kernel Compilation
      • Linux - Multi-OS
      • Linux - Mutex & Condition
      • Linux - Operations
      • Linux: Package Manager
      • Linux - Process Manipulation
      • Linux - User ID
      • Linux - Execve
      • OS - Compile and Link
      • OS - Dynamic Linking
      • OS - ELF
      • Linux - Image
      • OS - Loading
      • OS - Shared Library Organization
      • OS - Static Linking
      • Syzkaller - Architecture
      • Syzkaller - Description Syntax
      • Syzkaller - Usage
      • Ubuntu - Desktop Recover (Python)
      • WSL: CentOS 8
    • Performance
      • Linux Performance - Perf Event
      • Linux Performance - Perf Record
      • Linux Performance - Perf Report
      • Linux Performance - Flame Graphs
      • Linux Performance - Off CPU Analyze
    • PostgreSQL
      • PostgreSQL - ANALYZE
      • PostgreSQL - Atomics
      • PostgreSQL - CREATE INDEX CONCURRENTLY
      • PostgreSQL - COPY FROM
      • PostgreSQL - COPY TO
      • PostgreSQL - Executor: Append
      • PostgreSQL - Executor: Group
      • PostgreSQL - Executor: Limit
      • PostgreSQL - Executor: Material
      • PostgreSQL - Executor: Nest Loop Join
      • PostgreSQL - Executor: Result
      • PostgreSQL - Executor: Sequential Scan
      • PostgreSQL - Executor: Sort
      • PostgreSQL - Executor: Unique
      • PostgreSQL - FDW Asynchronous Execution
      • PostgreSQL - GUC
      • PostgreSQL - Locking
      • PostgreSQL - LWLock
      • PostgreSQL - Multi Insert
      • PostgreSQL - Plan Hint GUC
      • PostgreSQL - Process Activity
      • PostgreSQL - Query Execution
      • PostgreSQL - Spinlock
      • PostgreSQL - Storage Management
      • PostgreSQL - VFD
      • PostgreSQL - WAL Insert
      • PostgreSQL - WAL Prefetch
    • Productivity
      • LaTeX
      • Venn Diagram
      • VuePress
    • Solidity
      • Solidity - ABI Specification
      • Solidity - Contracts
      • Solidity - Expressions and Control Structures
      • Solidity - Layout and Structure
      • Solidity - Remix IDE
      • Solidity - Slither
      • Solidity - Types
      • Solidity - Units and Globally Available Variables
    • Vue.js
      • Vue.js - Environment Variable
    • Web
      • Web - CORS
      • Web - OpenAPI Specification
    • Wireless
      • Wireless - WEP Cracking by Aircrack-ng
      • Wireless - WPS Cracking by Reaver
      • Wireless - wifiphisher

watch

Created by : Mr Dk.

2022 / 10 / 29 11:35

Hangzhou, Zhejiang, China


Background

watch 命令能够周期性地执行一条命令,并全屏打印执行结果。这非常适合监控。默认周期为两秒。

Syntax

$ watch -h

Usage:
 watch [options] command

Options:
  -b, --beep             beep if command has a non-zero exit
  -c, --color            interpret ANSI color and style sequences
  -d, --differences[=<permanent>]
                         highlight changes between updates
  -e, --errexit          exit if command has a non-zero exit
  -g, --chgexit          exit when output from command changes
  -n, --interval <secs>  seconds to wait between updates
  -p, --precise          attempt run command in precise intervals
  -t, --no-title         turn off header
  -x, --exec             pass command to exec instead of "sh -c"

 -h, --help     display this help and exit
 -v, --version  output version information and exit

For more details see watch(1).

Usage

使用 -n 参数可以调整周期运行的时间间隔,-d 参数可以高亮本次运行和上次运行之间的差异。比如监控网络时:

$ watch -n 1 -d netstat

Every 1.0s: netstat                                                      nat: Sat Oct 29 11:27:31 2022

Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 nat:34510               169.254.0.55:http       ESTABLISHED
tcp        0      0 nat:56196               169.254.0.138:8186      ESTABLISHED
tcp        0      1 nat:53986               10.148.188.202:http     SYN_SENT
tcp        0      0 nat:ssh                 112.10.216.174:38489    ESTABLISHED
tcp        0      0 nat:39234               169.254.0.55:5574       ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ]         DGRAM                    120540811 /run/user/0/systemd/notify
unix  3      [ ]         DGRAM                    15934    /run/systemd/notify
...

另外,使用 -c 参数可以解释输出中的颜色信息,比如 neofetch:

$ watch neofetch

Every 2.0s: neofetch                                              zjt-lenovo: Sat Oct 29 11:24:55 2022

^[?25l^[?7l^[0m^[31m^[1m            .-/+oossssoo+/-.
        `:+ssssssssssssssssss+:`
      -+ssssssssssssssssssyyssss+-
    .ossssssssssssssssss^[37m^[0m^[1mdMMMNy^[0m^[31m^[1msssso.
   /sssssssssss^[37m^[0m^[1mhdmmNNmmyNMMMMh^[0m^[31m^[1mssssss/
  +sssssssss^[37m^[0m^[1mhm^[0m^[31m^[1myd^[37m^[0m^[1mMMMMMMMNddddy^[0m^[31m^[1mssssssss+
 /ssssssss^[37m^[0m^[1mhNMMM^[0m^[31m^[1myh^[37m^[0m^[1mhyyyyhmNMMMNh^[0m^[31m^[1mssssssss/
.ssssssss^[37m^[0m^[1mdMMMNh^[0m^[31m^[1mssssssssss^[37m^[0m^[1mhNMMMd^[0m^[31m^[1mssssssss.
+ssss^[37m^[0m^[1mhhhyNMMNy^[0m^[31m^[1mssssssssssss^[37m^[0m^[1myNMMMy^[0m^[31m^[1msssssss+
oss^[37m^[0m^[1myNMMMNyMMh^[0m^[31m^[1mssssssssssssss^[37m^[0m^[1mhmmmh^[0m^[31m^[1mssssssso
oss^[37m^[0m^[1myNMMMNyMMh^[0m^[31m^[1msssssssssssssshmmmh^[0m^[31m^[1mssssssso
+ssss^[37m^[0m^[1mhhhyNMMNy^[0m^[31m^[1mssssssssssss^[37m^[0m^[1myNMMMy^[0m^[31m^[1msssssss+
.ssssssss^[37m^[0m^[1mdMMMNh^[0m^[31m^[1mssssssssss^[37m^[0m^[1mhNMMMd^[0m^[31m^[1mssssssss.
 /ssssssss^[37m^[0m^[1mhNMMM^[0m^[31m^[1myh^[37m^[0m^[1mhyyyyhdNMMMNh^[0m^[31m^[1mssssssss/
  +sssssssss^[37m^[0m^[1mdm^[0m^[31m^[1myd^[37m^[0m^[1mMMMMMMMMddddy^[0m^[31m^[1mssssssss+
   /sssssssssss^[37m^[0m^[1mhdmNNNNmyNMMMMh^[0m^[31m^[1mssssss/
    .ossssssssssssssssss^[37m^[0m^[1mdMMMNy^[0m^[31m^[1msssso.
      -+sssssssssssssssss^[37m^[0m^[1myyy^[0m^[31m^[1mssss+-
        `:+ssssssssssssssssss+:`
            .-/+oossssoo+/-.^[0m
^[20A^[9999999D^[43C^[0m^[1m^[31m^[1mmrdrivingduck^[0m@^[31m^[1mzjt-lenovo^[0m
^[43C^[0m------------------------^[0m
^[43C^[0m^[31m^[1mOS^[0m^[0m:^[0m Ubuntu 22.04.1 LTS on Windows 10 x86_64^[0m
^[43C^[0m^[31m^[1mKernel^[0m^[0m:^[0m 5.10.16.3-microsoft-standard-WSL2^[0m
^[43C^[0m^[31m^[1mUptime^[0m^[0m:^[0m 1 hour, 5 mins^[0m
^[43C^[0m^[31m^[1mPackages^[0m^[0m:^[0m 780 (dpkg)^[0m
^[43C^[0m^[31m^[1mShell^[0m^[0m:^[0m zsh 5.8.1^[0m
^[43C^[0m^[31m^[1mTerminal^[0m^[0m:^[0m Windows Terminal^[0m

这都什么玩意儿啊?因为没有解析 ANSI 的颜色样式序列。加上 -c 以后:

$ watch -c neofetch

Every 2.0s: neofetch                                              zjt-lenovo: Sat Oct 29 11:25:31 2022

25l7l            .-/+oossssoo+/-.
        `:+ssssssssssssssssss+:`
      -+ssssssssssssssssssyyssss+-
    .ossssssssssssssssssdMMMNysssso.
   /ssssssssssshdmmNNmmyNMMMMhssssss/
  +ssssssssshmydMMMMMMMNddddyssssssss+
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/
.ssssssssdMMMNhsssssssssshNMMMdssssssss.
+sssshhhyNMMNyssssssssssssyNMMMysssssss+
ossyNMMMNyMMhsssssssssssssshmmmhssssssso
ossyNMMMNyMMhsssssssssssssshmmmhssssssso
+sssshhhyNMMNyssssssssssssyNMMMysssssss+
.ssssssssdMMMNhsssssssssshNMMMdssssssss.
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/
  +sssssssssdmydMMMMMMMMddddyssssssss+
   /ssssssssssshdmNNNNmyNMMMMhssssss/
    .ossssssssssssssssssdMMMNysssso.
      -+sssssssssssssssssyyyssss+-
        `:+ssssssssssssssssss+:`
            .-/+oossssoo+/-.
mrdrivingduck@zjt-lenovo
------------------------
OS: Ubuntu 22.04.1 LTS on Windows 10 x86_64
Kernel: 5.10.16.3-microsoft-standard-WSL2
Uptime: 1 hour, 6 mins
Packages: 780 (dpkg)
Shell: zsh 5.8.1
Terminal: Windows Terminal

References

  • watch(1) - Linux man page
Edit this page on GitHub
Prev
usermod
Next
wc