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



All commands from sorted by
Terminal - All commands - 12,422 results
sed -n 's/.*<foo>\([^<]*\)<\/foo>.*/\1/p'
2009-07-23 07:59:30
User: recursiverse
Functions: sed

Limited, but useful construct to extract text embedded in XML tags. This will only work if bar is all on one line.

If nobody posts an alternative for the multiline sed version, I'll figure it out later...

tail -F file
2009-07-23 07:37:11
User: recursiverse
Functions: tail
Tags: tail logs

If you use 'tail -f foo.txt' and it becomes temporarily moved/deleted (ie: log rolls over) then tail will not pick up on the new foo.txt and simply waits with no output.

'tail -F' allows you to follow the file by it's name, rather than a descriptor. If foo.txt disappears, tail will wait until the filename appears again and then continues tailing.

[[ "$WINDOW" ]] && PS1="\[email protected]\h:\w[$WINDOW]\$ "
2009-07-23 06:46:19
User: recursiverse
Tags: bash screen shell

Add this to your $HOME/.bashrc file. It will only set this prompt if it is running inside screen ($WINDOW var is set)

Looks like this...

[email protected]:~[2]$
awk '{print NR": "$0; for(i=1;i<=NF;++i)print "\t"i": "$i}'
2009-07-23 06:25:31
User: recursiverse
Functions: awk
Tags: awk

Breaks down and numbers each line and it's fields. This is really useful when you are going to parse something with awk but aren't sure exactly where to start.

ssh -t remote_host screen -r
2009-07-23 06:15:04
User: recursiverse
Functions: screen ssh
Tags: ssh screen

Directly attach a remote screen session (saves a useless parent bash process)

tar c folder_to_encrypt | openssl enc -aes-256-cbc -e > secret.tar.enc
2009-07-23 06:03:39
User: recursiverse
Functions: c++ tar

command to decrypt:

openssl enc -aes-256-cbc -d < secret.tar.enc | tar x

Of course, don't forget to rm the original files ;) You may also want to look at the openssl docs for more options.

explorer $( cygpath "/path/to/file_or_exe" -w )
2009-07-22 17:00:21
User: Highwayman

This executes faster than


I put this in a script and added it to my path:

cat `which explore.sh`


