Xargs on OSX: illegal option —

osxxargs

I'm on OSX. I want to run a python script against all pngs in a particular directory. This is what I've tried:

find docs/ -name "*png" | xargs --replace=F python myscript.py "F"

But I see this:

xargs: illegal option -- -
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
             [-L number] [-n number [-x]] [-P maxprocs] [-s size]
             [utility [argument ...]]

What am I doing wrong?

Best Answer

xargs on Mac OS X doesn't support the --replace option; you can use -I instead:

find docs/ -name "*png" | xargs -I F python myscript.py "F"

The strange error message is produced because this version of xargs interprets characters after a single - as options, so with --replace it's looking for an option named -, which doesn't exist.

Related Question