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,363 results
curl - https://graph.facebook.com/fql?q=SELECT%20like_count,%20total_count,%20share_count,%20click_count,%20comment_count%20FROM%20link_stat%20WHERE%20url%20=%20%27<URL>%27 | awk -F\" '{ print $7 }' | awk -F":" '{ print $2 }' | awk -F"," '{ print $1 }'
2015-08-19 20:01:15
User: sxiii
Functions: awk

Replace the with your URL, for example http://rublacklist.net/12348/ and it will show likes number

find /proc/*/fd -xtype f -printf "%l\n" | grep -P '^/(?!dev|proc|sys)' | sort | uniq -c | sort -n
2015-08-18 17:58:21
User: flatcap
Functions: find grep sort uniq
Tags: sort uniq find grep

List all open files of all processes.


find /proc/*/fd

Look through the /proc file descriptors


-xtype f

list only symlinks to file


-printf "%l\n"

print the symlink target


grep -P '^/(?!dev|proc|sys)'

ignore files from /dev /proc or /sys


sort | uniq -c | sort -n

count the results


Many processes will create and immediately delete temporary files.

These can the filtered out by adding:

... | grep -v " (deleted)$" | ...
lsof -a -d 1-99 -Fn / | grep ^n | cut -b2- | sort | uniq -c | sort -n
sudo lsof | egrep 'w.+REG' | awk '{print $10}' | sort | uniq -c | sort -n
2015-08-18 14:09:02
User: kennethjor
Functions: awk egrep sort sudo uniq

This command run fine on my Ubuntu machine, but on Red Hat I had to change the awk command to `awk '{print $10}'`.

echo "quit" | openssl s_client -connect facebook.com:443 | openssl x509 -noout -text | grep "DNS:" | perl -pe "s/(, )?DNS:/\n/g"
wget http://rendezvousavecmrx.free.fr/audio/mr_x_{1997..2015}_{01..12}_{01..31}.mp3
git log -i --grep='needle'
2015-08-11 23:07:55
User: sudopeople
Tags: git grep git-log

Normally, searching git log comments is case sensitive. The -i luckily applies to the --grep switch.

mtr -c 50 -r example.com
2015-08-05 07:18:52
User: ohe

mtr is a network utility that combines traceroute and ping utility

exec 5<>/dev/tcp/time.nist.gov/13; cat <&5 & cat >&5; exec 5>&-
2015-07-30 21:12:38
User: tyzbit
Functions: cat exec
Tags: bash Linux unix

Ever needed to test firewalls but didn't have netcat, telnet or even FTP?

Enter /dev/tcp, your new best friend. /dev/tcp/(hostname)/(port) is a bash builtin that bash can use to open connections to TCP and UDP ports.

This one-liner opens a connection on a port to a server and lets you read and write to it from the terminal.

How it works:

First, exec sets up a redirect for /dev/tcp/$server/$port to file descriptor 5.

Then, as per some excellent feedback from @flatcap, we launch a redirect from file descriptor 5 to STDOUT and send that to the background (which is what causes the PID to be printed when the commands are run), and then redirect STDIN to file descriptor 5 with the second cat.

Finally, when the second cat dies (the connection is closed), we clean up the file descriptor with 'exec 5>&-'.

It can be used to test FTP, HTTP, NTP, or can connect to netcat listening on a port (makes for a simple chat client!)

Replace /tcp/ with /udp/ to use UDP instead.

phpcs --no-colors --standard=WordPress-Core -s -- $( find . -name '*.php' ) | ack -o '(?<=\()\w+(\.\w+)+(?=\)$)' | sort | uniq -c | sort -nr
cd $JAVA_HOME && java -Xbootclasspath/a:jre/lib/deploy.jar -Djava.locale.providers=HOST,JRE,SPI -Xdock:name="Java Control Panel" com.sun.deploy.panel.ControlPanel
2015-07-30 19:24:33
Functions: cd
Tags: java jre

Useful if you need to make changes to the JVM on, say, 1.7 when your default installed is 1.8.

export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2015-07-30 18:50:51
Functions: export
Tags: version java

Useful if you have multiple versions of Java installed. The 1.7 pkg for Mac doesn't tell you anything about where it's putting stuff.

pyt() { youtube-dl -q -f bestaudio --max-downloads 1 --no-playlist --default-search ${2:-ytsearch} "$1" -o - | mplayer -vo null /dev/fd/3 3<&0 </dev/tty; }
2015-07-27 15:19:59
User: snipertyler

Same as other command, however uses youtube-dl internal search (thanks to qoxxxx mentioning this)

