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,584 results
rsync -P -e 'ssh -p PORT' SRC DEST
2011-10-13 08:59:07
User: vickio
Functions: rsync
Tags: ssh rsync
-1

Transfer files with rsync over ssh on a non-standard port, showing a progress bar and resuming partial transfers.

perl -e 'print "$_=$ENV{$_}\n" for keys %ENV'
find . -name "*~" -exec rm {} \;
echo -e "12 morning\n15 afternoon\n24 evening" | awk '{if ('`date +%H`' < $1) print "Good " $2}'
tr '[:upper:]' '[:lower:]' < input.txt > output.txt
sudo curl "http://hg.mindrot.org/openssh/raw-file/c746d1a70cfa/contrib/ssh-copy-id" -o /usr/bin/ssh-copy-id && sudo chmod 755 /usr/bin/ssh-copy-id
2012-02-09 20:29:24
User: misterich
Functions: chmod sudo
-1

Mac install ssh-copy-id

From there on out, you would upload keys to a server like this:

(make sure to double quote the full path to your key)

ssh-copy-id -i "/PATH/TO/YOUR/PRIVATE/KEY" username@server

or, if your SSH server uses a different port (often, they will require that the port be '2222' or some other nonsense:

(note the double quotes on *both* the "/path/to/key" and "user@server -pXXXX"):

ssh-copy-id -i "/PATH/TO/YOUR/PRIVATE/KEY" "username@server -pXXXX"

...where XXXX is the ssh port on that server

watch -n 7 -d 'uptime | sed s/.*users?, //'
odmget -q "attribute=unique_id" CuAt |sed -n 's/.*name = "\(.*\)"/\1/p;s/.*value = "..........\(....\)..SYMMETRIX..EMCfcp.*"/0x\1/p;s/.*value =//p'
setopt correct
2012-09-11 01:47:20
User: evandrix
Tags: zsh
-1

zsh has a powerful correction mechanism. If you type a command in the wrong way it suggests corrections. What happend here is that dir is an unknown command and zsh suggests gdir, while maybe ls was what you wanted.

If you want to execute gdir hit y (yes)

If you want to try to execute dir anyway hit n (no)

If you want to execute completely different spelt command like ls hit a (abort) and type your command

If you want to execute a similar spelt commant like udir hit e (edit) and edit your command.

Limit kernel compilation load
for output in $(find . ! -name movie.nfo -name "*.nfo") ; do rm $output ; done
2014-04-01 17:41:50
User: analbeard
Functions: find rm
-1

Finds all nfo files without the filename movie.nfo and deletes them.

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

mount -t cd9660 /dev/`mdconfig -a -t vnode -f discimg.iso` /cdrom
2009-02-19 06:31:14
User: mulad
Functions: mount
-1

FreeBSD version of the Linux command

mount discimg.iso /cdrom -o loop

The "mdconfig" command creates a device and prints the name (typically "md0"). Just append that to "/dev/" and mount.

Once unmounted, you can unconfigure the device with

mdconfig -d -u 0

using "0" for md0, "1" for md1, etc.

Print to screen all the directories above the pwd, showing: mountpoints, symbolic links, and permissions (with colors)
2013-07-25 22:55:08
User: malathion
Functions: screen
Tags: sed namei
-1

Useful for finding out quickly if you're still in the same filesystem or are in a descendant of a symbolic link or mountpoint. For plain text output, unset the color substitutions or strip them from the function.

for f in .; do awk 'BEGIN {sum=0;flag=0} {sum=sum+$1; if (flag == 0) { print $1"\t"sum > "cumulative.'$f'" } if (sum > 100) flag=1 }' $f; done
rsstail -o -n 1 --f 'RedditQuote: {title}' http://www.reddit.com/r/quotes/new/.rss
2014-01-08 15:33:48
User: Youpfu
-1

The rsstail is the python version (python-rsstail). The final command pipe it on every new line to gammu and a connected phone

rsstail -o -n 1 --f 'RedditQuote: {title}' http://www.reddit.com/r/quotes/new/.rss | while read line; do /usr/bin/gammu --sendsms TEXT +*yournumber* -text "$line"; done
rsync -avz --dry-run /somewhere/source_directory /somewhereelse/target_directory
2014-04-01 20:55:59
User: tsener
Functions: rsync
Tags: diff rsync
-1

--dry-run will only show you which files would be otherwise synced with rsync.

-z is for compressio

-v vervose

-a "as is" - permissions, ownership etc.

find . | grep -v svn
2011-01-16 03:51:57
User: gwchamb
Functions: find grep
Tags: grep
-1

Unless you have files that include 'svn' in them, this should provide enough information to be useful. If you need to be certain, add the leading dot in the search pattern

skill -KILL -t ttyS0
2009-05-26 21:47:33
User: jipipayo
Functions: skill
-1

when sometimes do a "w" or "who" command and see an orphan console session from time ago, you could kill with this command.

where ttyS0 its the console to kill.

rxvt-unicode -g 999x999 -sr -depth 32 -bg rg-ba:0000/0000/0000/dddd +sb -T irssi -n irssi -name irssichat -e ssh server.com -Xt screen -aAdr -RR irssi irssi
2009-07-30 04:53:17
User: MTecknology
Functions: screen ssh
-1

This will launch and irssi session on your server. If it's not running, it will create the session. If it's running it'll connect to it and destroy any other connections. If compositing is available, the rxvt window will have transparency added. This window will also open maximized. Anything else this does should be easily figured out in the man pages.

aptitude search ~d<string>
2011-08-02 05:19:13
-1

Especially useful for latex packages, which are listed in the description of their Ubuntu package E.g. say I want to find the Ubuntu package containing latex package aeguill:

aptitude search ~daeguill

p texlive-lang-french - TeX Live: French

cvs checkout -l project/src/
du -hs `du -sk * | sort -rn | cut -f2-`
awk 'BEGIN {count=0;prev=-1} {if(count>0) { if(int($1/100) > int(prev/100)) {print $1} } ; prev=$1; count++}' inputFile > rounded
CMD=chrome ; ps h -o pmem -C $CMD | awk '{sum+=$1} END {print sum}'