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,493 results
rm -rf `find . -name .svn`
2010-02-23 08:35:06
User: jfcalvo
Functions: rm
-2

Recursively remove .svn directories from the current location.

wget http://www.whatismyip.org --quiet -O - | cat
ntfsresize --size X[k,M.G] /dev/hda1
2011-07-02 17:47:05
User: 0disse0
Tags: ntfs
-2

With this command you can resize an NTFS partition by specifying the new size (X) in Kbytes, Mbytes or Gbytes. If you plan to do this it is advisable to precede --no-action parameter to size

see more:

http://ubuntuforums.org/showthread.php?t=1244058

and

http://en.wikipedia.org/wiki/Ntfsresize

ldapsearch -xLLL -b "cn=schema" "(objectclass=*)" \ \* objectclasses attributetypes | perl -p0e 's/\n //g'
2012-04-04 13:31:31
User: ioggstream
Functions: perl
-2

Dump 389ds schema, putting "\n " on one line with perl.

You have to specify the objectclasses, attributetypes operational attributes too, otherwise they won't be dumped!

find path/to/folder/ -type f -print0 | xargs -0 -n 1 md5sum | awk '{print $1}' | sort | md5sum | awk '{print $1}'
2009-02-16 19:39:37
User: mcover
Functions: awk find md5sum sort xargs
-2

For quick validation of folder's file-contents (structure not taken into account) - I use it mostly to check if two folders' contents are the same.

nmap -sS -O -v -oS - 192.168.2.0/24
alias mux='clear && cd ~/Music/ && ls && echo -n "File> " && read msi && mplayer ~/Music/$msi'
2009-03-23 10:45:27
User: Noxn
Functions: alias cd echo ls read
-2

An alias i made for myself to play music in a faster way.

Works great when you have Guake / Tilda installed (Console that drops down like in the game QUAKE)

---

I put this in my bash_alias file (I'm on ubuntu, the bash_alias file does autostart with the right config) but it works putting it in bashrc too. Or anything that autostarts when the console is opened.

---

Needs Mplayer and music files to work. With out music theres nothing to play!

Oh, and also, without modification, this alias will try to play stuff from your ~/Music folder! (case sensitive). Make sure that folder exists and has music OR edit this alias to fit your needs.

sed 's/$'"/`echo \\\r`/"
lynx --dump "http://checkip.dyndns.org"
w3m miip.cl | grep ip
2009-10-26 01:40:37
User: Cont3mpo
Functions: grep
-2

See external ip with w3m, simple and fast.

On a web site from Chile (spanish).

echo "Starting Daemon"; ( while :; do sleep 15; echo "I am still running =]"; done ) & disown -h $!
2010-02-23 19:17:05
User: daleki
Functions: echo sleep
-2

You don't want the -ar parameters in this case. The man page for BASH_BUILTINS(1) states:

"-a option means to remove or mark all jobs" and

"-r option without a jobspec argument restricts operation to running jobs"

In this case we are supplying the process id of the job to disown so neither of these should be used.

cat /usr/share/dict/words | grep -P ^[a-z].* | grep -v "'s$" | grep -Pv ^.\{1,15\}$ | shuf -n4 | tr '\n' ' ' | sed 's/$/\n/'
2011-08-15 01:03:48
User: bugmenot
Functions: cat grep sed tr
Tags: tr xkcd shuf
-2

The first grep rejects capitalised words since the dict has proper nouns in it that you mightn't want to use. The second grep rejects words with ending in apostrophe s, and the third forces the words to be at least 15 characters long.

alias cdc='cd `pwd -P`'
w3m http://amit-agarwal.co.in/mystuff/getip_txt.php will return the ip in text format.
wodim foo.iso
sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*"
2009-04-04 01:41:48
User: peterc
Functions: grep sudo tcpdump
-2

Replace "en1" with your network interface (on OS X, usually en0, en1, eth0, etc..)

umount -t smbfs
2012-02-23 10:46:44
User: Velenux
Functions: umount
Tags: samba
-2

smbfs or cifs, depends on which you are using

< /dev/urandom tr -dc A-Za-z0-9_ | head -c $((1024 * 1024)) | tee >(gzip -c > out.gz) >(bzip2 -c > out.bz) > /dev/null
cat /sys/devices/virtual/dmi/id/board_name
2010-04-22 03:21:40
User: matthewbauer
Functions: cat
-2

Prints the type of computer you have.

I think this should be used more in distros and other applications because it is so easy to get. This can also be asked by tutorials as an easy way to get your base hardware.

Some alternatives:

sudo dmidecode -s system-product-name

and

sudo smbios-sys-info-lite | sed -n 's/^Product Name: *\(.*\)/\1/p'
/sbin/ifconfig|grep -B 1 inet |head -1 | awk '{print $5}'
tar -C <source> -cf - . | tar -C <destination> -xf -
find . -name "*.gz" | xargs -n 1 -I {} bash -c "gunzip -c {} | sort | gzip -c --best > {}.new ; rm {} ; mv {}.new {}"
2009-08-05 14:16:15
User: kennethjor
Functions: bash find xargs
-2

I used this because I needed to sort the content of a bunch of gzipped log files. Replace sort with something else, or simply remove sort to just rezip everything

while read ; do python <script> ; done
2012-02-23 22:29:09
User: Zulu
Functions: python read
-2

Very useful for test a script. After launch this command, you only have to press ENTER for launch your script again. I work with screen and tape ENTER instead of '!!'+ENTER

If you break your script with CTRL-C, it will wait for press ENTER and will re-launch

You can write like it : while read -p "Press ENTER" ; do python ; done