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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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 tagged xargs from sorted by
Terminal - Commands tagged xargs - 125 results
svn revert .
cat item_list | xargs -n1 -P<n> process_item
for file in *; do convert $file -resize 800x600 resized-$file; done
2013-02-17 21:37:14
User: sonic
Functions: file
Tags: xargs convert

To ignore aspect ratio, run:

for file in *; do convert $file -resize 800x600! resized-$file; done

and all images will be exactly 800x600.

Use your shell of choice.. This was done in BASH.

for file in `svn st | awk '{print $2}'`; do svn revert $file; done
lsmod | tail -n +2 | cut -d' ' -f1 | xargs modinfo | egrep '^file|^desc|^dep' | sed -e'/^dep/s/$/\n/g'
find . -type f -exec stat -f '%m %N' {} \; | sort -n
find /path/to/dir -type f -print0 | xargs -0 grep -l "foo"
find . -type f -exec chmod a-x {} +
2012-06-11 12:50:56
User: sanmiguel
Functions: chmod find
Tags: find xargs chmod

Using `-exec cmd {} +` causes find to build the command using all matching filenames before execution, rather than once per file.

git remote -v | grep fetch | sed 's/\(.*github.com\)[:|/]\(.*\).git (fetch)/\2/' | awk {'print "https://github.com/" $1'} | xargs open
2012-04-15 20:48:46
User: brockangelo
Functions: awk grep sed xargs

Written for Mac OSX. When you are working in a project and want to open it on Github.com, just type "gh" and your default browser will open with the repo you are in. Works for submodules, and repo's that you don't own.

You'll need to copy / paste this command into a gh.sh file, then create an alias in your bash or zsh profile to the gh.sh script. Detailed instructions here if you still need help:


find . -type f -print0 | xargs -0 du -h | sort -hr | head -20
2012-03-30 10:21:12
User: flatcap
Functions: du find head sort xargs

Search for files and list the 20 largest.

find . -type f

gives us a list of file, recursively, starting from here (.)

-print0 | xargs -0 du -h

separate the names of files with NULL characters, so we're not confused by spaces

then xargs run the du command to find their size (in human-readable form -- 64M not 64123456)

| sort -hr

use sort to arrange the list in size order. sort -h knows that 1M is bigger than 9K

| head -20

finally only select the top twenty out of the list

cat z.log | cut -d ':' -f1 | sort | uniq | xargs -l1 -iFF echo 'echo FF $(cat z.log | grep -e "^FF" | grep -e Timeout | wc -l )' | bash
print "$(lsvg -Lo |xargs lsvg -L|grep "TOTAL PPs"|awk -F"(" '{print$2}'|sed -e "s/)//g" -e "s/megabytes/+/g"|xargs|sed -e "s/^/(/g" -e "s/+$/)\/1000/g"|bc ) GB"
2012-02-03 13:58:41

Not figured by me, but a colleague of mine.

See the total amount of data on an AIX machine.

ps -fea | grep PATTERN | awk {'print $2'} | xargs kill -9
find /usr/include/ -name '*.[c|h]pp' -o -name '*.[ch]' -print0 | xargs -0 wc -l | tail -1
function whichpkg() { readlink -f "$(which $1)" | xargs --no-run-if-empty dpkg -S; }
2011-10-28 02:53:19
User: b_t
Functions: readlink xargs

This revision to my command (command #8851) was called for when it failed to find the parent

package of 'rlogin', which is really a deep symbolic link to /usr/bin/ssh.

This revision fixes this newfound issue, while ensuring fixes of other older issues work too.

unzip -l filename.zip |awk '{ if($4 != "Name" && $4 != "----") print $4}'|xargs -t rm -rf {}
2011-10-20 18:54:15
User: hk0i
Functions: awk rm xargs
Tags: awk xargs unzip rm

Sometimes you unzip a file that has no root folder and it spews files all over the place. This will clean up all of those files by deleting them.

for i in /usr/bin/* ;do touch ${i##*/}; done
2011-10-20 12:38:45
User: _john
Functions: touch
Tags: bash find xargs zsh

You could avoid xargs and sed in this case (shorter command and less forking): At least bash and zsh have some mighty string modifiers.

I would also suggest using find with exec option to get more flexibility. You may leave out or include "special" file for example.

svn status|grep -iR '^!'|sed 's/!/ /g'|xargs -i svn rm '{}'
2011-10-06 08:11:25
User: erdeszt
Functions: grep rm sed xargs
Tags: svn sed xargs grep

Helps if you accidentally deleted files from an svn repo with plain rm and you would like to mark them for svn to delete too.

lsr() { find "${@:-.}" -print0 |sort -z |xargs -0 ls $LS_OPTIONS -dla; }
2011-08-15 03:10:58
User: h3xx
Functions: find ls sort xargs

Tells you everything you could ever want to know about all files and subdirectories. Great for package creators. Totally secure too.

On my Slackware box, this gets set upon login:

LS_OPTIONS='-F -b -T 0 --color=auto'


alias ls='/bin/ls $LS_OPTIONS'

which works great.

httpd -V | grep -i SERVER_CONFIG_FILE | cut -f2 -d'"' | xargs grep -i '^DocumentRoot' | cut -f2 -d'"'
2011-08-13 20:45:05
User: dcpesses
Functions: cut grep

Grabs the Apache config file (yielded from httpd) and returns the path specified as DocumentRoot.

xargs -P 3 -n 1 <COMMAND> < <FILE_LIST>
2011-07-25 22:53:32
User: h3xx
Functions: xargs

For instance:

find . -type f -name '*.wav' -print0 |xargs -0 -P 3 -n 1 flac -V8

will encode all .wav files into FLAC in parallel.

Explanation of xargs flags:

-P [max-procs]: Max number of invocations to run at once. Set to 0 to run all at once [potentially dangerous re: excessive RAM usage].

-n [max-args]: Max number of arguments from the list to send to each invocation.

-0: Stdin is a null-terminated list.

I use xargs to build parallel-processing frameworks into my scripts like the one here: http://pastebin.com/1GvcifYa

curl -s --compressed http://funnyjunk.com | awk -F'"' '/ '"'"'mainpagetop24h'"'"'/ { print "http://funnyjunk.com"$4 }' | xargs curl -s | grep -o 'ht.*m/pictures/.*\.jpg\|ht.*m/gifs/.*\.gif' | grep "_......_" | uniq | xargs wget
2011-07-21 15:57:21
User: laniner
Functions: awk uniq xargs

If your version of curl does not support the --compressed option, use

curl -s http://funnyjunk.com | gunzip

instead of

curl -s --compressed http://funnyjunk.com
mogrify -modulate 100,100,70 ../../icons/32x32/*.png
/bin/ls *.png | xargs -l1 -I {} convert {} -modulate 100,100,70 ../../icons/32x32/{}
curl -s http://example.com | grep -o -P "<a.*href.*>" | grep -o "http.*.pdf" | xargs -d"\n" -n1 wget -c
2011-06-09 14:42:46
User: b_t
Functions: grep wget xargs

This example command fetches 'example.com' webpage and then fetches+saves all PDF files listed (linked to) on that webpage.

[*Note: of course there are no PDFs on example.com. This is just an example]