XARGS(1) DOMAIN/IX Reference Manual (SYS5) XARGS(1)
NAME
xargs - construct argument list(s) and execute a command
USAGE
xargs [ options ] [ command [ initial arguments ] ]
DESCRIPTION
Xargs combines the fixed initial arguments with arguments
read from standard input to execute the specified command
one or more times. The options that you specify determine
the number of arguments read for each command invocation and
the manner in which they are combined.
Xargs uses your $PATH to search for command, which may be a
Shell file. If you omit command, it uses the /bin/echo
file.
Arguments read in from standard input are defined to be con-
tiguous strings of characters delimited by one or more
blanks, tabs, or newlines; empty lines are always discarded.
Blanks and tabs may be embedded as part of an argument if
escaped or quoted. Characters enclosed in quotes (single or
double) are taken literally, and the delimiting quotes are
removed. Outside quoted strings, a backslash (\) escapes
the next character.
Each argument list begins with the initial arguments, fol-
lowed by some number of arguments read from standard input
(with the exception of those using the -i option). The -i,
-l, and -n options determine how arguments are selected for
each command invocation. When none of these options are
coded, the initial arguments are followed by arguments read
continuously from standard input until an internal buffer is
full. Then, command is executed with the accumulated argu-
ments. Xargs repeats this process until there are no more
arguments. When options conflict (e.g., -l vs. -n), the
last option has precedence.
OPTIONS
-lnumber Execute the command for each non-empty
number lines of arguments from standard
input. The last invocation of command
will be with fewer lines of arguments if
fewer than number remain. A line is
considered to end with the first newline
unless the last character of the line is
a blank or a tab. A trailing blank/tab
signals continuation through the next
non-empty line. If number is omitted,
one is assumed. The -x option is
forced.
Printed 6/10/85 XARGS-1
XARGS(1) DOMAIN/IX Reference Manual (SYS5) XARGS(1)
-ireplstr Insert mode: execute command for each
line from standard input, taking the
entire line as a single argument,
inserting it in initial arguments for
each occurrence of replstr. A maximum
of five arguments in initial arguments
may each contain one or more instances
of replstr. Discard blanks and tabs at
the beginning of each line. Constructed
arguments may not grow larger than 255
characters, and option -x is also
forced. Braces ({}) are assumed for
replstr if not specified.
-nnumber Execute command using as many standard
input arguments as possible, up to
number arguments maximum. Fewer argu-
ments will be used if their total size
is greater than size characters, and for
the last invocation if there are fewer
than number arguments remaining. If
option -x is also coded, each number
arguments must fit in the size limita-
tion. Otherwise, xargs terminates exe-
cution.
-t Trace mode: echo command and each con-
structed argument list to file descrip-
tor 2 just prior to their execution.
-p Prompt mode: ask whether or not to exe-
cute command each invocation. Turn on
trace mode (-t) to print the command
instance to be executed, followed by a
?... prompt. Replying with a y (option-
ally followed by anything) executes the
command. Anything else, including a
simple carriage return, skips that par-
ticular invocation of command.
-x Terminate xargs if any argument list is
greater than size characters. The -x
option is forced by the -i and -l
options. When the -i, -l, or -n options
are coded, the total length of all argu-
ments must be within the size limit.
-ssize Set the maximum total size of each argu-
ment list to size characters. Size must
be a positive integer less than or equal
to 470. If the -s option is not coded,
470 becomes the default. Note that the
XARGS-2 Printed 6/10/85
XARGS(1) DOMAIN/IX Reference Manual (SYS5) XARGS(1)
character count for size includes one
extra character for each argument and
the count of characters in the command
name.
-eeofstr Use eofstr as the logical end-of-file
string. An underscore (_) is assumed
for the logical EOF string if the -e
option is not coded. The value of -e
with no eofstr coded turns off the logi-
cal EOF string capability (an underscore
is taken literally). Xargs reads stan-
dard input until it encounters either an
end-of-file or the logical EOF string.
EXAMPLES
To move all files from directory $1 to directory $2, and to
echo each move command just before executing, use the fol-
lowing:
ls $1 | xargs -i -t mv $1/{} $2/{}
To combine the output of the parenthesized commands onto one
line, which is then echoed to the end of file log, use this:
(logname; date; echo $0 $*) | xargs >>log
To execute diff (1) with successive pairs of arguments ori-
ginally typed as Shell arguments:
echo $* | xargs -n2 diff
CAUTIONS
Xargs terminates if it receives a return code of -1 from, or
if it cannot execute, command. When command is a Shell pro-
gram, it should explicitly exit with an appropriate value to
avoid accidentally returning with -1. Consult sh (1) for
more information about how the Shell works.
DIAGNOSTICS
Self-explanatory.
RELATED INFORMATION
sh (1).
Printed 6/10/85 XARGS-3