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,591 results
perl -pe 's/.+;//' ~/.zsh_history | sort | uniq -c | sort -r|head -10
alias rot13='perl -pe "y/A-Za-z/N-ZA-Mn-za-m/;"'
guid(){ lynx -nonumbers -dump http://www.famkruithof.net/uuid/uuidgen | grep "\w\{8\}-" | tr -d ' '; }
perl -le 'print join ", ", map { chomp; $_ } <>'
2009-02-06 12:50:43
User: jozef
Functions: join perl
-1

joins multiple lines to create single line with comma separated values. for example if we have an email addresses one per line (copy&paste from spreadsheet) it will oputput one line with comman separated addresses to put it to email client.

gsed -e :a -e 's/\(<\/[^>]*>\)/\1\n/g;s/\(<br>\)/\1\n/g' page2.txt | sed -n '/<cite>/p;s/<cite>\(.*\)<\/cite>/\1/g' >> output
2009-02-06 12:45:20
User: shrimphead
Functions: sed
-1

From a saved page of google search results, split out all of the links for the results. Useful for creating apache rewrite rules from.

perl -MHTML::Entities -ne 'print encode_entities($_)' /tmp/subor.txt
2009-02-06 12:44:24
User: jozef
Functions: perl
1

Encodes HTML entities from input (file or stdin) so it's possible to directly past the result to a blog or HTML source file.

find ~ -name '*.mp4' | xargs mplayer
rsync -av --progress ./file.txt user@host:/path/to/dir
2009-02-06 11:51:51
User: aoiaoi
Functions: rsync
7

transfer files from localhost to a remotehost.

sed "s/^ABC/+ABC/" <file | sed "s/DEF$/DEF+/" | tr "\n" "~" | tr "+" "\n" | grep "^ABC" | tr "~" "\n"
2009-02-06 11:29:29
User: poboxy
Functions: grep sed tr
2

If the file content is :

-

Blah blah blah

ABC

hello blah blah blah

bloh bloh bloh

DEF

Bah bah bah

-

You'll get:

-

ABC

hello blah blah blah

bloh bloh bloh

DEF

find . -exec grep "test" '{}' /dev/null \; -print
fuman(){ lynx -width=$COLUMNS -nonumbers -dump "http://www.commandlinefu.com/commands/using/$1" |sed '/Add to favourites/,/This is sample output/!d' |sed 's/ *Add to favourites/----/' |less -r; }
ssh -N -L2001:localhost:80 -o "ProxyCommand ssh someuser@hubmachine nc -w 5 %h %p" someuser@destinationmachine
2009-02-06 09:58:08
Functions: ssh
4

this is handy when the hubmachine is the only machine that can connect to the destination machine (allowed on ip by firewall) and you want to access it from your laptop.

awk '!_[$0]++{print}'
cd -
touch /forcefsk
pv access.log | gzip > access.log.gz
2009-02-06 08:50:40
User: p3k
Functions: gzip
49

Pipe viewer is a terminal-based tool for monitoring the progress of data through a pipeline. It can be inserted into any normal pipeline between two processes to give a visual indication of how quickly data is passing through, how long it has taken, how near to completion it is, and an estimate of how long it will be until completion. Source: http://www.catonmat.net/blog/unix-utilities-pipe-viewer/

cat file.txt|perl -ne '$_=~s/\s+/\n/g; print $_;'
2009-02-06 08:47:18
User: foodie
Functions: cat
-4

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.

for i in $(ls /the/path); do du -hs /the/path/$i; done
ps awwux|awk '{print $1}'|sort|uniq
date --utc --date "2009-02-06 09:57:54" +%s
2009-02-06 08:29:12
User: michelem
Functions: date
2

Simple way to get a timestamp from a date

(sed 's/^/x+=/' [yourfile] ; echo x) | bc
2009-02-06 08:25:43
User: michelem
Functions: echo sed
7

If you have a file full of numbers written line by line, you can sum every line to get the total.

With a file like this:

3443535

9878977

67554

987798

232324

you will got:

14610188

grep -r -l xxxxx . | xargs perl -i -pe "s/xxxxx/yyyyy/g"
2009-02-06 08:18:50
User: hassylin
Functions: grep perl xargs
-1

This script first find all files which contains word xxxxx recursively. Then replace the word xxxxx to yyyyy of the files.

Use case:

- Web site domain change

- Function name change of the program

$ python -m pygments -o source.html source.py
2009-02-06 08:00:02
User: antrix
Functions: python
1

You can specify various output formats, theme styles, etc.

python -m pygments -o source.png source.py python -m pygments -o source.rtf source.py

Check available output formats, styles, etc.:

python -m pygments -L

Find pygments module here: http://pygments.org/

trap '' 1 2 20 24(signal number)
find . -name "*~" -exec rm {} \;