Hide

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.

Hide

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:

Hide

News

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.
Hide

Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 11,619 results
diff -q dir1/ dir2/ | grep differ | awk '{ print "vimdiff " $2 " " $4 }'
2009-02-05 12:37:00
User: binaryslate
Functions: awk diff grep
1

We use this to quickly highlight differences and provide a quick way to cut and paste the command to view the files using the marvellous vimdiff

curl -O http://hosted.met-art.com/generated_gallery/full/061606AnnaUkrainePasha/met-art-free-sample-00[00-19].jpg
2009-02-05 12:35:07
User: kumara
4

-O switch creates local filename same as remote

curl [][] -o #1#2 makes local files unique inserting sequence values into #x placeholders

sequences can be alpha or numeric e.g [a-z] [1-25]

find /path/to/dir -type f |sed 's/^.*\///'|grep -o '\.[^.]*$'|sort -f|uniq -i
for jj in `seq -f "%02.0f" 1 12`; do rr=`ls *S04E$jj*.smi`; tt=`ls *S04E$jj*.avi`; mv "$rr" "${tt%.*}.smi"; done
2009-02-05 12:16:06
User: beila
Functions: mv
-1

Subtitles' file names contain S04E01, S04E02, ... S04E12 and end with ".smi".

Videos' file names contain S04E01, S04E02, ... S04E12 and end with ".avi".

You can change the patterns by changing `ls *S04E$jj*.smi` and `ls *S04E$jj*.avi` parts.

You can change the number of starting and ending file by changing `seq -f "%02.0f" 1 12` part.

perl -i -pe "s/old/new/g" *
2009-02-05 12:07:27
User: pandres
Functions: perl
-1

Replaces every ocurrence of 'old' for 'new' in all files specified. After the 'i' char you can put a '~' or whatever to create a backup file for each replaced with the name equal to the original plus character.

yes "$(seq 232 255;seq 254 -1 233)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
python -m SimpleHTTPServer
tar -tvjf backup.tar.bz2 | sort -nrk 3 | head
ssh-keygen -R \[localhost\]:8022
2009-02-05 11:48:09
User: Sekenre
Functions: ssh ssh-keygen
6

Useful if you have to tunnel ssh through a local port and it complains of the host key being different. Much easier than manually editing the file.

ps -auwx|egrep hunger|grep -v grep| awk '{print "kill -9",$1}' > ~/fu.bar
alias rgrep="find . \( ! -name .svn -o -prune \) -type f -print0 | xargs -0 grep"
du -s * | sort -n | tail
screen -ls | grep main && urxvt -name screen -e screen -x main || urxvt -name screen -e screen -R -S main
2009-02-05 10:51:31
User: trey
Functions: grep screen
0

Open a terminal (urxvt in this case) to connect to a screen session (named "main") and create the screen session if necessary.

ping localip -c 1 -W 1 &> /dev/null && ssh localip || ssh globalip
2009-02-05 10:40:26
User: trey
Functions: ping ssh
1

Ping machine once, waiting 1 second for response until failing. Upon fail, ssh globally, otherwise ssh locally.

apropos somekeyword
whereis somecommand
which somecommand
2009-02-05 10:29:04
User: chrisdrew
Functions: which
-1

Returns the pathnames of the files which would be executed in the current environment had its arguments been given as a command.

find . -type f -print0 | grep -vzZ '.svn' | xargs -0 grep --color -nEHi "SEARCHTERM"
2009-02-05 10:27:15
User: troelskn
Functions: find grep xargs
-3

Variant of find grep that ignores files with .svn in the name. Useful for searching through a local repository of source code.

alias cdc='cd `pwd -P`'
alias beep='echo -en "\007"'
ssh -N -L2001:localhost:80 somemachine
ssh somemachine "cd some dir; tar zcpf - somedirname" |tar zxpf -
alias counts=sort | uniq -c | sort -nr
mplayer -ao pcm -vo null -vc dummy -dumpaudio -dumpfile <output-file> <input-file>
diff <(sort file1) <(sort file2)
2009-02-04 22:20:13
User: systemj
Functions: diff sort
80

bash/ksh subshell redirection (as file descriptors) used as input to diff