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.

Universal configuration monitoring and system of record for IT.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Commands using xargs from sorted by
Terminal - Commands using xargs - 632 results
find . -name "*noticia*" -name "*jhtm*" -name "*.tpl" -exec grep -li "id=\"col-direita\"" '{}' \; | xargs -n1 mate
ls *.JPG | cut -d . -f 1 | xargs -L1 -i convert -resize 684 {}.JPG {}.jpg
grep -ZlRr -e BAD_SCRIPT_LINE * |xargs -0 sed -i 's/BAD_SCRIPT_LINE//g'
2010-08-30 22:12:57
User: homoludens
Functions: grep sed xargs

recursive find and replace. important stuff are grep -Z and zargs -0 which add zero byte after file name so sed can work even with file names with spaces.

find . -type f -print0 | xargs -0 md5sum
find /path/to/archive/?/??/??? -mtime -7 -name "*.pdf" | xargs stat -c "%s"| awk '{sum +=$1}END{printf("%0.0f\n",sum)}'|sed -r ':Label;s=\b([0-9]+)([0-9]{3})\b=\1,\2=g;t Label'
2010-08-23 15:55:30
Functions: awk find sed stat xargs

The find command isn't the important bit, here: it's just what feeds the rest of the pipe (this one looks for all PDFs less than 7 days old, in an archive directory, whose structure is defined by a wildcard pattern: modify this find, to suit your real needs).

I consider the next bit the useful part. xargs stats out the byte-size of each file, and this is passed to awk, which adds them all together, and prints the grand total. I use printf, in order to override awk's tendency to swtich to exponential output above a certain threshold, and, specifically "%0.0f\n", because it was all I can find to force things back to digital on Redhat systems.

This is then passed to an optional sed, which formats them in a US/UK number format, to make large numbers easier to read. Change the comma in the sed, for your preferred separator character (e.g. sed -r ':L;s=\b([0-9]+)([0-9]{3})\b=\1 \2=g;t L' for most European countries).

(This sed is credited to user name 'archtoad6', on the Linuxquestions forum.)

This is useful for monitoring changes in the storage use within large and growing archives of files, and appears to execute much more quickly than some options I have seen (use of a 'for SIZE in find-command -exec du' style approach, instead, for instance). I just ran it on a not particularly spectacular server, where a directory tree with over three thousand subdirectories, containing around 4000 files, of about 4 Gigs, total, responded in under a second.

find /tank -iname thumbs.db -print0 | xargs -0 rm
xargs -n1 -P100 -I{} sh -c 'ssh {} uptime >output/{} 2>error/{}' <hostlist
2010-08-20 11:03:11
User: dooblem
Functions: sh uptime xargs

Do the same as pssh, just in shell syntax.

Put your hosts in hostlist, one per line.

Command outputs are gathered in output and error directories.

svn status | grep "^\?" | awk '{print $2}' | xargs svn add
2010-08-14 18:56:15
User: kureikain
Functions: awk grep xargs
Tags: svn awk grep

When working on a big proeject with SVN, you create quite much files, for now! Can just sit here and type svn add for all of them!

svn status will return a list of all of file which get ?(not add), "M"(Modified), "D"(Deleted)! This code just grep "?" flag, then add it into SVN again!

svn st | grep -e '^M' | awk '{print $2}' | xargs svn revert
svn status | awk '{print $2}' | xargs du | sort -n | tail
find . -type f -iname '*.mp3' -print0 | xargs -0 mp3gain -r -k
2010-08-04 16:29:13
User: mtron
Functions: find xargs
Tags: mp3gain

This will search all subfolders for mp3's and gain them to more or less sane defaults (without reencoding).

http://mp3gain.sourceforge.net/ required!

tar tfz filename.tgz |xargs rm -Rf
find -type f -size +0 -mtime +1 -print0|xargs -0r rm -f
sudo ls -l $(eval echo "/proc/{$(echo $(pgrep java)|sed 's/ /,/')}/fd/")|grep log|sed 's/[^/]* //g'|xargs -r tail -f
2010-07-30 18:20:00
User: vutcovici
Functions: echo eval grep ls sed sudo tail xargs

Tail all logs that are opened by all java processes. This is helpful when you are on a new environment and you do not know where the logs are located. Instead of java you can put any process name. This command does work only for Linux.

The list of all log files opened by java process:

sudo ls -l $(eval echo "/proc/{$(echo $(pgrep java)|sed 's/ /,/')}/fd/")|grep log|sed 's/[^/]* //g'
find . -name "*.php" -print0 | xargs -0 grep -i "search phrase"
2010-07-27 20:52:37
User: randy909
Functions: find grep xargs

xargs avoids having to remember the "{} \;" (although definitely a useful thing to know. Unfortunately I always forget it). xargs version runs 2x faster on my test fwiw.

edit: fixed to handle spaces in filenames correctly.

lsof /dev/snd/pcm*p /dev/dsp | awk ' { print $2 }' | xargs kill
2010-07-23 20:24:16
User: alustenberg
Functions: awk xargs

for when a program is hogging the sound output. finds, and kills. add -9 to the end for wedged processes. add in 'grep ^program' after lsof to filter.

find . -name '*.txt' | grep -v '\.lzma$' | xargs -n 1 lzma -f -v -3
find * ! -name abc | xargs rm
find . -name '*.?pp' | xargs grep -H "string"
2010-07-14 14:41:07
User: cout
Functions: find grep xargs
Tags: find xargs grep

I like this better than some of the alternatives using -exec, because if I want to change the string, it's right there at the end of the command line. That means less editing effort and more time to drink coffee.

find /usr/share/figlet -name *.?lf -exec basename {} \; | sed -e "s/\..lf$//" | xargs -I{} toilet -f {} {}
2010-07-13 20:12:54
Functions: basename find sed xargs
Tags: find

Lists a sample of all installed toilet fonts

ps auxwww | grep outofcontrolprocess | awk '{print $2}' | xargs kill -9
find /protocollo/paflow -type f -mtime +5 | xargs tar -cvf /var/dump-protocollo/`date '+%d%m%Y'_archive.tar`
2010-06-29 12:43:30
User: 0disse0
Functions: find tar xargs
Tags: find tar dump

The following command finds all the files not modified in the last 5 days under /protocollo/paflow directory and creates an archive files under /var/dump-protocollo in the format of ddmmyyyy_archive.tar

svn st | awk '{if ($1 ~ "?") print $2}' | xargs svn add
2010-06-19 03:07:26
User: sciurus
Functions: awk xargs
Tags: svn awk

No need for grep, let awk do the match. This will not behave properly if the filenames contains whitespace, which is awk's default field separator.

ps ux|grep <process name>|awk '{print $2}'|xargs -n 1 kill
ps h -o pid,command | grep 'TEXT' | sed 's/^ \+//' | cut -d ' ' -f 1 | xargs -n 1 kill