O'Reilly logo

Mac OS X Tiger in a Nutshell by Jason McIntosh, Chuck Toporek, Chris Stone, Andy Lester

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

xargs

Synopsis

xargs [options] command

Executes command (with any initial arguments) but reads remaining arguments from standard input instead of specifying them directly. xargs passes these arguments in several bundles to command, allowing command to process more arguments than it could normally handle at once. The arguments are typically a long list of filenames (generated by ls or find, for example) that get passed to xargs via a pipe.

Options

-0

Expect filenames to be terminated by NULL instead of whitespace. Don't treat quotes or backslashes specially.

-E str

Use str as EOF.

-I replstr

Specifies replstr as the string to be replaced in command with each input line.

-J replstr

Like -I, but input lines are joined together, separated by spaces, to replace replstr.

-L lines

Call command once for each lines lines.

-n args

Allow no more than args arguments on the command line. May be overridden by -s.

-R replacements

Specify the maximum number of arguments that will be replaced by -I.

-s max

Allow no more than max characters per command line.

-t

Verbose mode. Print command line on standard error before executing.

-x

If the maximum size (as specified by -s) is exceeded, exit.

Examples

Search for pattern in all files on the system, including those with spaces in their names:

$ find / -print0 | xargs -0 grep pattern > out &

Run diff on file pairs (e.g., f1.a and f1.b, f2.a and f2.b...):

$ echo $* | xargs -n2 diff

The previous line would be invoked as a shell script, specifying filenames ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required