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,363 results
wget -qO - --post-data "data[Row][clear]=text" http://md5-encryption.com | grep -A1 "Md5 encrypted state" | tail -n1 | cut -d '"' -f3 | sed 's/>//g; s/<\/b//g'
2011-10-13 03:44:48
User: samhagin
Functions: cut grep sed tail wget
Tags: md5

Encrypt any text to MD5 , replace text with the string you want to convert to MD5

perl -MO=Deparse filename.pl | perltidy > new.pl
2011-11-16 18:54:30
User: kimmel
Functions: perl

This will create a new file with proper code formatting and all comments removed.

groovy -e "def output=args[0]; def terms = args[1].split(','); terms.each { it -> def keyValues = it.split(':'); output = output.replaceAll(keyValues[0],keyValues[1]); } println output;" "`diff -rq . SRC DEST`" "old1:new1,old2:new2"
2012-03-24 02:52:22
User: airline

Script has to be modified to be executable! SRC and DEST a relative unix path, olds and news are the terms to be modified.

Very helpful to sync source folders present in different SCM.

If you dont like this one, just use rsync...

cloc --force-lang=yaml --match-f='\.url$' .
watch 'mysql -e "show full processlist;"'
find . -type f -exec grep -Hn <pattern> {} \;
curl -L -d "uid=<username>&pwd=<password>" http://www.example.com -c cookies.txt
2012-11-10 19:08:45
User: drwlrsn
Tags: curl http python

Generate a Netscape cookies file to use with Python's mechanize.

for code in $(seq -w 0 255); do for attr in 0 1; do printf "%s-%03s %bTest%b\n" "${attr}" "${code}" "\e[${attr};38;05;${code}m" "\e[m"; done; done | column -c $((COLUMNS*2))
2013-01-13 18:23:44
User: claudius
Functions: column printf seq
Tags: bash color colors

Shows the ?rendering? for each of the 256 colours in both the bold and normal variant. Using seq is helpful to get even lines, passing $((COLUMNS*2)) to column sort-of-handles the nonprintable characters.

pwd|grep -o '/'|perl -ne '$x.="./.";print`readlink -f $x`'|xargs -tn1 chmod 755
2013-03-14 12:03:44
Functions: chmod grep perl pwd xargs

`pwd` returns the current path

`grep -o` prints each slash on new line

perl generates the paths sequence: './.', './../.', ...

`readlink` canonicalizes paths (it makes the things more transparent)

`xargs -tn1` applies chmod for each of them. Each command applied is getting printed to STDERR.

find .git/objects -type f -printf "%P\n" | sed s,/,, | while read object; do echo "=== $obj $(git cat-file -t $object) ==="; git cat-file -p $object; done
ps -eo pmem,comm | grep chrome | cut -d " " -f 2 | paste -sd+ | bc
2014-01-03 15:33:16
User: Darkstar
Functions: cut grep paste ps

This command will show the sum total of memory used in gigabytes by a program that spawns multiple instances of itself. Replace chrome with whatever program's memory usage you are investigating. This command is rather useless on software that only spawns a single instance of itself.

tail -f *.log | grep --color=always '|==>.+<=='
2014-07-11 07:47:27
User: danimath
Functions: grep tail
Tags: grep tail -f

This shows the the filenames of tail output in color. Helpful if you have many log files to tail

find cvsdir -name Root -exec sed -i 's/oldserver/newserver/' {} \;
2009-02-19 04:31:13
User: mulad
Functions: find sed

If your CVS server has moved, here's a way to update your CVS Root files throughout your code tree without checking out a new copy of your files.

sed ':a;N;$!ba;s/\n/ /g'
2009-03-17 20:54:04
User: cidiom
Functions: sed
Tags: Linux

Ever had a file with a list of numbers you wanted to add, use:

