Arguments in the standard input must be separated by unquoted blank characters, or unescaped blank characters or newline characters. A string of zero or more non-double-quote (") and non-newline characters can be quoted by enclosing them in double-quotes. A string of zero or more non-apostrophe (’) and non-newline characters can be quoted by enclosing them in apostrophes. Any unquoted character can be escaped by preceding it with a backslash (\). The utility will be executed one or more times until the end-of-file is reached. The results are unspecified if the utility named by utility attempts to read from its standard input.
The generated command line length will be the sum of the size in bytes of the utility name and each argument treated as strings, including a null byte terminator for each of these strings. The xargs utility will limit the command line length such that when the command line is invoked, the combined argument and environment lists will not exceed {ARG_MAX }-2048 bytes. Within this constraint, if neither the -n nor the -s option is specified, the default command line length will be at least {LINE_MAX }.
- The command line length accumulated exceeds the size specified by the -s option (or {LINE_MAX } if there is no -s option), or
- The last iteration has fewer than number, but not zero, operands remaining.
- The total number of arguments exceeds that specified by the -n option, or
- The total number of lines exceeds that specified by the -L option, or
- End of file is encountered on standard input before size bytes are accumulated.
Note that input is parsed as lines; blank characters separate arguments. If xargs is used to bundle output of commands like find dir -print or ls into commands to be executed, unexpected results are likely if any filenames contain any blank characters or newline characters. This can be fixed by using find to call a script that converts each file found into a quoted string that is then piped to xargs. Note that the quoting rules used by xargs are not the same as in the shell. They were not made consistent here because existing applications depend on the current rules and the shell syntax is not fully compatible with it. An easy rule that can be used to transform any string into a quoted form that xargs will interpret correctly is to precede each character in the string with a backslash (\).
On implementations with a large value for {ARG_MAX }, xargs may produce command lines longer than {LINE_MAX }. For invocation of utilities, this is not a problem. If xargs is being used to create a text file, users should explicitly set the maximum command line length with the -s option.
The xargs utility returns exit status 127 if an error occurs so that applications can distinguish ‘failure to find a utility’ from ‘invoked utility exited with an error indication.’ The value 127 was chosen because it is not commonly used for other meanings; most utilities use small values for ‘normal error conditions’ and the values above 128 can be confused with termination due to receipt of a signal. The value 126 was chosen in a similar manner to indicate that the utility could be found, but not invoked.
ls $1 | xargs -I {} -t mv $1/{} $2/{}
(logname; date; printf "%s\n" "$0 $*") |
printf "%s\n" "$*" |
a. ls | xargs -p -L 1 ar -r archb. ls | xargs -p -L 1 |
echo $* |
If a command line meeting the specified requirements cannot be assembled, the utility cannot be invoked, an invocation of the utility is terminated by a signal, or an invocation of the utility exits with exit status 255, the xargs utility will write a diagnostic message and exit without processing any remaining input.