Linux 有 watch 可以使用,在 MacOS X 也想要,要怎麼安裝?
註:watch 主要功能就是可以設定每幾秒鐘,執行某個指令,不斷執行
MacOSX 安裝 watch 程式
Mac 要安裝 watch,選項還蠻多種的,如下述:
使用 brew 或 ports 安裝 watch
- sudo port install watch
- sudo brew install watch # 若出現下述訊息,則需要再做下面的命令
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink .
/usr/local/Library/LinkedKegs is not writable. - sudo brew link watch
使用 Shell script 寫的 watch 程式
註:下述 Shell script 的 watch 程式,無法使用 | 來接更多命令
下述取自此篇:How do i repeate a unix command ever 5 seconds? | Apple Support Communities
- while :; do clear; your_command; sleep 3; done
下述取自此篇:atkinson.kiwi - Linux style 'watch' command on Mac OS X
#!/bin/bash # usage: watch.sh <your_command> <sleep_duration> while :; do clear; echo "$(date)" $1; sleep $2; done
下述取自此篇:OSX bash, 'watch' command - Stack Overflow
- alias myWatch='_() { while :; do clear; $2; sleep $1; done }; _'
相關網頁
- Install Watch Command on OS X
- osx - Is there a command like "watch" or "inotifywait" on the Mac? - Stack Overflow
- facebook watchman # 下述取自此篇:
- $ watchman watch ~/src
- $ watchman -- trigger ~/src buildme '*.css' -- minify-css