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.
-
-n
args
Allow no more than
args
-s
.-
-s
max
Allow no more than
max
-
-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 as arguments. Display file
, one
word per line (same as deroff
-w
):
$ cat file | xargs -n1
Get Mac OS X Panther in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.