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,858 results
find . -not \( -name .svn -prune \) -type f -print0 | xargs --null grep <searchTerm>
2009-07-08 20:08:05
User: qazwart
Functions: find grep xargs
Tags: find xargs grep
8

By putting the "-not \( -name .svn -prune \)" in the very front of the "find" command, you eliminate the .svn directories in your find command itself. No need to grep them out.

You can even create an alias for this command:

alias svn_find="find . -not \( -name .svn -prune \)"

Now you can do things like

svn_find -mtime -3
sed -r 's/[ \t\r\n\v\f]+/\^J/g' INFILE > OUTFILE
2009-07-08 19:59:33
User: qazwart
Functions: sed
0

What happens if there is more than a single space between words, or spaces and tabs? This command will remove duplicate spaces and tabs.

The "-r" switch allows for extended regular expressions. No additional piping necessary.

pv large.xml | xclip
2009-07-08 19:26:12
User: marssi
5

shortest alternative without the speed-o-meter"xclip large.xml"

"xclip -o" to get the clipboard content, alternatively [shift key] + insert or middle button of your mouse.

perl -e 'print "P1\n256 256\n", map {$_&($_>>8)?1:0} (0..0xffff)' | display
2009-07-08 17:50:23
User: dstahlke
Functions: perl
25

OK, not the most useful but a good way to impress friends. Requires the "display" command from ImageMagick.

cat large.xml | xclip
2009-07-08 16:30:07
User: copremesis
Functions: cat
0

avoid mouse abuse and the constant struggle of balancing scroll velocity ... not to mention that burning sensation in your upper right shoulder ....

egrep --color=auto 'usb|' /var/log/messages
2009-07-08 15:20:31
User: ioggstream
Functions: egrep
4

this is useful to highlight only some code without losing other lines (eg. software, logs, scripts)

some command|xsel --clipboard
2009-07-08 11:52:48
Tags: clipboard xsel
21

In turn you can get the contents of your clipboard by typing xsel by itself with no arguments:

xsel

This command requires you to install the xsel utility which is free

du -hs /example/folder/
df -h
2009-07-08 11:25:28
User: Paaskehare
Functions: df
-5

Bulit-in function in linux, so should work on any linux distribution.

for f in $(find * -maxdepth 0 -type f); do file=$(find ~/target -name $f); if [ -n "$file" ]; then cp $file ${file}.bak; mv $f $file; fi; done
2009-07-08 10:18:06
User: sanmiguel
Functions: cp find mv
0

You could start this one with

for f in *; do

BUT using the find with "-type f" ensures you only get files not any dirs you might have

It'll also create backups of the files it's overwriting

Of course, this assumes that you don't have any files with duplicated filenames in your target structure

unzip -lt foo.zip | grep testing | awk '{print $2}' | xargs rm -r
l=500; x=500; y=200; d=-15;for i in `seq $x $d $y`; do beep -l $l -f $i;done
2009-07-07 22:12:20
Tags: bash beep sound
0

Generates a frequency sweep from $x to $y, with $d numbers inbetween each step, and with each tone lasting $l milliseconds.

test `uname` = Linux && lsb_release -a || ( test `uname` = SunOS && cat /etc/release || uname -rms )
2009-07-07 20:51:30
User: virtualshock
Functions: cat test uname
-7

Found in comments section works on most Linux flavors.

vmrun list
2009-07-07 12:13:50
0

Shows a list of running virtual machines on a vmware host (workstation/server/esx/etc.)

Again, this command is vmware-specific.

There are also other things you can do with `vmrun`. Just simply type vmrun by itself (no arguments) to get a readout of other things you can do with it.

vmrun start /path/to/virtual_machine.vmx nogui
2009-07-07 12:11:45
0

There is no output from this command. The command boots a virtual machine and you will have to wait for the boot sequence to complete before you can ping or connect to the virtual machine via ssh/rdp/vnc/nx/etc.

mount -t vfat /dev/sdx1 /media/psp/
cp texfile.toc texfile.toc.bak; latex texfile.tex; cmp -s texfile.toc texfile.toc.bak; if [ $? -ne 0 ]; then latex texfile.tex; fi
2009-07-07 07:09:45
User: gwiener
Functions: cmp cp
2

To check if the table-of-content in a LaTeX document is up-to-date, copy it to a backup before running LaTeX and compare the new .toc to the backup. If they are identical, it is updated. If not, you need to run LaTeX again.

egrep "(There were undefined references|Rerun to get (cross-references|the bars) right)" texfile.log
2009-07-07 06:48:03
User: gwiener
Functions: egrep
Tags: latex
0

LaTeX is not a smart compiler - You need to run it several times to make it back-patch all the missing refs. The message if to do so or not is buried in its endless output and the log file. This grep lines helps to find it.

< <infile> tr ' \t' '\n' | tr -s '\n' > <outfile>
2009-07-07 01:17:47
User: qubyte
Functions: tr
Tags: shell tr
-1

Puts words on new lines, removing additional newlines.

tar -tf <file.tar.gz> | xargs rm -r
tr ' \t' '\n' <INFILE >OUTFILE
2009-07-06 21:24:44
User: CharlieInCO
Functions: tr
Tags: shell
2

Simply translates whitespace to newlines. Could be enhanced to compress out extra newlines, but that might be better handled in the next tool down the pipe, with eg uniq(1).

for i in $(tar -tf <file.tar.gz>); do rm $i; done;
2009-07-06 19:57:23
User: din7
Functions: rm tar
-4

Remove annoying improperly packaged files that untar into the incorrect directory.

Example, When you untar and it extracts hundreds of files into the current directory.... bleh.

# dd if=/dev/sda | gzip -c | ssh user@ip 'dd of=/mnt/backups/sda.dd'
awk '{c=split($0, s); for(n=1; n<=c; ++n) print s[n] }' INPUT_FILE > OUTPUT_FILE
2009-07-06 06:10:21
User: agony
Functions: awk
Tags: awk
0

Basically it creates a typical word list file from any normal text.

ruby -e " 3.times { system 'pdflatex mydoc.tex' } "
2009-07-05 09:55:59
0

When I make a latex document, I need to compile three times for generate an updated index of contents. With ruby on command line, I run this operation with a fast one liner.