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,493 results
uname -m
2011-01-15 21:07:13
User: retrodanny
Functions: uname
Tags: 32 processor

i686 = 32 bits

x86_64 = 64 bits

the command "getconf LONG_BIT" will work just as well.

# cat file1.mp3 file2.mp3 > file3.mp3
2010-01-17 13:18:34
User: svnlabs
Functions: cat

cat - concatenate MP3 files and save it...

lsb_release -a
source filename_script.sh
2010-05-14 15:14:25
User: mrttlemonde

Useful command to avoid unreadble script in a single file...

cat /dev/ttyS2 | hexdump -C
man $(/bin/ls /bin | awk '{ cmd[i++] = $0 } END { srand(); print cmd[int(rand()*length(cmd))]; }')
2010-08-20 17:31:02
User: emilsit
Functions: awk man
Tags: man awk

Build an awk array with all commands and then select a random one at the end.

This avoids spawning extra processes for counting with wc or generating random numbers.

Explicitly call /bin/ls to avoid interactions with aliases.

not () { "$@" && return 1 || return 0; }
2009-09-23 01:09:53
User: arcege
Functions: return
Tags: shell

Useful in while and if statements

if not grep string filename; then echo string not found; exit 1; fi
export IFS=$'\n';for dir in $( ls -l | grep ^d | cut -c 52-);do du -sh $dir; done
cat file.txt|perl -ne '$_=~s/\s+/\n/g; print $_;'
2009-02-06 08:47:18
User: foodie
Functions: cat

This command is useful for separating a text file where all the words are in one line. Any group of spaces will be replaced with a single newline. Instead of one long line of tokens. You'll have a long list of tokens. One token per line.

ps aux | grep [c]ommandname
macchanger --random interface
2010-09-26 11:12:31
User: JulianTosh
Tags: sed openssl

macchanger will allow you to change either 1) mfg code, 2) host id, or 3) all of the above. Use this at wifi hotspots to help reduce profiling.

printf "$string" | md5sum
files=(/usr/share/cowsay/cows/*); cowsay -f `echo ${files[$((RANDOM%${#files}))]}` <TEXT>
2011-02-20 05:43:01
User: lkjoel

This will show a random cow with cowsay.

find . |more |grep -v filename |xargs rm
awk '{if (NR == 3) print}' <file>
2009-10-19 15:58:09
User: yooreck
Functions: awk

I don't know if it's better but works fine :)

gawk '{n=$1;a=0;b=1;c=1;for(i=1;i<n;i++){c=a+b;a=b;b=c};print c}' << eof
2010-11-26 08:36:30
Functions: gawk
Tags: awk

only take the first field on each row to compute the fibo on this number

find . -name "*.c" -exec sed -i "/\/sh/a\####################################\n#Date:2010-05-18\n#Company:XXXXX tech Co.\n#Author:Wangjunling\n#Copyright:gpl\n####################################" {} \;
iptables -F
removedir(){ read -p "Delete the current directory $PWD ? " human;if [ "$human" = "yes" ]; then [ -z "${PWD##*/}" ] && { echo "$PWD not set" >&2;return 1;}; rm -Rf ../"${PWD##*/}"/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; }
say `cat /path/to/textfile.txt`
p=$(netstat -nate 2>/dev/null | awk '/LISTEN/ {gsub (/.*:/, "", $4); if ($4 == "4444") {print $8}}'); for i in $(ls /proc/|grep "^[1-9]"); do [[ $(ls -l /proc/$i/fd/|grep socket|sed -e 's|.*\[\(.*\)\]|\1|'|grep $p) ]] && cat /proc/$i/cmdline && echo; done
2009-04-30 12:39:48
User: j0rn
Functions: awk cat grep ls netstat sed

Ok so it's rellay useless line and I sorry for that, furthermore that's nothing optimized at all...

At the beginning I didn't managed by using netstat -p to print out which process was handling that open port 4444, I realize at the end I was not root and security restrictions applied ;p

It's nevertheless a (good ?) way to see how ps(tree) works, as it acts exactly the same way by reading in /proc

So for a specific port, this line returns the calling command line of every thread that handle the associated socket

netstat -nlput