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.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

All commands from sorted by
Terminal - All commands - 12,392 results
find . -name "*.sql" -print0 | wc -l --files0-from=-
2009-06-22 17:45:03
User: vincentp
Functions: find wc
Tags: find wc count line

This command gives you the number of lines of every file in the folder and its subfolders matching the search options specified in the find command. It also gives the total amount of lines of these files.

The combination of print0 and files0-from options makes the whole command simple and efficient.

multitail /var/log/messages /var/log/apache2/access.log /var/log/mail.info
2009-06-22 06:51:11
User: Neo23x0

It works like a "tail -f" on several files.

Use the number keys 0-9 to set a baseline in the numbered window.

Pressing "b" let you scroll back in one of the windows.

while true; do { $(which logger) -p local4.notice `free -m | grep Mem`; sleep 60; } done &
2009-06-22 00:29:53
User: Neo23x0
Functions: grep sleep which

Uses logger in a while loop to log memory statistics frequently into the local syslog server.

bind '"\e[24~"':"\"ps -elF;df -h;free -mt;netstat -lnpt;who -a\C-m"""
2009-06-21 23:57:20
User: Neo23x0

Command binds a set of commands to the F12 key.

Feel free to alter the dashboard according to your own needs.

How to find the key codes?



Then press the desired key (example: F5)



bind '"\e[15~"':"\"ssh [email protected]\C-m"""


bind '"\e[16~"':"\"apachectl -k restart\C-m"""
2009-06-21 17:58:01
User: Neo23x0

!* is all of the arguments to the previous command rather than just the last one.

This is useful in many situations.

Here's a simple example:

vi cd /stuff


[exit vi, twice]


expands to: cd /stuff

# cd $partition; dd if=/dev/zero of=ShredUnusedBlocks bs=512M; shred -vzu ShredUnusedBlocks
2009-06-21 14:17:22
User: mpb
Functions: cd dd shred

This command securely erases all the unused blocks on a partition.

The unused blocks are the "free space" on the partition.

Some of these blocks will contain data from previously deleted files.

You might want to use this if you are given access to an old computer and you do not know its provenance.

The command could be used while booted from a LiveCD to clear freespace space on old HD.

On modern Linux LiveCDs, the "ntfs-3g" system provides ReadWrite access to NTFS partitions thus enabling this method to also be used on Wind'ohs drives.

NB depending on the size of the partition, this command could take a while to complete.

sudo sed 's/\o0/\n/g' "/proc/$(pidof -x firefox)/environ" ;# replace firefox
watch -t -n1 "date +%T|figlet"
2009-06-21 01:02:37
User: dennisw
Functions: watch

This command displays a clock on your terminal which updates the time every second. Press Ctrl-C to exit.

A couple of variants:

A little bit bigger text:

watch -t -n1 "date +%T|figlet -f big"

You can try other figlet fonts, too.

Big sideways characters:

watch -n 1 -t '/usr/games/banner -w 30 $(date +%M:%S)'

This requires a particular version of banner and a 40-line terminal or you can adjust the width ("30" here).

sudo pmset -a hibernatemode 1
2009-06-20 22:52:10
Functions: sudo

sudo pmset -a hibernatemode 1 sets hiberate on.

sudo pmset -a hibernatemode 0 sets hibernate off.

from the pmset man page:

0001 (bit 0) enables hibernation; causes OS X to write memory state to

hibernation image at sleep time. On wake (without bit 1 set) OS X will

resume from the hibernation image. Bit 0 set (without bit 1 set) causes

OS X to write memory state and immediately hibernate at sleep time.

I often change my MacBook's sleep state. So I created a function for bash to make it a little easier.


hibernate (on | off)

"hibernate on" will set your laptop to hibernate if the lid is closed.

"hibernate off" will set your laptop to sleep if the lid is closed.

### note : "proper" indentation isn't preserved on the website

function hibernate()


case "${1}" in


sudo pmset -a hibernatemode 1

echo Hibernate mode on.



sudo pmset -a hibernatemode 0

echo Hiberate mode off.



echo "I'm sorry Dave, but I can't do that."




To make things easier, add the proper line in your /etc/sudoers file so that your user may invoke pmset without a password. Here's how mine looks:

bwayne luna = NOPASSWD: /usr/bin/pmset

Don't forget that you must edit sudoers with `sudo visudo` from Terminal.app, and not by another text editor.

Sorry this is so Mac OS specific.

