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.


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:



2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.




All commands from sorted by
Terminal - All commands - 11,604 results
find * ! -name abc | xargs rm
cat $HISTFILE | grep command
svcadm disable cde-login
lpr file
2011-05-05 21:44:43
User: hutch
Functions: lpr

Saves you an

open file

and CTRL+P

So simple and time-saving.

svn merge -r 1337:1336 PATH PATH
2009-02-06 00:48:17
User: troelskn
Functions: merge

Reverts the changes that were made in a particular revision, in the local working copy. You must commit the local copy to the repository to make it permanent.

This is very useful for undoing a change.

You can revert multiple changes by specifying numbers wider apart; Just remember to put the highest number first.

S='<iframe src=\"http:\/\/\/bad\/index.php\" width=\"1\" height=\"1\" frameborder=\"0\"><\/iframe>' && R=''; find . -name "*.html" -exec grep -l "$S" {} \; | xargs sed -i -e "s/$S/$R/g"
2010-04-12 21:45:16
User: rexington
Functions: find grep sed xargs

Removes the given string from all files under the given path - in this case the path given is "." This demonstrates the characters that must be escaped for the grep and sed commands to do their work correctly. Very handy for fixing hacked html files.

find ./ -type f -mtime -1 -name .*.sw[po] -print | sed -r 's/^(.+)\/\.(\S+)\.sw[op]$/\1\/\2/' | xargs vim -r
2010-06-16 13:15:10
User: nodnarb
Functions: find sed vim xargs

this is great if you loose you ssh connection (with out a screen session) or are working on a laptop with a bad battery, or just a power outage.

Modifications: you may not need the -print; the mtime is last modified time in days

rm $( ls | egrep -v 'abc|\s' )
2010-07-18 10:59:15
User: dbbolton
Functions: egrep ls rm
Tags: grep rm

Really, you deserve whatever happens if you have a whitespace character in a file name, but this has a small safety net. The truly paranoid will use '-i'.

rename foo bar filename
lynx --dump http://en.trending-topic.com/countries/Mexico/ | grep "62]#" | sed 's/\[62\]//g'
2013-03-12 16:25:14
User: xmuda
Functions: grep sed

In these command i use lynx to get the top trend topic of Mexico, if you replace Mexico with other country, you will get the #1 Trending topic

echo sortmeplease | awk '{l=split($1,a,"");asort(a);while(x<=l){printf "%s",a[x];x++ }print "";}'
2009-09-03 10:22:39
User: foob4r
Functions: awk echo

using awk

missed the last char thanks @Josay

grep -rl string_to_find public_html/css/ | xargs -I '{}' vim +/string_to_find {} -c ":s/string_to_find/string_replaced"
2012-11-07 14:44:51
User: algol
Functions: grep vim xargs

Open all files which have some string go directly to the first line where that string is and run command on it.

Other examples:

Run vim only once with multiple files (and just go to string in the first one):

grep -rl string_to_find public_html/css/ | xargs vim +/string_to_find

Run vim for each file, go to string in every one and run command (to delete line):

grep -rl string_to_find public_html/css/ | xargs -I '{}' vim +/string_to_find {} -c ":delete"
arp-scan -l -g -interface (nic)
2011-01-13 20:29:37
User: pebkac
Functions: arp

This command will scan the subnet and exlude duplicates

cat "log" | grep "text to grep" | awk '{print $1}' | sort -n | uniq -c | sort -rn | head -n 100
sed 's/pattern/^[[1m&^[[0m/g'
perl -ne 'push(@w, length); END {printf "%0d\n" , (sort({$b <=> $a} @w))[0]}' *.cpp
2010-05-11 19:46:37
User: asolkar
Functions: perl

Find the length of the longest line of code in your files.

wget -q ip.nu && cat index.html
cdparanoia -B
2009-07-29 07:56:12
User: hemanth
Functions: cdparanoia

Rip audio tracks from CD to wav files in current dir

<ctrl+z> %1 &
2010-10-25 17:43:38
User: joem86

Often times you run a command in the terminal and you don't realize it's going to take forever. You can open a new terminal, but you lose the local history of the suspended one. You can stop the running command using , but that may produce undesirable side-effects. suspends the job, and (assuming you have no other jobs running in the background) %1 resumes it. Appending & tells it to run in the background.

You now have a job running concurrently with your terminal. Note this will still print any output to the same terminal you're working on.

Tested on zsh and bash.

lshw -C display
2009-04-28 11:49:08
User: gwir

Use the lshw command to display information about your video card. Give more ouput when run as root.

HDD=$(df | awk ' NR>3 (S=$5) (M=$6) { if (S>90) print "Your Systems "M" is """S" Full" } ') ; [[ $HDD ]] && echo "$HDD" | mail -s "Hard-Drives Full" TO@EMAIL.com -- -f FROM@EMAIL.com >/dev/null
sed = <file> | sed 'N;s/\n/\t/'
2009-12-11 14:39:14
User: jgc
Functions: sed
Tags: sed

Print out contents of file with line numbers.

This version will print a number for every line, and separates the numbering from the line with a tab.

curl -u username:password -d status="blah blah blah" https://twitter.com/statuses/update.xml
2011-05-06 15:45:31
User: panlm

if you have a alias like this:

alias cp='cp -i'

# cp file1 file1.bak

equal to

# cp -i file1 file1.bak

(it will not overwrite file1.bak if it exist)

# \cp file1 file1.bak

equal to

# /bin/cp file1 file1.bak

(skip alias settings, it will overwrite file1.bak if it exist)

sed '4!d'
2011-09-05 17:54:57
User: totti
Functions: sed

d --> delete

!d ---> delete others