Updated: May 06, 2022

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


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

Runs on:

QNX Neutrino, Microsoft Windows


(QNX Neutrino 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
(QNX Neutrino 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 2048.
Trace; print each program on standard error before executing.
(QNX Neutrino extension) Be verbose; the same as -t.
Terminate if the command line is too long when using numargs (or the default number of) arguments.
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.
One or more arguments to program that are presented every time program is executed.


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.

This utility is available on the target and on Windows hosts as well. The target (QNX Neutrino) and host (Windows) utilities have different supported options and behavior. In a QNX build environment on the host, you can view the use message that explains the semantics by running the following command:
xargs --help

The utility can be specified as xargs in host scripts and command lines; specifying the full path isn't necessary.

For Linux and Mac, no xargs utility is supplied with the QNX SDP because these OSs come with their own versions of xargs.

The QNX Neutrino 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 a backslash (\) 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. If a single argument would cause an overflow of the command buffer, an error message is printed and the argument is ignored.

The following example may be used to verify the integrity of data files on a filesystem (mounted as /):

find / -print | xargs cksum | diff check_file -

In the example above, find prints the name of each file on the mounted filesystem. The xargs utility groups the filenames up for cksum to minimize the number of times cksum must be executed. The diff utility is then used to verify that the calculated checksums are the same as recorded in the check_file file.

It's important to note that the following command:

find / -exec cksum {} \; | diff check_file -

achieves the same thing, but requires cksum to be reloaded once for each file in /.


Use cmp to determine whether the files in the directory old_data are the same as the files in the directory new_data:

ls old_data | xargs -i cmp old_data/{} new_data/{}

Display the files in the current working directory and all subdirectories, with two filenames per line:

find . -print | xargs -n 2 echo

Exit status:

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