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,592 results
dd if=/dev/zero of=/dev/null bs=1M count=32768
2009-02-16 12:22:18
Functions: dd
42

Read 32GB zero's and throw them away.

How fast is your system?

mount /path/to/file.iso /mnt/cdrom -oloop
2009-02-05 17:28:06
User: nerd65536
Functions: mount
Tags: mount iso
42

"-o loop" lets you use a file as a block device

du -s * | sort -n | tail
chmod --reference file1 file2
2010-03-31 12:05:48
User: rpavlick
Functions: chmod
Tags: chmod chown chgrp
41

Also works with:

chgrp --reference file1 file2 chown --reference file1 file2
ssh -t remote_host screen -r
2009-07-23 06:15:04
User: recursiverse
Functions: screen ssh
Tags: ssh screen
41

Directly attach a remote screen session (saves a useless parent bash process)

for code in {0..255}; do echo -e "\e[38;05;${code}m $code: Test"; done
2010-06-19 02:14:42
User: scribe
Functions: echo
Tags: bash color colors
40

Same as http://www.commandlinefu.com/commands/view/5876, but for bash.

This will show a numerical value for each of the 256 colors in bash. Everything in the command is a bash builtin, so it should run on any platform where bash is installed. Prints one color per line. If someone is interested in formatting the output, paste the alternative.

ssh -MNf <user>@<host>
2009-02-26 14:11:19
User: raphink
Functions: ssh
40

Create a persistent SSH connection to the host in the background. Combine this with settings in your ~/.ssh/config:

Host host

ControlPath ~/.ssh/master-%r@%h:%p

ControlMaster no

All the SSH connections to the machine will then go through the persisten SSH socket. This is very useful if you are using SSH to synchronize files (using rsync/sftp/cvs/svn) on a regular basis because it won't create a new socket each time to open an ssh connection.

ssh -t hostA ssh hostB
2009-08-27 21:35:19
User: 0x89
Functions: ssh
39

Of course you need to be able to access host A for this ;-)

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=OUTPUT.pdf -c .setpdfwrite -f INPUT.pdf
2009-12-14 21:30:22
User: deijmaster
Functions: gs
38

Remove security from PDF document using this very simple command on Linux and OSX. You need ghostscript for this baby to work.

dpkg -S /usr/bin/ls
2009-04-18 18:18:23
User: bwoodacre
38

'dpkg -S' just matches the string you supply it, so just using 'ls' as an argument matches any file from any package that has 'ls' anywhere in the filename. So usually it's a good idea to use an absolute path. You can see in the second example that 12 thousand files that are known to dpkg match the bare string 'ls'.

% screen -r someuser/
2009-03-25 23:59:38
User: totoro
Functions: screen
38

If you enable multiuser, then you can permit others to share your screen session. The following conditions apply:

1. screen must be suid root;

2. "multiuser on" must be configured in ~/.screenrc;

3. control the others user(s) access with "aclchg":

# ----- from ~/.screenrc-users -----

aclchg someuser +rx "#?" #enable r/o access to "someuser"

aclchg someuser -x "#,at,aclchg,acladd,acldel,quit" # don't allow these

aclchg otheruser +rwx "#?" # enable r/w access to "otheruser"

aclchg otheruser -x "#,at,aclchg,acladd,acldel,quit" # don't allow them to use these commands

# -----

After doing this (once), you start your session with:

$ screen

Then, the other user can join your terminal session(s) with youruserid:

$ screen -r youruserid/

Note: the trailing "/" is required.

Multiple users can share the same screen simultaneously, each with independent access controlled precisely with "aclchg" in the ~/.screenrc file.

I use the following setup:

# ~/.screenrc-base

# default screenrc on any host

source $HOME/.screenrc-base

source $HOME/.screenrc-$HOST

source $HOME/.screenrc-users

# -----

Then, the base configurations are in ~/.screenrc-base; the host-specific configurations are in ~/.screenrc-$HOST, and the user configurations are in ~/.screenrc-users.

