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.

Universal configuration monitoring and system of record for IT.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

All commands from sorted by
Terminal - All commands - 12,380 results
check_disk -w 15% -c 10% $(for x in $(cat /proc/mounts |awk '{print $2}')\; do echo -n " -p $x "\; done)
grep lm /proc/cpuinfo
2009-02-19 22:48:47
User: bobbydale
Functions: grep

If the 'lm' flag is present, then the CPU is 64-bit.

If no output, then CPU is 32-bit.

top -b -n 1 | awk '{if (NR <=7) print; else if ($8 == "D") {print; count++} } END {print "Total status D: "count}'
comm -1 -2 <(sort file1) <(sort file2)
cat foo.csv bar.csv | sort -t "," -k 2 | uniq
2009-02-19 20:23:03
User: rafeco
Functions: cat sort

The value for the sort command's -k argument is the column in the CSV file to sort on. In this example, it sorts on the second column. You must use some form of the sort command in order for uniq to work properly.

autossh -f -M 20000 -D 8000 somehost -N
2009-02-19 20:17:52
User: sud0er

This command will log you into somehost via SSH and then go into the background (-f). From there, you can point e.g. firefox at localhost:8000 as a SOCKS proxy. Autossh will use port 20000 and 20001 to send and receive test data on those ports to ensure the SSH tunnel is still running, and will try to re-start the tunnel if it goes down. Make sure you have ssh-agent running, or passwordless ssh keys distributed between the two hosts.

vncviewer -via [email protected]
2009-02-19 20:14:37

The ip address is of the remote machine running the vncserver. Must log in first to the router then the VNC session. Very nice if you have open-wrt or dd-wrt on your router.

$(STEEP=300; sleep $STEEP; xmessage "Your tea is done") &
2009-02-19 20:10:49
User: sud0er
Functions: sleep

wrapping the snippet in $( )& puts the whole thing in the background so you don't tie up your login session.

lsof | awk '{print $1}' | sort | uniq -c | sort -rn | head
sed -n -e '/postfix\/smtp\[.*status=sent/s/^.*to=<\([^>]*\).*$/\1/p' /var/log/mail.log | sort -u
netstat -an | grep -i listen
2009-02-19 19:27:49
User: scubacuda
Functions: grep netstat

From 'man netstat'

"netstat -i | -I interface [-abdnt] [-f address_family] [-M core] [-N system]

Show the state of all network interfaces or a single interface

which have been auto-configured (interfaces statically configured

into a system, but not located at boot time are not shown). An

asterisk (``*'') after an interface name indicates that the

interface is ``down''. If -a is also present, multicast

addresses currently in use are shown for each Ethernet interface

and for each IP interface address. Multicast addresses are shown

on separate lines following the interface address with which they

are associated. If -b is also present, show the number of bytes

in and out. If -d is also present, show the number of dropped

packets. If -t is also present, show the contents of watchdog


. ./cd_some_dir.sh
2009-02-19 19:02:21
User: jcgam69

The script contains a single command:

cd /a/long/directory/path/i/can/never/remember

x11vnc -display :0 -auth $(ps -ef|awk '/xauth/ {print $15}'|head -1) -forever -bg &
2009-02-19 18:55:54
User: nottings
Functions: ps

the $15 may change for you depending on your distro, etc...

ps aux | grep -i firefox | grep -v grep | awk '{print $2}' | xargs -t -i kill -9 {}
2009-02-19 18:50:00
User: blackdude
Functions: awk grep kill ps xargs

This is a nice way to kill processes.. the example here is for firefox!!! substitute firefox for whatever the process name is...

while read line; do echo "$(date),$(hostname),$line"; done < somefile.txt
nmap -sS -O -oX /tmp/nmap.xml -v -v && perl nmap2nagios.pl -v -r /tmp/10net.xml -o /etc/nagios/10net.cfg
set -o vi
xxcopy x:\folder1 y:\folder2 /s /h /tca /tcc /tcw /yy
cat somefilehere.txt | ssh-xfer nametocallfile.txt -
2009-02-19 18:35:33
User: scubacuda
Functions: cat

from http://matt.ucc.asn.au/ssh-xfer/

"ssh-xfer is a hackish but handy way of transferring files from remote hosts to your local computer. Firstly, you need to run a slightly modified SSH authentication agent program on your local computer. Patches are available for both OpenSSH and PuTTY, see below. If you haven't used a SSH agent program before, this article seems to be reasonable, or you can look at the OpenSSH/PuTTY docs.

You don't need any modifications to your ssh client or server programs - only the modified SSH authentication agent, and the extra ssh-xfer program."

^r in bash begins a reverse-search-history with command completion
2009-02-19 18:17:54
User: abcde
Functions: bash command

In the sample output, I pressed ctrl+r and typed the letters las. I can't imagine how much typing this has saved me.

grep -v "^$" file
2009-02-19 18:11:58
User: hkyeakley
Functions: grep

To save the result, redirect the output to another file.

grep -v "^$" file1 > file2
while [ 0 ]; do echo -e "HTTP/1.1 302 Found\nLocation: http://www.whatevs.com/index.html" | nc -vvvv -l -p 80; done
2009-02-19 18:04:01
User: wwest4
Functions: echo

any HTTP requests to the machine on the specified port will be redirected to http://www.whatevs.com... quick, dirty, works fine for sites w/

egrep '^[^#]' some_file
alias ds='dig +noauthority +noadditional +noqr +nostats +noidentify +nocmd +noquestion +nocomments'
2009-02-19 17:32:56
Functions: alias

Turn off almost all of dig's output except for what you'd see in a zone file. This can also be put into ~/.digrc.

ionice -c3 find /
2009-02-19 17:23:12
User: mkc
Functions: find

This command is somewhat similar to 'nice', but constrains I/O usage rather than CPU usage. In particular, the '-c3' flag tells the OS to only allow the process to do I/O when nothing else is pending. This dramatically increases the responsiveness of the rest of the system if the process is doing heavy I/O.

There's also a '-p' flag, to set the priority of an already-running process.