cat file | sed ':a;N;$!ba;s/\n/+/g' | bc
find /home/user/doc/ -type d -printf "mkdir -vp '/home/user/Dropbox%p'\n" -o -type f -printf "ln -vs '%p' '/home/user/Dropbox%p'\n" | sh
2009-03-29 09:25:12
User: jnash
Functions: find

Extremely useful to maintain backups if you're using Dropbox. This mirrors the entire directory structure and places symlinks in each to the original file. Instead of copying over the data again to the ~/Dropbox folder creating a symbolic link tree is much more sensible in terms of space usage.

This has to be supplemented by another script that removes dead symlinks in the Dropbox folder which point to files that have been moved/removed.

find -L ./ -type l -delete

And then removing empty directories

find ./ -type d -exec rmdir 2>/dev/null {} \;

**Actually after some finding I found lndir which creates symbolic trees but it wasn't in the Arch repos so.. ;)

x=1 ; while [ $x -le 10 ] ; do lynx -dump http://www.alexa.com/siteinfo/http://[YOUR WEBSITE] | grep Global | sed 's/ \|Global\|\,//g' >> /var/log/alexa-stats.txt ; sleep 5h ; done &
2009-10-17 13:48:05
User: felix001
Functions: grep sed sleep

This will record the Alexa Traffic Stats to a file and run every 5 hours.

-- www.fir3net.com --

git log --format=%H | tail -1
2010-07-20 08:12:05
User: l0b0
Functions: tail
Tags: git commit

Can anyone make a shorter one?

This doesn't work:

git log --reverse -1 --format=%H
cat /etc/services | egrep [[:blank:]]<port_number>/
find $DIR -exec bash method {} ";"
2011-03-28 02:41:02
User: netzahdzc
Functions: bash find

An easy way to send all directories to a bash script, it makes it recursive

echo | gcc -dM -E -
while sleep 30; do tput sc;tput cup 0 $(($(tput cols)-15));echo -n " New Emails: $(curl -u username:password --silent https://mail.google.com/mail/feed/atom | grep 'fullcount' | grep -o '[0-9]\+')";tput rc; done &
function right { bc <<< "obase=8;ibase=2;$1"; }; touch foo; chmod $(right 111111011) foo; ls -l foo
2011-11-16 22:43:31
User: nerd
Functions: bc chmod ls touch

I simply find binary notation more straightforward to use than octal in this case.

Obviously it is overkill if you just 600 or 700 all of your files...

x="/tmp/auth.html";sudo cat /var/log/auth.log | logtool -o HTML >$x;xdg-open $x;rm $x
2012-02-09 13:36:21
Functions: cat rm sudo

similar to previous except this exports to a temporary file, opens that file with your default web browser, then deletes it.

avconv -i input.avi -target pal-dvd dvd.mpg && echo PAL > ~/.config/video_format && dvdauthor -o dvd/ -t dvd.mpg && dvdauthor -o dvd/ -T && growisofs -Z /dev/dvd -dvd-video dvd/
2012-09-09 20:56:54
User: ppq
Functions: echo

This is the fastest way to burn a DVD-Video from the command line.





The first command:

avconv -i input.avi -target pal-dvd dvd.mpg

converts any given video file avconv can handle into MPEG2-PS (6 Mbit/s) with AC3 audio (448 kbit/s). If your distribution is not up to date, just use ffmpeg - the syntax is the same. Hint: If you want to create an NTSC DVD, type ntsc-dvd instead ;-)

The second command:

echo PAL > ~/.config/video_format

sets PAL as your default video format. This is a workaround for an old dvdauthor bug. If you want NTSC, guess what? Type NTSC instead!

The third command:

dvdauthor -o dvd/ -t dvd.mpg

creates .VOB files and adds them to the dvd/ folder. You don't have to create this folder yourself. You can add as many titles as you like, just keep in mind that there's a maximum of 4482 MiB (4.37 GiB) for normal DVDs.

The fourth command:

dvdauthor -o dvd/ -T

finishes the DVD-Video.

Now you can burn your DVD using growisofs:

growisofs -Z /dev/dvd -dvd-video dvd/