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.



Expect filenames to be terminated by NULL instead of whitespace. Do not treat quotes or backslashes specially.

-n args

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

-s max

Allow no more than max characters per command line.


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


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


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

                     find / -print0 | xargs -0 grep 
                      > 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 as arguments. Display file, one word per line (same as deroff -w):

                      | xargs -n1

Get Mac OS X in a Nutshell now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.