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.
-
-nargs Allow no more than
argsarguments on the command line. May be overridden by-s.-
-smax Allow no more than
maxcharacters 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 diffThe 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 -n1Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access