Commands using watch (140)

  • To monitor .vmdk files during snapshot deletion (commit) on ESX only (ESXi doesn't have the watch command): 1. Navigate to the VM directory containing .vmdk files. # watch "ls -tough --full-time *.vmdk" where: -t sorts by modification time -o do not list group information (to narrow the output) -u sorts by access time -g only here for the purpose to easily remember the created mnemonic word 'tough' -h prints sizes in human readable format (e.g., 1K 234M 2G) --full-time sets the time style to full-iso and does not list user information (to narrow the output) optionally useful parameters to the watch command: -d highlight changes between updates -n seconds to wait between updates (default is 2) -t turn off printing the header

    watch 'ls -tough --full-time *.vmdk'
    vRobM · 2010-08-20 17:28:28 0
  • Change HH:MM with your target time. This is for a Debian/Ubuntu GNU system. You need bash (package bash), date (package coreutils) and toilet (package toilet). Install with: # apt-get install bash coreutils toilet toilet-fonts

    watch -tn1 'date -u +%T -d @$(expr $(date -d HH:MM +%s) - $(date +%s)) | toilet -f bigmono12'
    prayer · 2010-06-26 11:56:11 0
  • Figlet is easy to find for download on the internet, and works for any text. Quite cool. Show Sample Output

    watch -tn1 'date +%r | figlet'
    SuperFly · 2010-06-22 10:59:16 1
  • This command shows the size of directories below here, refreshing every 2s. It will also track directories created after running the command (that what the find bit does). Show Sample Output

    watch 'find -maxdepth 1 -mindepth 1 -type d |xargs du -csh'
    shadycraig · 2010-05-19 13:13:57 4
  • Show active calls as the happen on an Asterisk server. Note that the Asterisk command (in single quotes) is formatted for Asterisk 1.6. Use the -n flag on the watch command to modify the refresh period (in seconds - default is 2 seconds). Show Sample Output

    watch -n 1 "sudo asterisk -vvvvvrx 'core show channels' | grep call"
    mheadd · 2010-03-26 15:42:13 0
  • -n means refresh frequency you could change eth0 to any interface you want, like wlan0 Show Sample Output

    watch -n1 'ifconfig eth0|grep bytes'
    qiaomuf · 2010-03-20 03:24:26 1
  • Show a simple table with disk IO for the specified host. you monitor a LOT of different thing. Mostly used for MRTG and similar, but this is nice for a quick look, which disk is busy. "public" is your SNMP community ensure that snmpd is running on the host which you intend to monitor Show Sample Output

    watch -n1 snmptable -v2c -c public localhost diskIOTable
    oernii2 · 2010-03-19 11:31:52 0
  • It's not my code, but I found it useful to know how many open connections per request I have on a machine to debug connections without opening another http connection for it. You can also decide to sort things out differently then the way it appears in here. Show Sample Output

    watch "netstat -plan|grep :80|awk {'print \$5'} | cut -d: -f 1 | sort | uniq -c | sort -nk 1"
    ik_5 · 2010-03-15 09:27:43 2

  • -1
    watch -n 7 -d 'uptime | sed s/.*users?, //'
    matthewbauer · 2010-01-17 18:45:52 0
  • You can substitute /home/$USER with any path you like.

    watch -n1 "du -hs /home/$USER | cut -f1 -d'/' | figlet -k"
    cviorel · 2010-01-07 07:30:59 3
  • Useful with new unknown devices or just monitoring, probably useful for the sysadmin. Updates every 2 seconds. More here:

    watch 'dmesg | tail -15'
    Heoa · 2009-12-20 02:00:05 0
  • I wanted to create a copy of my whole laptop disk on an lvm disk of the same size. First I created the logical volume: lvcreate -L120G -nlaptop mylvms SOURCE: dd if=/dev/sda bs=16065b | netcat ip-target 1234 TARGET: nc -l -p 1234 | dd of=/dev/mapper/mylvms-laptop bs=16065b to follow its process you issue the following command in a different terminal STATS: on target in a different terminal: watch -n60 -- kill -USR1 $(pgrep dd) (see

    SOURCE: dd if=/dev/sda bs=16065b | netcat ip-target 1234 TARGET: netcat -l -p 1234 | dd of=/dev/mapper/laptop bs=16065b STATS on target: watch -n60 -- kill -USR1 $(pgrep dd)
    bw · 2009-12-16 10:51:06 0
  • if you start a large dd and forgot about statistics, but you still wonder what the progress is this command in an OTHER terminal will show you the way. NOTE: the watch command by itself will not output anything NOTE: the kill command will not kill the process Show Sample Output

    watch -n60 --kill -USR1 $(pgrep dd)
    bw · 2009-12-16 10:35:28 1
  • This command is a great way to check to see if acpi is doing damage to your disks by agressivly parking the read arm and wearing down it's life. As you can see, mine has lost half its life. I'm sure this could be shortened though somehow. It will use smartctl to dump the stats and then grep out just the temperature and load cycles for the disk (a load cycle is when a the read arm comes out of park and wears on the drive). Show Sample Output

    watch -d 'sudo smartctl -a /dev/sda | grep Load_Cycle_Count ; sudo smartctl -a /dev/sda | grep Temp'
    vxbinaca · 2009-12-15 00:15:24 0

  • 1
    watch -n 1 -d "finger"
    tsiqueira · 2009-12-08 14:53:18 0
  • Monitor with watch command and vmstat, memory usage Show Sample Output

    watch vmstat -sSM
    servermanaged · 2009-12-04 22:35:45 0
  • On my cluster a D in the states column means it is time to reboot the server.

    watch -n 1 "ps aux | sed -n 's/ D /&/p'"
    lunarblu · 2009-12-03 18:22:44 0
  • If you just executed some long command, like "ps -aefww | grep -i [m]yProcess", and if you don't want to retype it or cycle backwards in history and waste time quoting it, then you can use history substitution.

    watch -n1 -d !!
    TeacherTiger · 2009-11-24 21:01:14 0
  • Create a binary clock. Show Sample Output

    watch -n 1 'echo "obase=2;`date +%s`" | bc'
    matthewbauer · 2009-11-04 02:04:00 5

  • 1
    watch -n 60 du /var/log/messages
    rbossy · 2009-10-27 14:53:41 0
  • already described on the other two versions, this one uses ascii characters on game style to display elapsed time. Show Sample Output

    export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds) | toilet -f shadow'
    m33600 · 2009-10-23 07:56:30 0
  • Variation of the theme, this one blinks in low profile on top level of X, ie, it is visible, indeed small. Try changing fonts and sizes of osd_cat

    export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds) | osd_cat -o 20 -d 1 -p bottom'
    m33600 · 2009-10-23 07:47:11 0
  • Works on real time clock, unix time based, decrementing the actual time from initial time saved in an environment variable exported to child process inside watch Shows elapsed time from start of script in hh:mm:ss format Non afected by system slow down due to the use of date.

    export I=$(date +%s); watch -t -n 1 'T=$(date +%s);E=$(($T-$I));hours=$((E / 3600)) ; seconds=$((E % 3600)) ; minutes=$((seconds / 60)) ; seconds=$((seconds % 60)) ; echo $(printf "%02d:%02d:%02d" $hours $minutes $seconds)'
    m33600 · 2009-10-23 07:31:44 1
  • This time I added a print to reemaining energy, every minute, time stamped. The example shown here is complete and point to large discrepancies as time passes, converging to accuracy near the end. Show Sample Output

    echo start > battery.txt; watch -n 60 'date >> battery.txt ; acpi -b >> battery.txt'
    m33600 · 2009-10-19 05:28:15 0
  • Fully recharge your computer battery and start this script. It will create or clean the file named battery.txt, print a start on it and every minute it will append a time stamp to it. Batteries last few hours, and each hour will have 60 lines of time stamping. Really good for assuring the system was tested in real life with no surprises. The last time stamp inside the battery.txt file is of interest. It is the time the computer went off, as the battery was dead! Turn on your computer after that, on AC power of course, and open battery.txt. Read the first and last time stamps and now you really know if you can trust your computer sensors. If you want a simple line of text inside the battery.txt file, use this: watch -n 60 'date > battery.txt' The time of death will be printed inside Show Sample Output

    echo start > battery.txt; watch -n 60 'date >> battery.txt'
    m33600 · 2009-10-18 07:00:26 0
  • ‹ First  < 2 3 4 5 6 > 

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: