maux
Star on GitHub Buy me a coffee

Manual / xargs

xargs(1)

XARGS(1) General Commands Manual XARGS(1)

xargs - construct argument lists and run a utility with them

xargs [ -0pt ] [ -n number ] [ -s size ] [ -t ] [ -I replstr ] [ utility [ argument ] ... ]

Xargs reads whitespace- and newline-delimited arguments from the standard input, appends as many of them as will fit to the given argument list, and runs utility with the result. This is repeated until standard input is exhausted. Utility defaults to echo. If standard input carries no arguments at all, utility is not run and the exit status is 0.

Arguments are delimited by unquoted blanks (space or tab) or newlines; adjacent delimiters collapse to one. '...' and "..." each protect everything but their own matching quote (not a bare newline, and not the shell's own escaping -- backslash is literal inside either kind of quote). An unquoted backslash escapes the very next byte, newline included. A quote left open at end of input is an error.

Use at most number standard-input-derived arguments per invocation of utility, in addition to any argument words given on the command line.
Bound the standard-input-derived arguments' packed byte total per invocation to size bytes. Both -n and -s are additionally bounded by this machine's own spawn() ceiling (the packed argument list, and the pointer array indexing it, are both fixed-size); a value asking for more than the ceiling allows is silently lowered to it. If a single standard-input argument alone exceeds the size in effect, it still runs by itself rather than being dropped.
Write each constructed command line to standard error, terminated with a newline, just before running it.
-0
Items end at a NUL byte and at nothing else: blanks, newlines, quotes and backslashes are ordinary bytes. An empty item is dropped. With -I a NUL ends a line and nothing is stripped from it.
Before each invocation write the command line to standard error, then ?... and read one reply line from the terminal (the standard error, which stays the console when the standard input is a file or a pipe). The utility runs only if the reply begins with y or Y; anything else, including an empty line, skips that invocation without an error. Where standard error is not a terminal nobody can be asked and every invocation is skipped. Replaces -t.
Read one whole input line per invocation (leading blanks stripped, blank lines skipped) and substitute every occurrence of replstr in utility and its argument words with that line's text. Disables -n.

/usr/man/XARGS this page

find(1), sh(1)

Exit status is 0 if every invocation of utility exited 0, or if none ran; 123 if some invocation exited between 1 and 125 (noted, but xargs keeps going); 124 if some invocation exited abnormally (this machine's wait status cannot always distinguish an exit(255) from a kill by signal, so both fold into this one code, and xargs stops); 126 if utility was found but could not be invoked; 127 if utility could not be found on PATH; 1 for a usage error, an unmatched quote, or an argument list too long to leave any room for standard input's own arguments.

-0 (NUL-delimited input), -E, -L, -p, -r, -x and -P are not implemented. The child's standard input is closed (not connected to a terminal, and not xargs's own standard input, which POSIX leaves unspecified for this reason: xargs's own input is very often the read end of a pipe xargs itself is still draining). xargs's own environment is not passed to utility, unlike a real execvp -- a deliberate simplification that keeps the whole packed-argument budget available to argument text. Each argument's own text is truncated at 255 bytes.

October 8, 2026 maux