What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Commands using watch from sorted by
Terminal - Commands using watch - 132 results
watch -n 7 -d 'uptime | sed s/.*users?, //'
watch -n1 "du -hs /home/$USER | cut -f1 -d'/' | figlet -k"
2010-01-07 07:30:59
User: cviorel
Functions: watch

You can substitute /home/$USER with any path you like.

watch 'dmesg | tail -15'
2009-12-20 02:00:05
User: Heoa
Functions: tail watch

Useful with new unknown devices or just monitoring, probably useful for the sysadmin. Updates every 2 seconds. More here: http://linuxclisecurity.blogspot.com/2009/12/monitor-kernel-ring-buffer.html.

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)
2009-12-16 10:51:06
User: bw
Functions: dd kill watch

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 http://www.commandlinefu.com/commands/view/4356/output-stats-from-a-running-dd-command-to-see-its-progress)

watch -n60 --kill -USR1 $(pgrep dd)
2009-12-16 10:35:28
User: bw
Functions: watch

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

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

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).

watch -n 1 -d "finger"
watch vmstat -sSM
2009-12-04 22:35:45
Functions: vmstat watch

Monitor with watch command and vmstat, memory usage

watch -n 1 "ps aux | sed -n 's/ D /&/p'"
2009-12-03 18:22:44
User: lunarblu
Functions: watch

On my cluster a D in the states column means it is time to reboot the server.

watch -n1 -d !!
2009-11-24 21:01:14
User: TeacherTiger
Functions: watch

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 -n 1 'echo "obase=2;`date +%s`" | bc'
watch -n 60 du /var/log/messages
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'
2009-10-23 07:56:30
User: m33600
Functions: date echo export printf watch

already described on the other two versions, this one uses ascii characters on game style to display elapsed time.

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'
2009-10-23 07:47:11
User: m33600
Functions: date echo export printf watch

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)'
2009-10-23 07:31:44
User: m33600
Functions: date echo export printf watch

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.

echo start > battery.txt; watch -n 60 'date >> battery.txt ; acpi -b >> battery.txt'
2009-10-19 05:28:15
User: m33600
Functions: acpi echo watch

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.

echo start > battery.txt; watch -n 60 'date >> battery.txt'
2009-10-18 07:00:26
User: m33600
Functions: echo watch

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

watch -n60 du /var/log/messages
2009-10-09 18:37:45
User: matrixguy
Functions: du watch

use "watch" instead of while-loops in these simple cases

watch -n <seconds> <command>
watch -d 'ls -l'
2009-09-03 20:12:36
User: 0disse0
Functions: watch
Tags: watch stats

To highlight the difference between screen updates

watch 'cat /proc/loadavg'
2009-09-03 20:10:46
User: 0disse0
Functions: watch
Tags: status watch

If you need to keep an eye on a command whose output is changing, use the watch command. For example, to keep an eye on your load average

watch --interval 0 'iptables -nvL | grep -v "0 0"'
2009-08-22 18:18:05
User: Code_Bleu
Functions: grep watch

This will allow you to watch as matches occur in real-time. To filter out only ACCEPT, DROP, LOG..etc, then run the following command: watch 'iptables -nvL | grep -v "0 0" && grep "ACCEPT"' The -v is used to do an inverted filter. ie. NOT "0 0"

watch -n .5 "iwlist wlan0 scan"
2009-08-20 23:05:04
User: Abiden
Functions: watch

If you're like some individuals who rely on ndiswrapper and cannot use kismet, this command may be of service.

watch -n .5 "iwlist wlan0 scan | egrep 'ESSID|Encryption'"


watch -n .5 "iwlist wlan0 scan | egrep 'ESSID|Encryption' | egrep 'linksys'"

:-) Hopefully you'll find some dd-wrt compatible routers.

watch() { t=$1; shift; while test :; do clear; date=$(date); echo -e "Every "$t"s: $@ \t\t\t\t $date"; $@; sleep $t; done }
watch() { while test :; do clear; date=$(date); echo -e "Every "$1"s: $2 \t\t\t\t $date"; $2; sleep $1; done }