xargs

NAME

xargs - construct argument list(s) and execute utility

SYNOPSIS

xargs [-t] [-p] [-e[eofstr]] [-E eofstr] [-I replstr] 
	[-i[replstr]] [-L number] [-l [number]] 
	[-n number [-x]] [-s size] [utility [argument...]]

DESCRIPTION

The xargs(1) utility reads arguments from standard input and then runs the specified utility with those arguments (and any specified on the command line). Arguments are delimited by spaces, tabs, newlines, and end-of-file. The xargs(1) utility is often used for splitting very long argument lists into smaller chunks.

The utility and any arguments specified on the command line are given to the utility upon each invocation, followed by some number of the arguments read from standard input. The utility is repeatedly executed until standard input is exhausted.

Spaces, tabs and newlines can be embedded in arguments using single quotes ('). Single quotes escape all non-single quote characters, excluding newlines, up to the matching single quote. Double quotes escape all non-double quote characters, excluding newlines, up to the matching double quote. Any single character, including newlines, can be escaped by a backslash.

The options are as follows:

-e
eofstr is taken as the logical end-of-file (EOF) string. Underscore (_) is assumed for the logical EOF string if neither -e nor -E is specified. The value -e with no specified eofstr turns off the logical EOF string capability (underscore is taken literally). The xargs utility reads the standard input until it encounters end-of-file or the logical EOF string.
-E
Specifies a logical end-of-file string to replace the default underscore. The xargs utility reads standard input until it encounters end-of-file or the logical EOF string.
-I
Insert mode. The utility is run for each line from the standard input, taking the entire line as a single argument and inserting it into initial-arguments for each occurrence of replstr. A maximum of five arguments in initial-arguments can each contain one or more instances of replstr. Blanks and tabs at the beginning of each line are discarded. Constructed arguments cannot exceed 255 bytes. The -I option forces the -x option. The -I and -i options are mutually exclusive; the last one specified takes effect.
-i
This option is equivalent to -I [replstr]. The string{} is assumed for replstr if the option argument is omitted.
-L
The utility is run for each nonempty number lines of arguments from the standard input. The last invocation of utility will contain fewer lines of arguments than specified 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 or tab signals continuation through the next nonempty line. The -L, -l, and -n options are mutually exclusive; the last one specified takes effect.
-l (Lowercase L)
This option is equivalent to -L number. If number is omitted, 1 (one) is assumed. The -l option forces the -x option.
-n
Runs utility using as many standard input arguments as possible, up to a maximum of number (a positive decimal integer) arguments. Fewer arguments are used if either of the following conditions exist:
-p
(Prompt mode) Asks the user whether to run utility at each invocation. Trace mode (-t option) is turned on to print the utility to be run, followed by a prompt to the standard error. A reply of y (optionally followed by anything) runs utility. Anything else, including just a carriage return, skips that particular invocation of utility.
-s
Invokes utility using as many standard input arguments as possible, yielding a command-line length less than size (a positive decimal integer) bytes. Fewer arguments will be used if any of the following conditions exist:
-t
(Trace mode) The utility and each constructed argument list are echoed to standard error just prior to their execution.
-x
Causes xargs to terminate if any argument list would be greater than size characters. The -i, -I, -l, and -L options force the -x option. When none of the options -i, -I, -l, -L, or -n are specified, the total length of all arguments must be within the size limit.

If no utility is specified, xargs(1) executes echo(1).

Undefined behavior might occur if utility reads from the standard input.

The xargs(1) utility exits immediately (without processing any further input) if a command line cannot be assembled, utility cannot be invoked, an invocation of the utility is terminated by a signal, or an invocation of the utility exits with a value of 255.

DIAGNOSTICS

The xargs(1) utility exits with a value of 0 if no error occurs. If utility cannot be invoked, xargs(1) exits with a value of 127. If any other error occurs, xargs(1) exits with a value of 1.

EXAMPLES

Run the awk script ~/lib/convert.awk on all files in the current directory (assuming there are too many to use * as the file specifier):

ls | xargs awk -f ~/lib/convert.awk

Remove all files that have not been modified in at least four weeks:

find . -type f -mtime +28 -print | xargs rm

SEE ALSO

echo(1)

find(1)