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,604 results
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

echo "rm -rf /unwanted-but-large/folder" | batch
2009-02-04 19:07:52
User: root
Functions: echo
38

Good for one off jobs that you want to run at a quiet time. The default threshold is a load average of 0.8 but this can be set using atrun.

realpath examplefile.txt
2009-02-04 15:41:44
User: root
3

Useful in scripts when the file is passed in as an argument. Eg.

filepath=$(realpath $1)
ssh user@host cat /path/to/remotefile | diff /path/to/localfile -
2009-02-04 11:33:19
User: root
Functions: cat diff ssh
147

Useful for checking if there are differences between local and remote files.

zcat /usr/share/man/man1/grep.1.gz | grep "color"
2009-02-04 09:38:45
User: root
Functions: grep zcat
-7

This decompresses the file and sends the output to STDOUT so it can be grepped. A good one to put in loops for searching directories of gzipped files, such as man pages.

bind -p | grep -F "\C"
2009-02-03 16:22:14
User: root
Functions: grep
5

Useful for getting to know the available keyboard shortcuts.

function sshdel { perl -i -n -e "print unless (\$. == $1)" ~/.ssh/known_hosts; }
2009-02-03 16:20:50
User: xsawyerx
Functions: perl
-1

sometimes you got conflicts using SSH (host changing ip, ip now belongs to a different machine) and you need to edit the file and remove the offending line from known_hosts. this does it much easier.

(> errors.log) && tail -f !^
2009-02-03 16:08:19
User: root
Functions: tail
2

This is useful for keeping an eye on an error log while developing. The !^ pulls the first arg from the previous command (which needs to be run in a sub-shell for this shortcut to work).

cat /etc/issue
iptables -A INPUT -s 222.35.138.25/32 -j DROP
2009-02-02 12:42:04
User: root
Functions: iptables
10

This appends (-A) a new rule to the INPUT chain, which specifies to drop all packets from a source (-s) IP address.

wget -O - http://www.commandlinefu.com/commands/browse/rss 2>/dev/null | awk '/\s*<title/ {z=match($0, /CDATA\[([^\]]*)\]/, b);print b[1]} /\s*<description/ {c=match($0, /code>(.*)<\/code>/, d);print d[1]"\n"} '
curl --basic --user "user:pass" --data-ascii "status=tweeting%20from%20%the%20linux%20command%20line" http://twitter.com/statuses/update.json
2009-01-30 18:08:35
User: g__j
2

great for outputting tweets from cron jobs and batch scripts

echo -e "[mysql]\npager=less -niSFX" >> ~/.my.cnf
2009-01-29 11:45:52
User: boombastic
Functions: echo
5

Changes standard mysql client output to 'less'.

In another words makes query results of mysql command line client to look much better.

tar czv file1 file2 folder1 | ssh user@server tar zxv -C /destination
2009-01-29 10:38:26
User: xsawyerx
Functions: ssh tar
13

it compresses the files and folders to stdout, secure copies it to the server's stdin and runs tar there to extract the input and output to whatever destination using -C. if you emit "-C /destination", it will extract it to the home folder of the user, much like `scp file user@server:`.

the "v" in the tar command can be removed for no verbosity.

svn status |grep '\?' |awk '{print $2}'| xargs svn add
2009-01-29 10:33:22
User: xsawyerx
Functions: xargs
13

checks which files are not under version control, fetches the names and runs them through "svn add". WARNING: doesn't work with white spaces.

ping google.com | tee ping-output.txt
2009-01-29 10:26:59
User: root
Functions: ping tee
2

The tee (as in "T" junction) command is very useful for redirecting output to two places.