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 charac-
ter 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 char-
acter (_).
-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 exe-
cuted 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 execu-
tion of this command instance is skipped.
-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, com-
mand 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.
Heirloom Toolchest 8/14/05 XARGS(1)
Man(1) output converted with
man2html