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,229 results
%! perl -MO=Deparse | perltidy
2009-09-24 03:32:04
User: syssyphus
Functions: perl

the command show can be run in vim, here is the same thing on the command line

cat script.pl | perl -MO=Deparse | perltidy
perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
sudo chown -R user2:user2 /../../somedirectory
2009-09-23 21:27:45
User: bkn390
Functions: chown sudo

This will change the ownership of /../../somedirectory as well as all its subdirectories so they will be be owned by user2 - typically used when a directory is owned by root:root

expr 512 \* 7
2009-09-23 19:11:38
User: chuckr
Functions: expr
Tags: math expr

expr will give you a quick way to do basic math from the CLI. Make sure you escape things like * and leave a space between operators and digits.

grep CONFIG $(which mysqlbug)
(echo "set terminal png;plot '-' u 1:2 t 'cpu' w linespoints;"; sudo vmstat 2 10 | awk 'NR > 2 {print NR, $13}') | gnuplot > plot.png
export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007";'
2009-09-23 16:38:06
User: dstahlke
Functions: export
Tags: terminal title

This helps to keep track of what is going on when you have several tabs open in your terminal. The title automatically changes when you change directories.

timeout 10 sleep 11
ssh-keygen -R `host hostname | cut -d " " -f 4`
2009-09-23 14:58:28
User: flart
Functions: cut hostname ssh ssh-keygen

Quick shortcut if you know the hostname and want to save yourself one step for looking up the IP address separately.

<Shift + W>
2009-09-23 13:51:22
User: hfs
Tags: top

'top' has fancy layout modes where you can have several windows with different things displayed. You can configure a layout and then save it with 'W'. It will then be restored every time you run top.

E.g. to have two colored windows, one sorted by CPU usage, the other by memory usage, run top


then press the keys

<A> <z> <a> <-> <a> <z> <a> <-> <a>

and then as you don?t want to repeat this the next time:

for each in `cut -d " " -f 1 inputfile.txt`; do echo "select * from table where id = \"$each\";"; done
2009-09-23 13:29:16
User: hfs
Functions: echo
Tags: echo cut for-each

I never can remember the syntax of awk. You can give a different -d option to cut to separate by e.g. commas. Also this allows to do more things with the generated SQL, e.g. to redirect it into different files.

cut -f 2- -d " "
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
perl -e "alarm 10; exec @ARGV" "somecommand"
2009-09-23 12:03:55
User: jgc
Functions: perl

In this example the command "somecommand" will be executed and sent a SIGALARM signal if it runs for more than 10 seconds. It uses the perl alarm function. It's not 100% accurate on timing, but close enough. I found this really useful when executing scripts and commands that I knew might hang E.g. ones that connect to services that might not be running. Importantly this can be used within a sequential script. The command will not release control until either the command completes or the timeout is hit.

awk '{$1=""; print}'
vmstat 2 10 | awk 'NR > 2 {print NR, $13}' | gnuplot -e "set terminal png;set output 'v.png';plot '-' u 1:2 t 'cpu' w linespoints;"
xwinwrap -ni -argb -fs -s -st -sp -nf -b -- /usr/libexec/xscreensaver/atlantis -count 20 -window-id WID &
2009-09-23 05:29:21
User: dstahlke
Tags: xwinwrap

xwinwrap allows you to run any program in the root desktop pane. I like to run atlantis, it goes well against Fedora 10's blue sun background. At one time this also served a useful purpose for me as a workaround for a problem that would happen when the video card went into sleep mode.

snarf http://foo.bar.com/picture.jpg
2009-09-23 04:22:57

It can transfer files through the http, gopher, finger, and ftp protocols without user interaction. It is small and fast.

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
perl -le 'print join $/, @INC'
2009-09-22 22:18:35
User: chuckr
Functions: join perl

This will show where your Perl installation is looking for modules.

perl -le 'use Config; foreach $i (keys %Config) {print "$i : @Config{$i}"}'
2009-09-22 22:14:21
User: chuckr
Functions: perl
Tags: perl

This dumps all of your installed perl's config information.

x=1; while [ $x = 1 ]; do process=`pgrep -u username`; if [ $process ]; then x=0; fi; done; strace -vvtf -s 256 -p $process
2009-09-22 16:46:27
User: dimentox
Functions: strace

It sits there in a loop waiting for a proccess from that user to spawn.

When it does it will attach strace to it

grep -RnisI <pattern> *
2009-09-22 15:09:43
User: birnam
Functions: grep
Tags: bash grep

This is how I typically grep. -R recurse into subdirectories, -n show line numbers of matches, -i ignore case, -s suppress "doesn't exist" and "can't read" messages, -I ignore binary files (technically, process them as having no matches, important for showing inverted results with -v)

I have grep aliased to "grep --color=auto" as well, but that's a matter of formatting not function.

grep -r <pattern> * .[!.]*
ack <pattern>
2009-09-22 14:08:34
User: levenbrech

ack seeks for , list all found files and display everything in nice colors. Look for it in http://betterthangrep.com/