if [ $# -eq 0 ]; then

explorer.exe $( cygpath `pwd` -w ) &


explorer.exe $( cygpath $1 -w ) &


Using the script you just type

explore.sh file_or_executable

Note: you can do this for any file that has an associated executable in the windows registry. This is quite handy if you want to open pictures or movies from xterm.

$ awk '{ split(sprintf("%1.3e", $1), b, "e"); p = substr("yzafpnum_kMGTPEZY", (b[2]/3)+9, 1); o = sprintf("%f", b[1] * (10 ^ (b[2]%3))); gsub(/\./, p, o); print substr( gensub(/_[[:digit:]]*/, "", "g", o), 1, 4); }' < test.dat
2009-07-22 16:54:14
User: mungewell
Functions: awk
Tags: awk

converts any number on the 'stdin' to SI notation. My version limits to 3 digits of precious (working with 10% resistors).

lynx -dump http://www.ip-adress.com/ip_tracer/?QRY=$1|sed -nr s/'^.*My IP address city: (.+)$/\1/p'
ls -drt /var/log/* | tail -n5 | xargs sudo tail -n0 -f
2009-07-22 14:44:41
User: kanaka
Functions: ls sudo tail xargs
Tags: bash tail log watch

This command finds the 5 (-n5) most frequently updated logs in /var/log, and then does a multifile tail follow of those log files.

Alternately, you can do this to follow a specific list of log files:

sudo tail -n0 -f /var/log/{messages,secure,cron,cups/error_log}

lomount -diskimage /path/to/your/backup.img -partition 1 /mnt/foo

Instead of calculating the offset and providing an offset option to mount, let lomount do the job for you by just providing the partition number you would like to loop mount.

ip addr|grep "inet "
2009-07-22 07:38:06
User: RickDeckardt
Functions: grep

Shows a single line per interface (device), with its IPv4 settings.

Shorter command, better readability in output.

curl -u 'username' https://api.del.icio.us/v1/posts/all | sed 's/^.*href=//g;s/>.*$//g;s/"//g' | awk '{print $1}' | grep 'http'
2009-07-22 07:32:59
User: bubo
Functions: awk grep sed

a variation of avi4now's command - thanks by the way!

/sbin/ifconfig | grep inet | cut -f 2 -d ":" | cut -f 1 -d " " |egrep -v "^$"
while true ; do IFS="" read i; echo "$i"; sleep .01; done < <(tr -c "[:digit:]" " " < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR="1;32" grep --color "[^ ]")
2009-07-22 03:59:07
Functions: dd echo grep read sleep tr true
Tags: color

Same as above but slooooow it down

/sbin/ifconfig | grep inet | cut -f 2 -d ":" | cut -f 1 -d " "
2009-07-21 21:42:04
User: random_bob
Functions: cut grep

another way to output the IP address' of the system

for i in `git log --all --oneline --format=%h`; do git grep SOME_STRING $i; done
/sbin/ifconfig | awk -F'[ :]+' '/inet addr/{print $4}'
2009-07-21 14:18:17
User: inof
Functions: awk

That one works on Linux. On BSD and Solaris, the ifconfig output is much easier to parse:

/sbin/ifconfig -a | awk '/inet/{print $2}'
alias restart='apache2ctl configtest && apache2ctl restart'
2009-07-21 14:13:15
Functions: alias

making lots of configurations to apache and restarting the server only to find it broken just plain sucks.

/sbin/ifconfig eth0 | grep "inet addr" | sed -e 's/.*inet addr:\(.*\) B.*/\1/g'
ifconfig $DEVICE | perl -lne '/inet addr:([\d.]+)/ and print $1'
2009-07-21 13:48:19
User: jdob
Functions: ifconfig perl
Tags: IP

Found this useful for scripts where I needed to work with the machine's IP. If $DEVICE is not specified, this will return all IPs on the machine. If $DEVICE is set to a network adapter, it will return just that adapter's IP.

alias grip="grep -i"
2009-07-21 11:12:15
User: inof
Functions: alias

This is *NOT* about the -i option in grep. I guess everybody already knows that option. This is about the basic rule of life that the simplest things are sometimes the best. ;-)

One day when I used "grep -i" for the umpteenth time, I decided to make this alias, and I've used it ever since, probably more often than plain grep. (In fact I also have aliases egrip and fgrip defined accordingly. I also have wrip="grep -wi" but I don't use this one that often.)

If you vote this down because it's too trivial and simplistic, that's no problem. I understand that. But still this is really one of my most favourite aliases.

alias sucs="sort | uniq -c | sort -n"
2009-07-21 10:55:06
User: inof
Functions: alias

This alias finds identical lines in a file (or pipe) and prints a sorted count of them (the name "sucs" descends from the first letters of the commands). The first example shows the number of logins of users; the one who logged in most often comes last. The second example extracts web client IP addresses from a log file, then pipes the result through the "sucs" alias to find out which clients are performing the most accesses. Or pipe the first column of ps(1) output through "sucs" to see how many processes your users are running.

/usr/sbin/apache2ctl -S
2009-07-21 10:52:49
User: lingo

Simply shows virtualhosts enabled, root access not needed (assuming apache2ctl is non-root executable).

/usr/sbin/apache2ctl -S 2>&1 | perl -ne '[email protected]*port\s+([0-9]+)\s+\w+\s+(\S+)\s+\((.+):.*@ && do { print "$2:$1\n\t$3\n"; $root = qx{grep DocumentRoot $3}; $root =~ s/^\s+//; print "\t$root\n" };'
2009-07-21 10:51:30
User: lingo
Functions: perl

Lists virtualhosts currently enabled for apache2, showing the ServerName:port, conf file and DocumentRoot