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





Commands by depesz from sorted by
Terminal - Commands by depesz - 37 results
perl -le 'print$_%3?$_%5?$_:"Buzz":$_%5?"Fizz":"FizzBuzz"for 1..100'
ack; pcregrep
2011-08-14 18:01:36
User: depesz
Tags: perl grep regex

Much better alternatives - grep-alikes using perl regexps. With more options, and nicer outputs.

find public_html/ -type d -exec chmod 755 {} +
2011-07-25 15:25:36
User: depesz
Functions: chmod find

+ at the end means that many filenames will be passed to every chmod call, thus making it faster. And find own {} makes sure that it will work with spaces and other characters in filenames.

lsb_release -ri
find . -depth \( -path '*/*.java.orig' -o -path '*/*.java.orig/*' \) -delete
echo $(( $( date +%s ) - $( stat -c %Y * | sort -nr | head -n 1 ) ))
echo "shutdown -h now" | sudo at now + 4 hours
2011-05-02 15:29:48
User: depesz
Functions: at echo sudo

Benefit is that it doesn't make you keep the terminal open.

mkdir copy{1,2}; gzip -dc file.tar.gz | tee >( tar x -C copy1/ ) | tar x -C copy2/
2011-04-14 17:02:05
User: depesz
Functions: gzip mkdir tar tee
Tags: bash tee tar

Sometimes you might need to have two copies of data that is in tar. You might unpack, and then copy, but if IO is slow, you might lower it by automatically writing it twice (or more times)

MyVAR=85 awk '{ print ENVIRON["MyVAR"] }'
2011-04-14 16:46:23
User: depesz
Functions: awk
Tags: bash awk print


export MyVAR=84; awk '{ print ENVIRON["MyVAR"] }'

ack hoge .
grep -r hoge .
find -L . -type l
find . -type d -name .svn -prune -o -type f -print0 | xargs -r0 ...
ps -C apache o pid= | sed 's/^/-p /' | xargs strace
dpkg --get-selections | awk '$2=="install" {print $1}' | sort
find . -type f -name '*.pm' -printf '%6s %p\n' | sort -nr | head -n 50
2011-02-09 16:19:11
User: depesz
Functions: find head sort

Will work with filenames with spaces inside. Will not break in case of someone making directory that matches *.pm. And sorts from largest. Where largest is file size, not line count.

ps -o comm= -p $$
2011-02-05 11:54:42
User: depesz
Functions: ps

First version was "ps uw -p $$", but current "ps -o comm= -p $$" just gives shell name

perl -le '$,=".";print map int rand 256,1..4'
perl -le '$,=".";print map int rand 256,1..4'
perl -le 'print time()'
find -type f -exec du -sh {} + | sort -rh | head
find . -type f -size +20000k -print0 | xargs -0 du -h | awk -F"\t" '{printf "%s : %s\n", $2, $1}'
2010-12-15 17:51:09
User: depesz
Functions: awk du find xargs

Output made so that it will match initial suggestion for this task. Personally, I think that output of du -h is more readable.

perl -ane 'print unless $x{$F[0]}++' infile > outfile
shopt -s globstar; rm -rfv **/.svn
(netstat -atn | awk '{printf "%s\n%s\n", $4, $4}' | grep -oE '[0-9]*$'; seq 32768 61000) | sort -n | uniq -u | head -n 1