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 "awk '/Rss/{sum += \$2; } END{print sum, \"kB\"}' < /proc/$(pidof firefox)/smaps"
2015-09-19 00:36:34
User: gumnos
Functions: watch

Sometimes top/htop don't give the fine-grained detail on memory usage you might need. Sum up the exact memory types you want

watch -n 10 -d eval "sensors | grep RPM | sed -e 's/.*: *//;s/ RPM.*//'"
2015-04-07 14:28:32
User: omap7777
Functions: eval watch

Uses the lm-sensors package in Linux to display fan speed. Grep RPM is used to discover lines containing the text RPM, and sed is used to edit out everything but the RPM number. The watch utility is used to update the display every 10 seconds and -d highlights any changes from the previous value. The eval function of Bash is used to execute the command enclosed in the ".." string.

watch -n5 ss \| grep -c WAIT
2014-07-30 17:09:08
User: djpohly
Functions: grep watch
Tags: tcp ss iproute2

Uses the suggestions by jld on #12421 as well as the new iproute2 tools instead of old net-tools.

watch -n1 iptables -vnL
watch -n1 iptables -vnL
watch -n10 --no-title "w3m http://www.livescore.com/ |egrep 'live [0-9H]+[^ ]'"
2014-06-12 21:44:26
Functions: watch
Tags: bash livescore

World Cup Live Score of the ongoing match.

Alternative to have the live score with the match statistics:

watch -n10 --no-title "w3m http://www.livescore.com/ |awk '/live [0-9H]+[^ ]/,/red cards/'"
watch -n0.5 'ps -e -o pid,vsz,comm= | sort -n -k 2 | grep apache | wc -l'
watch ls -lh /path/to/folder
2014-03-27 10:51:36
User: vonElfensenf
Functions: ls watch
Tags: pv

forgot to use a pv or rsync and want to know how much has been copied.

watch -d -n 2 iptables -nvL
2014-02-23 16:35:03
User: xxdesmus
Functions: iptables watch

This will highlight (with a box over it) any changes since the last refresh.

watch -d "ls -l /proc/$!/fd"
2014-01-31 23:51:17
User: flatcap
Functions: watch

You're running a program that reads LOTS of files and takes a long time.

But it doesn't tell you about its progress.

First, run a command in the background, e.g.

find /usr/share/doc -type f -exec cat {} + > output_file.txt

Then run the watch command.

"watch -d" highlights the changes as they happen

In bash: $! is the process id (pid) of the last command run in the background.

You can change this to $(pidof my_command) to watch something in particular.

watch -n 10 free -m
2014-01-04 10:10:15
User: Darkstar
Functions: free watch

This command shows a high level overview of system memory and usage refreshed in seconds. Change -n 10 to you desired refresh interval.

watch -d 'echo -e "Remaining: `(nodetool netstats | grep " 0%" | wc -l)` \nCurrent: `(nodetool netstats | grep "%" | grep -v " 0%")`"'
2014-01-01 16:59:01
User: mrwulf
Functions: watch

When bootstrapping or repairing a node this is a simple way to keep tabs on what a node is actively doing.

watch -n1 dig google.com
watch -n 4 "tail -n $(expr $(tput lines) - 4) /var/log/apache2/access.log | cut -c 1-$(tput cols)"
2013-12-03 23:45:25
User: atw527
Functions: watch

This bash one-liner will let you watch the tail end of a log file in real time.

watch --interval 1 ls -lah
2013-10-16 10:41:15
User: c0r3dump3d
Functions: ls watch

Use this command if you want to control the size of the files in human readable, every one second.

watch -d -n 2 'df; ls -FlAt;'
watch -d "rabbitmqctl -q list_connections | awk '{gsub(/[ \t]+/, \"\", \$1); print \$1}' | sort | uniq -c | sort -nr"
2013-09-10 20:52:01
User: mrwulf
Functions: watch

Must have rabbitmqctl: https://www.rabbitmq.com/man/rabbitmqctl.1.man.html

See connections as the change, by user, sorted.

watch "netstat -plan | grep -v LISTEN | grep \":80 \" | awk {'print \$5'} | cut -d: -f 1 | uniq -c | sort -nk 1"
2013-09-05 13:50:00
User: simonsimcity
Functions: watch

Doesn't list connections to other ports than port 80. Not f.e. 8080 or 8091.

Excludes programs listening for connections, like your favorite webserver.

alias timer='export ts=$(date +%s);p='\''$(date -u -d @"$(($(date +%s)-$ts))" +"%H.%M.%S")'\'';watch -n 1 -t banner $p;eval "echo $p"'
2013-08-24 16:18:45
User: ichbins
Functions: alias banner date eval watch
Tags: timer banner

Starts and shows a timer. banner command is a part of the sysvbanner package. Instead of the banner an echo or figlet commands could be used. Stop the timer with Ctrl-C and elapsed time will be shown as the result.

watch 'php -r '"'"'$m=new Memcache;$m->connect("", 11211);print_r($m->getstats());'"'"
randchannelurl=$(lynx -dump http://www.tvcatchup.com/channels.html | grep watch | sed 's/^......//'| awk 'BEGIN { srand() } int(rand() * NR) == 0 { x = $0 } END { print x }') && firefox -new-window $randchannelurl
2013-08-01 10:38:10
User: dunryc
Functions: awk grep sed watch

becuase im lazy and cant be bothered looking at the tv guide to choose a channel , any improvments or comments appreciated

watch -n 1 'iostat -xmd 1 2'
2013-07-06 08:07:32
User: ryanchapman
Functions: watch
Tags: iostat

Shows a constantly updating display of disk IO activity. Two sections are in the output. The first is the IO activity since the machine was booted, the second section is the IO activity in the last second

watch -t -c -n30 'wget -q -O- "http://wwwapps.ups.com/WebTracking/processInputRequest?TypeOfInquiryNumber=T&InquiryNumber1=1Z4WYXXXXXXXXXX" | html2text | sed -n "/Shipment Progress/,/Shipping Information/p" | grep -v "*" | ccze -A'
watch 'ls -tr1 | tail -n1 | xargs tail'
2013-05-09 11:37:59
User: batandwa
Functions: tail watch xargs
Tags: tail ls xargs watch

Watches for file modifications in the current directory and tails the file.

watch "ls -al myfile"