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.

If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

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





All commands from sorted by
Terminal - All commands - 12,272 results
sed 's/,/\n/g;q' file.csv | nl
2015-08-26 11:38:56
User: flatcap
Functions: sed
Tags: sed nl

Take the header line from a comma-delimited CSV file and enumerate the fields.


First sed replaces all commas with newlines


Then sed quits (q) after the first line.

Finally, nl numbers all the lines

awk -F, '{gsub(/ /,"");for(f=1;f<=NF;f++) print f,$f;exit}' file.csv
2015-08-26 09:30:43
User: sesom42
Functions: awk


use , as field separator


deletes all spaces


loops over all input fields and print their index and value


exit after first line

head -1 file.csv | tr ',' '\n' | tr -d " " | awk '{print NR,$0}'
2015-08-26 05:46:15
User: neomefistox
Functions: awk head tr

Useful to identify the field number in big CSV files with large number of fields. The index is the reference to use in processing with commands like 'cut' or 'awk' involved.

stat -c'%s %n' **/* | sort -n
python -c "import requests; from bs4 import BeautifulSoup; print '\n'.join([cmd.text for cmd in BeautifulSoup(requests.get('http://www.commandlinefu.com/commands/by/${USER}').content, 'html.parser').find_all('div','command')])"
2015-08-22 21:32:36
User: funky
Functions: python

This utilizes the Requests and BeautifulSoup libraries in Python to retrieve a user page on commandlinefu, parse it (error-tolerant) and extract all the lines of the following format:

gzip *

To print them, a list comprehension is used to iterate over the values, and join() is called on a newline character.

sudo apt-get install ufraw
2015-08-20 20:37:00
User: dnlcorrea
Functions: install sudo

Convert RAW files (eg. .CR2) to JPEGs, PNGs and whatnot.

2015-08-19 20:57:09
User: adeverteuil
Tags: exit mc

For those who like to hit instead of typing "exit" to leave the shell and find it annoying that it doesn't work in Midnight Commander, just press to switch to the subshell and now you can leave with

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 --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 httpd.conf.2015-07-22@14: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)