svn status | grep '!' | sed 's/!/ /' | xargs svn del --force
mplayer dvdnav:// -dvd-device foo.img -mouse-movements
unrar p -inul foo.rar|mplayer -
ffmpeg -an -f video4linux -s 320x240 -b 800k -r 15 -i /dev/v4l/video0 -vcodec mpeg4 myvideo.avi
2009-06-19 17:41:43
User: dcabanis

The option -an disables audio recording, -f forces the use of video4linux for the input, -s sets the video to the size 320x240, -b sets the recording bitrate, -r sets the frame rate to 15fps, -i gives the input device, -vcodec sets the output format.

Press Q to stop recording or you can specify the recording time with the -t option like -t 00:1:30

mencoder video.avi lavc -lavcopts vcodec=mpeg4:vbitrate=800 newvideo.avi
2009-06-19 17:30:46
User: dcabanis

Encode video.avi into newvideo.avi using the libav codec to produce an MPEG4 file with a bitrate of 800

mencoder -tv device=/dev/video1 tv:// -ovc copy -o video.avi
2009-06-19 17:21:33
User: dcabanis

video.avi is the resulting file. Press Ctrl+c to stop the recording. You can change the OVC option to another to record into a different format.

sed -n '/START/,${/STOP/q;p}'
2009-06-19 15:27:36
User: mungewell
Functions: sed
Tags: sed grep

GNU Sed can 'address' between two regex, but it continues parsing through to the end of the file. This slight alteration causes it to terminate reading the input file once the STOP match is made.

In my example I have included an extra '/START/d' as my 'start' marker line contains the 'stop' string (I'm extracting data between 'resets' and using the time stamp as the 'start').

My previous coding using grep is slightly faster near the end of the file, but overall (extracting all the reset cycles in turn) the new SED method is quicker and a lot neater.

:r! echo %
2009-06-19 12:17:28
User: miccaman
Functions: echo
Tags: vim

insert filename

Normal mode: "%p

Insert mode: %

:source ~/.vimrc
:set nomore :argdo %s/foo/bar/g | update
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
2009-06-19 10:23:38
User: plasticdoc
Functions: sed
Tags: Linux sed dpkg

will show:

installed linux headers, image, or modules: /^ii/!d

avoiding current kernel: /'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d

only application names: s/^[^ ]* [^ ]* \([^ ]*\).*/\1/

avoiding stuff without a version number: /[0-9]/!d

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
2009-06-19 10:11:00
User: plasticdoc
Functions: sed sudo xargs

will purge:

only installed apps: /^ii/!d

avoiding current kernel stuff: /'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d

using app names: s/^[^ ]* [^ ]* \([^ ]*\).*/\1/

avoiding stuff without a version number: /[0-9]/!d

gdiff --unified=10000 input.file1 inpute.file2 | egrep -v "(^\+[a-z]|^\-[a-z])"| sort > outputfile.sorted
2009-06-18 20:35:00
User: slashdot
Functions: egrep sort

This commands will make it easier to select only common items between two files being compared. If your lines start with things other than lowercase a-z, adjust this Regex appropriately. Number of lines in the output has been set to no more than 10000, and should be adjusted as needed.

iptables -t nat -A PREROUTING -p tcp --dport [port of your choosing] -j REDIRECT --to-ports 22
2009-06-18 17:38:59
User: brizznown
Functions: iptables

Stuck behind a restrictive firewall at work, but really jonesing to putty home to your linux box for some colossal cave? Goodness knows I was...but the firewall at work blocked all outbound connections except for ports 80 and 443. (Those were wide open for outbound connections.) So now I putty over port 443 and have my linux box redirect it to port 22 (the SSH port) before it routes it internally. So, my specific command would be:

iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 22

Note that I use -A to append this command to the end of the chain. You could replace that with -I to insert it at the beginning (or at a specific rulenum).

My linux box is running slackware, with a kernel from circa 2001. Hopefully the mechanics of iptables haven't changed since then. The command is untested under any other distros or less outdated kernels.

Of course, the command should be easy enough to adapt to whatever service on your linux box you're trying to reach by changing the numbers (and possibly changing tcp to udp, or whatever). Between putty and psftp, however, I'm good to go for hours of time-killing.

cut -d: -f1 /etc/passwd | grep -vE "#" | xargs -i{} crontab -u {} -l
2009-06-18 16:49:52
User: hoberion
Functions: crontab cut grep xargs

additionally use "find /etc/cron*" for cronscripts