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

Commands using xargs from sorted by
Terminal - Commands using xargs - 598 results
find -type d -name ".svn" -print0 | xargs -0 rm -rf
2010-02-25 10:16:18
User: tuxilicious
Functions: find rm xargs
-1

man find: If no paths are given, the current directory is used. - Can anybody tell me why so many people are typing the dot?

function skreemplay() { lynx -dump "http://skreemr.com/results.jsp?q=$*" | grep mp3$ | sed 's/^.* //' | xargs mplayer }
2010-02-24 08:44:01
User: thelan
Functions: grep sed xargs
1

This use the Screemr search engine to play mp3 songs

ls -RAx | grep "svn:$" | sed -e "s/svn:/svn/" | xargs rm -fr
du -x --max-depth=1 | sort -n | awk '{ print $2 }' | xargs du -hx --max-depth=0
2010-02-18 19:46:47
User: d34dh0r53
Functions: awk du sort xargs
4

Provides numerically sorted human readable du output. I so wish there was just a du flag for this.

ls . | xargs file | grep text | sed "s/\(.*\):.*/\1/" | xargs gedit
newest () { find ${1:-\.} -type f |xargs ls -lrt ; }
find . -type f |xargs -I% sed -i '/group name/s/>/ deleteMissing="true">/' %
2010-02-01 21:09:57
User: 4fthawaiian
Functions: find sed xargs
1

Changed out the for loop for an xargs. It's a tad shorter, and a tad cleaner.

find . -type f -size +1100000k |xargs -I% du -sh %
2010-01-31 22:04:07
User: 4fthawaiian
Functions: du find xargs
1

simple find -> xargs sort of thing that I get a lot of use out of. Helps find huge files and gives an example of how to use xargs to deal with them. Tested on OSX snow leopard (10.6). Enjoy.

ipcs -a | grep 0x | awk '{printf( "-Q %s ", $1 )}' | xargs ipcrm
find -type d -name ".svn" -prune -o -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type d -name ".svn" -prune -o -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
2010-01-28 09:45:29
User: 2chg
Functions: find md5sum sort uniq xargs
2

Improvement of the command "Find Duplicate Files (based on size first, then MD5 hash)" when searching for duplicate files in a directory containing a subversion working copy. This way the (multiple dupicates) in the meta-information directories are ignored.

Can easily be adopted for other VCS as well. For CVS i.e. change ".svn" into ".csv":

find -type d -name ".csv" -prune -o -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type d -name ".csv" -prune -o -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
echo $(( $( cat count.txt | tr "\n" "+" | xargs -I{} echo {} 0 ) ))
2010-01-27 10:02:30
User: glaudiston
Functions: cat echo tr xargs
0

if you, like me, do not have the numsum, this way can do the same.

find filepath -type f -iname "*.html" -o -iname "*.htm" -o -iname "*.php" | xargs grep "Exception\|LGPL\|CODE1"
ls -Q * | xargs -p rm
2010-01-27 02:46:49
User: temp_reg
Functions: ls xargs
1

ls -Q will show the filenames in quotes. xargs -p rm will print all the filenames piped from ls -Q and ask for confirmation before deleting the files.

without the -Q switch, if we have spaces in names, then the files won't be deleted.

find directory/ |xargs grep -i "phrase"
ls /usr/bin | xargs whatis | grep -v nothing | less
2010-01-26 12:59:47
User: michelsberg
Functions: grep ls whatis xargs
12

no loop, only one call of grep, scrollable ("less is more", more or less...)

find . -maxdepth 1 -type f| xargs sha1sum | sed 's/^\(\w*\)\s*\(.*\)/\2 \1/' | while read LINE; do mv $LINE; done
dpkg -l | grep ^rc | awk '{print $2}' | sudo xargs dpkg -P
echo $VARIABLE | xargs -d'\40' -n 6 echo
2010-01-20 15:12:53
User: SuperFly
Functions: echo xargs
1

Print out the contents of $VARIABLE, six words per line, ignoring any single or double quotes in the text. Useful when $VARIABLE contains a sentence that changes periodically, and may or may not contain quoted text.

find . -name "*.php" | xargs grep -il searchphrase
2010-01-14 22:42:36
User: refrax
Functions: find grep xargs
2

This command will find all files recursively containing the phrase entered, represented here by "searchphrase". This particular command searches in all php files, but you could change that to just be html files or just log files etc.

exipick -zi | xargs exim -Mrm
find /lib/modules/`uname -r`/ -type f -iname '*.o' -or -iname '*.ko' |grep -i -o '[a-z0-9]*[-|_]*[0-9a-z]*\.ko$' |xargs -I {} echo '# {}' >>/etc/modules.autoload.d/kernel-2.6
2010-01-13 02:12:08
User: paragao
Functions: echo find grep xargs
-1

Whenever you compile a new kernel, there are always new modules. The best way to make sure you have the correct modules loaded when you boot is to add all your modules in the modules.autoload file (they will be commented) and uncomment all those modules you need.

Also a good way to keep track of the available modules in your system.

For other distros you may have to change the name of the file to /etc/modprobe.conf

grep -e `date +%Y-%m-%d` /var/log/dpkg.log | awk '/install / {print $4}' | uniq | xargs apt-get -y remove
ifconfig -l | xargs -n1 ipconfig getifaddr 2> /dev/null
find dir -size -1024k -type f | xargs -d $'\n' -n1 ls -l | cut -d ' ' -f 5 | sed -e '2,$s/$/+/' -e '$ap' | dc
2009-12-28 04:23:01
User: zhangweiwu
Functions: cut dir find ls sed xargs
Tags: size sum
1

The command gives size of all files smaller than 1024k, this information, together with disk usage, can help determin file system parameter (e.g. block size) or storage device (e.g. SSD v.s. HDD).

Note if you use awk instead of "cut| dc", you easily breach maximum allowed number of records in awk.

find . -name '*png' -printf '%h\0' | xargs -0 ls -l --hide=*.png | grep -ZB1 ' 0$'