xargs(1) xargs(1)NAME xargs - builds arguments based on the standard input, passing them in batches to the specified command which is executed enough times to deplete all the arguments SYNOPSIS xargs [-eeofstr] [-ireplstr] [-lnumber] [-nnumber] [-p] [-ssize] [-t] [-x] [command [cmd-args]] ARGUMENTS command Specifies the given command which xargs executes. cmd-args Represents the arguments that are passed to the specified command when it is executed. -eeofstr Specifies the logical end-of-file string. Underbar (_) is assumed for the logical EOF string if -e is not coded. The value -e with no eofstr coded turns off the logical EOF string capability (underbar is taken literally). xargs reads standard input until either end-of-file or the logical EOF string is encountered. -ireplstr Indicates the insert mode. The command is executed for each line from standard input, taking the entire line as a single argument, inserting it in cmd-args for each occurrence of replstr. A maximum of 5 arguments in cmd-args may each contain one or more instances of replstr. Blanks and tabs at the beginning of each line are thrown away. Constructed arguments may not grow larger than 255 characters, and the -x option is forced. {} is assumed for replstr if not specified. -lnumber Executes command for each nonempty 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 nonempty line. If number is omitted, 1 is assumed. The -x option is forced. -nnumber Executes command using as many standard input arguments as possible, up to number arguments maximum. Fewer arguments 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 January 1992 1
xargs(1) xargs(1)the -x option is also coded, each number arguments must fit in the size limitation, else xargs terminates execution. -p Specifies the prompt mode. The user is asked whether to execute command at each invocation. Trace mode (-t) is turned on to print the command instance to be executed, followed by a ?... prompt. A reply of y (optionally followed by anything) will execute the command; anything else, including just a carriage return, skips that particular invocation of command. -ssize The maximum total size of each argument list is set to size characters; size must be a positive integer less than or equal to 1180. If -s is not coded, 1180 is taken as the default. Note that the character count for size includes one extra character for each argument and the count of characters in the command name. -t Indicates the trace mode. The command and each constructed argument list are echoed to file descriptor 2 just prior to their execution. -x Causes xargs to terminate if any argument list would be greater than size characters; -x is forced by the -i and -l options. When none of the -i, -l, or -n options are coded, the total length of all arguments must be within the size limit. DESCRIPTION xargs combines the fixed cmd-args with arguments read from standard input to execute the specified command one or more times. The number of arguments read for each command invocation and the manner in which they are combined are determined by the options specified. The replacement for command, may be a shell file. In any case, xargs searches for commands as directed by the $PATH variable. If command is omitted, /bin/echo is used. Arguments read in from standard input are defined to be contiguous 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 of quoted strings, a backslash (\) will escape the next character. Each argument list is constructed starting with cmd-args, followed by some number of arguments read from standard 2 January 1992
xargs(1) xargs(1)input (Exception: see 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, cmd-args are followed by arguments read continuously from standard input until an internal buffer is full, and then command is executed with the accumulated arguments. This process is repeated until there are no more arguments. When there are option conflicts (for example, -l versus -n), the last option has precedence. The xargs program will terminate if: it cannot execute command; or if command returns a -1 exit status. When command is a shell program, it should explicitly exit (see sh(1)) with an appropriate value to avoid accidentally returning with -1 . EXAMPLES Enter this command: ls $1 | xargs -i -t mv $1/{} $2/{} to move all files from directory $1 to directory $2, and echo each move command just before doing it. Entering the command: (logname; date; echo $0 $*) | xargs >>log will combine the output of the parenthesized commands onto one line, which is then echoed to the end of file log. This command: ls | xargs -p -l ar r arch ls | xargs -p -l | xargs ar r arch causes the user to be asked which files in the current directory are to be archived and archives them into arch one at a time in the first instance, or as in the second instance, many at a time. Enter: echo $* | xargs -n2 diff to execute diff(1) with successive pairs of arguments originally typed as shell arguments. FILES /usr/bin/xargs Executable file January 1992 3
xargs(1) xargs(1)SEE ALSO csh(1), ksh(1), sh(1) 4 January 1992