It does however seem to be a little buggy and youtube-dl crashes sometimes.


pyt 'Stairway to heaven - Led Zeppelin'

pyt 'brain damage - Pink Floyd'

No web browser or even X needed. Just a cli and internet connection!

mplayer is pauseable and can skip ahead

This may break if youtube changes their search html.

ir() { perl -pne 's/(.)(.*)/\[\1]\2/' <<< "$@" ;}
2015-07-25 14:13:33
User: bartonski
Functions: perl
Tags: ps

Note that `grep "$(ir foo)"` really doesn't save any typing, but wrapping this inside a second shell function will:

psg() { grep "$(ir \"$@\")" ;}
mojo get <URL> 'a[href]' attr href
sed -i.$(date +%F@%T) 's/^LogLevel warn/LogLevel debug/g' httpd.conf
2015-07-22 14:47:26
User: zlemini
Functions: date sed

httpd.conf [email protected]:43:20

pyt() { id=$(curl -s 'https://www.youtube.com/results?search_query='$(tr ' ' + <<<"$1") | grep -om3 '"[[:alnum:]]\{11\}"' | awk NR==3 | tr -d \"); youtube-dl -q 'https://www.youtube.com/watch?v='"$id" -o - | mplayer -vo null /dev/fd/3 3<&0 </dev/tty; }
2015-07-20 05:30:27
User: snipertyler
Functions: awk grep tr

pyt 'Stairway to heaven - Led Zeppelin'

pyt 'brain damage - Pink Floyd'

No web browser or even X needed. Just a cli and internet connection!

mplayer is pauseable and can skip ahead

This may break if youtube changes their search html.

grep -v -e '^$' -e '^[#\[]' -e '\/' some_file
2015-07-17 21:28:14
User: abhikeny
Functions: grep
Tags: grep no-match

Grep for:

>> non-empty lines : denoted by -v -e '^$'

>> that do not start with # (comments) or : denoted by -v -e '^[#\]'

>> and does not include : denoted by -v -e '\'

(Note that we use -v only once)

ran() { [ $((RANDOM%100)) -lt "$1" ] && shift && "$@"; }
2015-07-16 13:32:45
User: flatcap
Functions: shift
Tags: bash shell random

Randomly decide whether to run a command, or fail.

It's useful for testing purposes.



Note: In this version the percentage is required.


This is like @sesom42 and @snipertyler's commands but in a USABLE form.


e.g. In your complicated shell script, put "ran 99" before a crucial component.

Now, it will fail 1% of the time allowing you to test the failure code-path.

ran 99 my_complex_program arg1 arg2
sort -s -b -t' ' -k 4.9,4.12n -k 4.5,4.7M -k 4.2,4.3n -k 4.14,4.15n -k 4.17,4.18n -k 4.20,4.21n access.log*
2015-07-16 00:22:03
User: sesom42
Functions: sort
Tags: sort log apache

Sort Apache access logs by date and time using sort key field feature

ran() { [ $((RANDOM%100)) -lt ${1:-50} ]; }
2015-07-16 00:06:25
User: sesom42

Command will succeed n% of the time.

ran 75 will cause command to succeed 75% of the time.

No argument will cause it to succeed 50% of the time.

ran() { R=$((RANDOM%100)); if [ $R -gt "${1:-50}" ]; then echo FALSE; false; else echo TRUE; true; fi; }
2015-07-15 15:34:56
User: snipertyler
Functions: echo

Command will succeed n% of the time.

ran 75 will cause command to succeed 75% of the time.

No argument will cause it to succeed 50% of the time.

pvl() { (for i in "$@"; do youtube-dl -q --max-downloads 1 --no-playlist "$i" -o - | mplayer -vo null /dev/fd/3 3<&0 </dev/tty; sleep .5; done); }
2015-07-14 04:44:36
User: snipertyler
Functions: sleep

pvl 'link1' 'link2' 'link3'

Play Youtube, Vimeo, etc links without visual elements.

Great for music videos when you just want the audio.

You can control mplayer with this!

Hit Ctrl-C twice to exit (if you're playing multiple files)

echo "text to prepend" | cat - file
lsblk -do name,model,serial
2015-07-12 10:49:49
User: hackerb9

As of this writing, this requires a fairly recent version of util-linux, but is much simpler than the previous alternatives. Basically, lsblk gives a nice, human readable interface to all the blkid stuff. (Of course, I wouldn't recommend this if you're going to be parsing the output.) This command takes all the fun out of the previous nifty pipelines, but I felt I ought to at least mention it as an alternative since it is the most practical.