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,859 results
convert -resize 200 -sharpen 40 some_file.pdf[0] some_file.jpg
2009-02-06 23:12:01
User: abcde
5

convert is included in ImageMagick. Don't forget the [X] (where X is the page number). [0] is the first page of the PDF.

date --date="1 fortnight ago"
2009-02-06 20:57:59
User: mkc
Functions: date
3

The date command does offset calculations nicely, handles concepts like "a month" as you'd expect, and is good for offsets of at least 100M years in either direction.

view `ls -1 access_log.* | tail -n 1`
2009-02-06 18:38:25
User: jimjmarion
Functions: tail
0

This command opens the latest, most current rotating apache access log for visual analysis and inspection. Run this command from the apache log directory. For error logs, replace access_log with error_log.

apt-show-versions -u
2009-02-06 17:56:13
User: cowholio4
Functions: apt
-3

apt-show-versions is a program that shows what packages in the system may be updated and several useful information. The -u option displays a list of upgradeable packages:

From: http://www.debian.org/doc/manuals/apt-howto/ch-helpers.en.html

dd if=/dev/sdX of=/root/sdX.bin bs=1M count=1
2009-02-06 17:45:59
User: dhing
Functions: dd
-4

This will copy the first 1MB of your /dev/sdX volume to your /root/sdX.bin file, where SDX is the name of the device you wish to copy the data from (Usually a hard disk)

NOTE: Make sure you capitalize the M in field for BS.

git svn --authors-file=some-authors-file clone svn://address/of/svn/repo new-git-dir
git diff HEAD..rev | git apply --index; git commit
2009-02-06 17:29:46
User: Pistos
Functions: diff
4

Use this to make a new commit that "softly" reverts a branch to some commit (i.e. squashes the history into an inverse patch). You can review the changes first by doing the diff alone.

convert -resize 50%x50% image{,_resize}.jpg
git daemon --reuseaddr --verbose --export-all --base-path=/parent/of/bare/git/repos
2009-02-06 17:25:04
User: Pistos
0

Use this to start git daemon serving all git repos under a path.

tail -f <filename> | grep -C <# of lines to show above and below> <text>
alias scd='dirs -v; echo -n "select number: "; read newdir; cd -"$newdir"'
cflow file.c | grep ':$' | sed 's/ <.*//'
tar -cvzf - /source/path | ssh <targethostname> -l <username> dd of=/destination/path/backupfile.tgz
2009-02-06 15:52:09
User: smm
Functions: dd ssh tar
1

Creates a quick backup with tar to a remote host over ssh.

mysqlcheck -a --auto-repair -c -o -uroot -p [DB]
2009-02-06 15:49:16
User: michelem
2

A useful way to do a full check and auto repair damaged databases

pg_dump -U postgres [nomeDB] > db.dump
file !$
2009-02-06 15:41:08
User: leprasmurf
Functions: file
15

Bash shortcut to work with the last argument of your last command

pidof () { ps acx | egrep -i $@ | awk '{print $1}'; }
perl -e "use SOAP::Lite"
2009-02-06 15:26:37
User: leprasmurf
Functions: perl
0

Quick command to check if Perl library is installed on your server.

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