The host-specific .screenrc file might contain some host-specific screen commands; e.g.:

# ~/.screen-myhost

# -----

screen -t 'anywhere' /bin/tcsh

screen -t 'anywhere1' /bin/tcsh

# ----

The .screenrc-base contains:

# ~/.screenrc-base

## I find typing ^a (Control-a) awkward. So I set the escape key to CTRL-j instead of a.

escape ^Jj

termcapinfo xterm* ti@:te@:

autodetach on

zombie kr

verbose on

multiuser on

echo "rm -rf /unwanted-but-large/folder" | batch
2009-02-04 19:07:52
User: root
Functions: echo
38

Good for one off jobs that you want to run at a quiet time. The default threshold is a load average of 0.8 but this can be set using atrun.

bind -P
2012-05-28 18:51:59
User: ricardofunke
37

This command shows the various shortcuts that can be use in bash, including Ctrl+L, Ctrl+R, etc...

You can translate "\C-y" to Ctrl+y, for example.

sudo touch /forcefsck
2009-10-29 17:04:47
User: johnraff
Functions: sudo touch
37

The empty file /forcefsck causes the file system check fsck to be run next time you boot up, after which it will be removed.

This works too:

sudo >/forcefsck
sed -n 5p <file>
2009-10-15 11:00:48
User: Waldirio
Functions: sed
37

You can get one specific line during any procedure. Very interesting to be used when you know what line you want.

ls -d */
2009-10-08 22:07:22
User: brianmuckian
Functions: ls
37

-d: list directory entries instead of contents, and do not dereference symbolic links

ps awwfux | less -S
2009-07-04 09:39:28
User: ToyKeeper
Functions: less ps
37

If you want a visual representation of the parent/child relationships between processes, this is one easy way to do it. It's useful in debugging collections of shell scripts, because it provides something like a call traceback.

When a shell script breaks, just remember "awwfux".

wget http://www.youtube.com/watch?v=dQw4w9WgXcQ -qO- | sed -n "/fmt_url_map/{s/[\'\"\|]/\n/g;p}" | sed -n '/^fmt_url_map/,/videoplayback/p' | sed -e :a -e '$q;N;5,$D;ba' | tr -d '\n' | sed -e 's/\(.*\),\(.\)\{1,3\}/\1/' | wget -i - -O surprise.flv
2011-01-25 04:19:06
User: Eno
Functions: sed tr wget
36

Nothing special required, just wget, sed & tr!

rtfm() { help $@ || man $@ || $BROWSER "http://www.google.com/search?q=$@"; }
script -qf | tee >(nc -kl 5000) >(nc -kl 5001) >(nc -kl 5002)
2010-10-11 07:55:30
User: clvv
Functions: script tee
Tags: tee pipe script nc
36

run 'nc yourip 5000', 'nc yourip 5001' or 'nc yourip 5002' elsewhere will produce an exact same mirror of your shell. This is handy when you want to show someone else some amazing stuff in your shell without giving them control over it.

google docs edit --title "To-Do List" --editor vim
2010-06-21 16:15:42
User: spiffwalker
Tags: google
36

Google just released a new commend line tool offering all sorts of new services from the commend line. One of them is uploading a youtube video but there are plenty more google services to interact with.

Download it here: http://code.google.com/p/googlecl/

Manual: http://code.google.com/p/googlecl/wiki/Manual

This specific command courtesy of lifehacker:http://lifehacker.com/5568817/

Though all can be found in manual page linked above.

tar -tf <file.tar.gz> | xargs rm -r
lsmod | perl -e 'print "digraph \"lsmod\" {";<>;while(<>){@_=split/\s+/; print "\"$_[0]\" -> \"$_\"\n" for split/,/,$_[3]}print "}"' | dot -Tpng | display -
2011-11-27 14:02:35
User: bandie91
Functions: dot lsmod perl
35

parse `lsmod' output and pass to `dot' drawing utility then finally pass it to an image viewer

timeout 5s COMMAND