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

Commands by dbh from sorted by
Terminal - Commands by dbh - 9 results
less -p pattern file.txt
scanimage -p --resolution 250 --mode Gray -x 215.9 -y 279.4 | pnmtops -imageheight 11 -imagewidth 8.5 | ps2pdf - output.pdf
2013-04-12 18:18:42
User: dbh
Functions: scanimage
Tags: pdf scan scanner
3

Adjust the --resolution and --mode as required (if these options are available for your scanner).

The size options (-x, -y, -imageheight, -imagewidth) are for US letter paper. For A4, I think the command would be:

scanimage -p --resolution 250 --mode Gray -x 210 -y 297 | pnmtops -imageheight 11.7 -imagewidth 8.3 | ps2pdf - output.pdf
manswitch () { man $1 | less -p "^ +$2"; }
2011-08-19 16:44:48
User: dbh
Functions: less man
Tags: grep switch
13

e.g.

manswitch grep -o

This will take you to the relevant part of the man page, so you can see the description of the switch underneath.

sudo bash -c "sleep 1h ; command"
2011-06-15 16:46:31
User: dbh
Functions: bash sudo
4
sleep 1h ; sudo command

or

sudo sleep 1h ; sudo command

won't work, because by the time the delay is up, sudo will want your password again.

firefox http://en.wikipedia.org/wiki/$(date +'%b_%d')
quickemail() { echo "$*" | mail -s "$*" email@email.com; }
2011-02-22 20:33:18
User: dbh
Functions: echo mail
3

I created this so I could send myself an email alert when a long-running job was finished, e.g.,

my_long_job.exe ; quickemail my_long_job.exe has finished
rcsdiff -y myfile
2010-06-14 15:49:42
User: dbh
0

Use -W to adjust the width of the output, and --suppress-common-lines to show only the lines that have been changed.

sdiff file1 file2
2010-06-14 15:47:12
User: dbh
Functions: sdiff
3

I found out about this from Unix Power Tools, and thought it was pretty useful.

Use the -w option to change the width of the output, and the -s option to suppress lines that are the same in both files.

alias termsize='echo $COLUMNS x $LINES'