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,927 results
/originalInstall/gem list | tr -d '(),' | xargs -L 1 sudo ./gemInst.sh
2009-07-09 21:46:06
User: snakerdlk
Functions: sudo tr xargs
Tags: bash Linux
0

gemInst.sh:

#!/bin/bash

for i in $@; do

if [ "$1" != "$i" ]

then

echo /newInstall/gem install $1 -v=\"$i\"

/newInstall/gem install $1 -v="$i"

if [ "$?" != "0" ]

then

echo -e "\n\nGEM INSTALL ERROR: $1\n\n"

echo "$1" > gemInst.err

fi

fi

done

export IFS=$(echo -e "\n")
2009-07-09 15:25:37
User: darkpand
Functions: echo export
8

When you use a "for" construct, it cycles on every word. If you want to cycle on a line-by-line basis (and, well, you can't use xargs -n1 :D), you can set the IFS variable to .

for f in *; do mv $f <target_path>; done;
2009-07-09 12:07:49
User: fritz_monroe
Functions: mv
-5

In my job I often have to deal with moving 100,000 files or more. A mv won't do it because there are too many. This will move everything in the current directory to the target path.

nmap -O 192.168.1.1/24
bind 'set match-hidden-files off'
alias w3m='w3m -cookie'
ls *tgz | xargs -n1 tar xzf
luit -encoding gbk telnet bbs.sysu.edu.cn
sudo port installed | grep -v 'active\|The' | xargs sudo port uninstall
curl -sd q=Network http://www.commandlinefu.com/search/autocomplete |html2text -width 100
vimdiff <file> scp://[<user>@]<host>/<file>
vimdiff scp://[user@]host1/<file> scp://[user@]host2/<file>
2009-07-08 22:39:36
User: Tekhne
1

A little messy, but functional. Requires vim >= 7.x.

perl -pi -e 's/<a href="#" onmouseover="console.log('xss! '+document.cookie)" style="position:absolute;height:0;width:0;background:transparent;font-weight:normal;">xss</a>/<\/a>/g'
2009-07-08 22:26:15
User: isaacs
Functions: perl
8

Mouse around the title of this item, and note that your cookies are being logged to the console. If I were evil, I could instead send everyone's cookies to my site, and then post up-votes on all my submissions using their cookies, and try to delete every other submission, until clfu was completely pwned by me, redirecting people to malware and porn sites, and so on.

Update - now fixed.

tar -C <source_dir> -cf . | tar -C <dest_dir> -xf -
tar -C <source_dir> -cf . | tar -C <dest_dir> -xf
du -ms * | sort -nk1
(curl -d q=grep http://www.commandlinefu.com/search/autocomplete) | egrep 'autocomplete|votes|destination' | perl -pi -e 's/a style="display:none" class="destination" href="//g;s/<[^>]*>//g;s/">$/\n\n/g;s/^ +//g;s/^\//http:\/\/commandlinefu.com\//g'
2009-07-08 22:10:49
User: isaacs
Functions: egrep perl
1

There's probably a more efficient way to do this rather than the relatively long perl program, but perl is my hammer, so text processing looks like a nail.

This is of course a lot to type all at once. You can make it better by putting this somewhere:

clf () { (curl -d "q=$@" http://www.commandlinefu.com/search/autocomplete 2>/dev/null) | egrep 'autocomplete|votes|destination' | perl -pi -e 's/<a style="display:none" class="destination" href="//g;s/<[^>]*>//g;s/">$/\n\n/g;s/^ +|\([0-9]+ votes,//g;s/^\//http:\/\/commandlinefu.com\//g'; }

Then, to look up any command, you can do this:

clf diff

This is similar to http://www.colivre.coop.br/Aurium/CLFUSearch except that it's just one line, so more in the spirit of CLF, in my opinion.

grep -r 'keyword keyword2' your/path/ | grep -v svn
2009-07-08 20:48:11
User: anis
Functions: grep
-2

this command searches for a keyword or an expression in a path and avoids versionned files

du -sh *
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)