watch command

1 분 소요

linux의 watch 명령어는 특정 명령어를 반복하여 실행할 때 유용한 명령어 입니다.

$> watch -n 3 df

간단한 쉘스크립트를 이용해도 비슷한 효과를 볼 수 있습니다.

$> while true \n
do \n
df \n
sleep 3 \n
done

help watch

$> watch --help

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:
 uptime [options]

Options:
 -p, --pretty   show uptime in pretty format
 -h, --help     display this help and exit
 -s, --since    system up since
 -V, --version  output version information and exit

For more details see uptime(1).

tldr watch

$> tldr watch

  watch

  Execute a command repeatedly, and monitor the output in full-screen mode.

  - Monitor files in the current directory:
    watch ls

  - Monitor disk space and highlight the changes:
    watch -d df

  - Monitor "node" processes, refreshing every 3 seconds:
    watch -n 3 "ps aux | grep node"