xargs

Construct argument list(s) and invoke a program (POSIX)

Syntax:

xargs [-itx] [-n numargs] [-P n] [-s size]
      [program [initial-arguments]]

Options:

-i
(BlackBerry 10 OS extension) Execute in "insert mode." The program is executed once for each item in standard input. Each occurrence of {} in initial-arguments is replaced with the argument read from standard input. If there are no occurrences of {} in initial-arguments, the argument is appended to the initial list.
-n numargs
The maximum number of arguments to append to the command line. The default for numargs is 255.
-P n
(BlackBerry 10 OS extension) Use up to n concurrent commands. The default is 1.
-s size
Set the maximum command buffer to size characters, including program and initial-argument. The default for size is 4096.
-t
Trace; print each program on standard error before executing.
program
The name of the program to execute. The program must be found by searching the path using the PATH environment variable. If you don't specify program, the default is the echo utility.
initial-arguments
One or more arguments to program that are presented every time program is executed.
-x
Terminate if the command line is too long when using numargs (or the default number of) arguments.

Description:

The xargs utility uses character strings, read from standard input, to construct a command line which it executes. The specified program and initial-arguments are placed at the beginning of the command line, followed by some number of character strings read. This process continues until the end of the file.

The utility executes a given program with initial-arguments one or more times using the parameters read from standard input. The number of strings appended may be limited by the -n option; the size of the command line may be limited by the -s option.

The strings are separated by blanks or newlines, which may be embedded in the strings by prefixing them with \ or enclosing them in quotes ("). To use the quote character as itself, you must prefix it with a \.

The -i option causes the command to be executed for each string read. Instead of the normal process of appending the string to the command buffer, the initial-arguments are scanned, and every occurrence of {} is replaced by the string. If {} doesn't occur in initial-arguments, the string is appended to the command line and executed.

When a program is executed, it inherits standard output and standard error from xargs. Standard input is set to the controlling tty.

Examples:

Display the files in the current working directory, and all subdirectories, in two columns:

find . -print | xargs -n 2 echo

Exit status:

0
All invocations of program completed successfully.
> 0
An error occurred.

Last modified: 2013-12-21

comments powered by Disqus