Twitter Updates

Tuesday, 10 February 2009

Using Xargs on Mac Terminal

Xargs is used to run commands on the output from other command line programs.
The OS X version is missing the default -I {} that other *nix sytems seem to have.
The following command will search for and print files matching *something*. The xargs is redundant here but gives a good frame work.

$ find . -iname *something* | xargs -I {} echo {}

Or move matching files to another location.
$ find . -iname *something* | xargs -I {} mv {} ../Other/Location


Anonymous said...

Thank you, good Lord, Thank You.

Days of searching produced constant frustration with
find . | xargs cp (or mv) {}
and a nearly infinite permutation of same.

Doesn't Bleedin' Work On The Stupid Mac.

Your site is the Only Place I found the key.

Which Works. Caloo, Callay . . .

Stupid Mac.

And yes, I own a few Macs.
And some WinTels, which sit ignored in their little cases.
Poor little WinTels.

Stupid Macs.

Thank you.
Yes, again.

Morgy said...

Thank you, am glad I could help.
I like macs but they do have some stupid parts, like non gnu defaults.

Poor WinTels.

wdef said...

Excellent tip, thanks. This provides undoubtedly the easiest way to batch rename files whose filenames contain spaces:

Eg The following will change the extension of files in the current directory from .fla to .flac

$ ls *fla | xargs -I {} mv {} {}"c"


wdef said...


$ ls *fla | xargs -I {} mv {} {}"c"

xargs has a problem here with filenames beginning with a space or containing an apostrophe - watch out for French filenames containing things like "qu'a".

Anonymous said...

If you are using MacPorts, just use gxargs.

Ali Ayoub said...


Anonymous said...

Yep, your post did it for me too. I references it on stack overflow

My Brushes said...

Really great news!!! this information is well worth looking everyone. Good tips. I will be sharing this with all of my friends! Thank you for sharing valuable information.
Graphic Design Software for Mac

John said...

Fantastic. Exactly what I needed to copy just the PDF files from a whole slew of subdirectories into another one on my Mac. Thanks much.