XARGS(1)

NAME
xargs - construct argument list(s) and execute command

SYNOPSIS
xargs [flags] [command [initial-arguments]]

DESCRIPTION
Xargs executes command using the given initial arguments followed by arguments read from standard input. By default, command is invoked as many times as necessary using the maximum number of arguments possible for each invocation. If no command is given, echo is used.

Data read from standard input is split into a list of arguments, using blanks and newline characters as delimiters. Special characters are: backslash (\), which causes any following character to be interpreted literally, and single (') and double (") quotes, which cause following characters except newline to be taken literally until the quote character appears again.

The following option flags are accepted:

-e[eofstr]
    Sets the logical end-of-file delimiter to eofstr; data is read from standard input until an argument equal to eofstr is encountered. If eofstr is omitted, no logical end-of-file delimiter is used and data is read from standard input until the physical end-of-file is reached. The default logical end-of-file delimiter is a single underscore character (_).

-i[replstr]
    Changes the operation of xargs such that each line read from standard input replaces occurrences of replstr within the initial-arguments. If replstr is omitted, {} is default. Any member of initial-arguments can each contain any number of occurrences of replstr. The command is executed once for each line until physical end-of-file is reached or a line consisting exactly of the logical end-of-file delimiter is read. Empty lines and leading blank characters are ignored, other blank characters are kept regardless of quotes.

-l[number]
    Invokes command for each number of lines; 1 is default if no number is specified. Empty lines are ignored; if a line ends with an unquoted blank character, it is not counted.

-n number
    Executes command for each number of arguments read from standard input, or with fewer arguments if the maximum argument length is exceeded or fewer than number arguments remain.

-p  Each resulting command is written to standard error along with its arguments before it is executed and the user is asked whether it should be executed. If the response is affirmative, the command is executed; otherwise, the execution of this command instance is skipped.

-s size
    Sets the maximum length of generated command lines to size.

-t  Trace mode; each resulting command is written to standard error along with its arguments before it is executed.

-x  If execution cannot be done within the limits specified by the -n, -L, or -s flags, xargs will terminate.

The following options have been introduced by X/Open:

-E eofstr
    Same as -eeofstr.

-L number
    Same as -lnumber.

-I replstr
    Same as -ireplstr.

When any instance of command exits with a status of -1 or is terminated by a signal, xargs terminates.

ENVIRONMENT VARIABLES

LANG, LC_ALL
    See locale(7).

LC_CTYPE
    Determines the mapping of bytes to characters and the set of blank characters.

PATH
    Used to locate command.

FILES
/dev/tty Used with the -p option.

SEE ALSO
find(1), sh(1), locale(7)

NOTES
When xargs is used to read data generated by the find or ls commands and any of the characters special to xargs appear in file names, command will be invoked with a wrong set of file names. To avert this, find is given a special pathname consisting of two slashes that marks the beginning of a file name, and each character is preceded with a backslash:

    find .//. -print | sed 's/./\\&/g' | awk '{
            if (NR > 1) {
                    printf("%s", line)
                    if ($0 !~ /\\\/\\\//)
                            printf("\\")
                    printf("\n")
            }
            line = $0
    }
    END {
            print(line)
    }' | xargs command

Note that the `-exec command {} +' operand of find provides a method to achieve similar results as with xargs for simple cases.