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.

Universal configuration monitoring and system of record for IT.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





All commands from sorted by
Terminal - All commands - 12,273 results
du -s * | sort -n | tail
grep -RnisI <pattern> *
2009-09-22 15:09:43
User: birnam
Functions: grep
Tags: bash grep

This is how I typically grep. -R recurse into subdirectories, -n show line numbers of matches, -i ignore case, -s suppress "doesn't exist" and "can't read" messages, -I ignore binary files (technically, process them as having no matches, important for showing inverted results with -v)

I have grep aliased to "grep --color=auto" as well, but that's a matter of formatting not function.

dd if=/dev/zero of=/dev/null bs=1M count=32768
2009-02-16 12:22:18
Functions: dd

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

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

ssh-keygen -R <the_offending_host>
2010-07-11 19:37:24
User: bunam
Functions: ssh ssh-keygen
Tags: sed

In this case it's better do to use the dedicated tool

chmod --reference file1 file2
2010-03-31 12:05:48
User: rpavlick
Functions: chmod
Tags: chmod chown chgrp

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

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

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

'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'.

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

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.

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

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.

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

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

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

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

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

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".

rtfm() { help $@ || man $@ || $BROWSER "http://www.google.com/search?q=$@"; }
sed -n 5p <file>
2009-10-15 11:00:48
User: Waldirio
Functions: sed

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

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

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

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.

timeout 5s COMMAND
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

Nothing special required, just wget, sed & tr!

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

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.

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

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
ls -d */
2009-10-08 22:07:22
User: brianmuckian
Functions: ls

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

tar -tf <file.tar.gz> | xargs rm -r
date --set="$(ssh user@server date)"
2011-08-30 20:03:06
User: splante
Functions: date
Tags: ssh ,NTP ,Date

Shorter, easier to remember version of cmd#7636

NTP is better, but there are situations where it can't be used. In those cases, you can do this to sync the local time to a server.

wget -q -U Mozilla -O output.mp3 "http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=hello+world
2011-03-08 14:05:36
User: sairon
Functions: wget

EDIT: command updated to support accented characters!

Works in any of 58 google supported languages (some sound like crap, english is the best IMO).

You get a mp3 file containing your query in spoken language. There is a limit of 100 characters for the "q" parameter, so be careful. The "tl" parameter contains target language.