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

All commands from sorted by
Terminal - All commands - 10,551 results
wget -q -U Mozilla -O output.mp3 "http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=hello+world
2011-03-08 14:05:36
User: sairon
Functions: wget
29

EDIT: command updated to support accented characters!

Works in any of 58 google supported languages (some sound like crap, english is the best IMO).

You get a mp3 file containing your query in spoken language. There is a limit of 100 characters for the "q" parameter, so be careful. The "tl" parameter contains target language.

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

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.

youtube-dl -t --extract-audio --audio-format mp3 YOUTUBE_URL_HERE
2011-11-15 20:11:20
User: menachem
Tags: youtube mp3
28

youtube-dl has this functionality built in. If you're running an older version of youtube-dl, you can update it using `youtube-dl -U` (although if you have an older version, it probably doesn't download youtube videos anyway.)

youtube-dl --help will show you other options that may come in useful.

grep ^Dirty /proc/meminfo
2011-08-24 08:48:49
User: h3xx
Functions: grep
28

Ever ask yourself "How much data would be lost if I pressed the reset button?"

Scary, isn't it?

ls !(*.gz)
2010-07-29 23:47:26
User: c0t0d0
Functions: ls
Tags: ls glob
28

Negative shell globs already come with bash. Make sure to turn on extended pattern matching with 'shopt -e extglob'.

lsof -P -i -n | cut -f 1 -d " "| uniq | tail -n +2
diff <(cd dir1 && find | sort) <(cd dir2 && find | sort)
2009-05-21 04:44:29
User: mbirk
Functions: cd diff find
Tags: bash diff find
28

This uses Bash's "process substitution" feature to compare (using diff) the output of two different process pipelines.

grep --color=always | less -R
2009-05-20 20:30:19
User: dinomite
Functions: grep less
28

Get your colorized grep output in less(1). This involves two things: forcing grep to output colors even though it's not going to a terminal and telling less to handle those properly.

kill -9 $$
2009-03-27 23:13:53
User: stu
Functions: kill
Tags: history exit
28

this exits bash without saving the history. unlike explicitly disabling the history in some way, this works anywhere, and it works if you decide *after* issuing the command you don't want logged, that you don't want it logged

... $$ ( or ${$} ) is the pid of the current bash instance

this also works perfectly in shells that don't have $$ if you do something like

kill -9 `readlink /proc/self`
leave +15
2009-03-13 06:09:52
User: haivu
Tags: PIM
28

If you spend most of your time in front of the terminal, leave is a useful reminder. Leave can have absolute form: leave 1555 reminds you to leave at 3:55PM

mkdir -p work/{d1,d2}/{src,bin,bak}
echo | openssl s_client -connect www.google.com:443 2>/dev/null |openssl x509 -dates -noout
2009-02-05 15:21:50
User: systemj
Functions: echo
28

remotely connects to an https site, fetches the ssl certificate and displays the valid dates for the cert

awk '{$1=$3=""}1' file
2011-10-25 22:15:06
User: zlemini
Functions: awk
27

Print all columns except the 1st and 3rd.

[enter]~?
2011-06-17 18:29:59
User: xeor
Tags: ssh
27

SSH can be controlled trough an ~ escape sequence. Example, to terminate the current ssh connection, type a newline, then the ~ character, and last a . character.

This is useful eg when an ssh connection hangs after you reboot a machine and the connection hangs.

echo ${SSH_CLIENT%% *}
tar --exclude-vcs -cf src.tar src/
find ./ -type f -exec chmod 644 {} \;
showkey -a
find . -type f -newermt "2010-01-01" ! -newermt "2010-06-01"
2011-06-26 09:52:26
User: flatcap
Functions: find
Tags: find dates
26

Find files in a specific date range - in this case, the first half of last year.

-newermt = modification time of the file is more recent than this date

GNU find allows any date specfication that GNU date would accept, e.g.

find . -type f -newermt "3 years ago" ! -newermt "2 years ago"

or

find . -type f -newermt "last monday"
cat /dev/urandom | hexdump -C | grep "ca fe"
2010-09-27 08:20:44
User: BOYPT
Functions: cat grep hexdump
26

just make some data scrolling off the terminal. wow.

ssh host -l user $(<cmd.txt)
2010-06-04 17:47:00
User: recursiverse
Functions: host ssh
26

Much simpler method. More portable version: ssh host -l user "`cat cmd.txt`"

<ctrl+z> fg; notify_me
2010-05-20 16:16:43
User: recursiverse
26

If you want to be notified when a long-running command is finished, but you have already started it:

CTRL+Z

fg; echo "finished" | sendmail me@example.com

I use a script to post a tweet, which sends me a txt:

fg; echo "finished" | tweet
nl
ccze
2009-11-23 15:54:33
User: tiagofischer
26

CCZE is a robust and modular log coloriser, with plugins for apm, exim, fetchmail, httpd, postfix, procmail, squid, syslog, ulogd, vsftpd, xferlog and more.

Examples:

tail -f /var/log/messages | ccze -A

tail -f /var/log/exim4/mainlog | ccze -A

history -d
2009-04-27 20:19:09
User: sud0er
Tags: bash
26

If you're a moron like me, sometimes your fingers get away from you and you, for example, enter your password when you're already authenticated to ssh-agent, sudo, etc., and your password ends up in shell history. Here's how to get it out.