Construct argument list(s) and invoke program (POSIX)
xargs [-n number] [-s size] [-t] [-i] [-P n] [program [initial-arguments]]
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.
The xargs utility will always limit the total command buffer size to 4096 characters. The following example may be used to verify the integrity of data files on a floppy disk (mounted as /fd):
find /fd -print | xargs cksum | diff check_file -
In the example above, find will print out the names of each file on the mounted filesystem. The xargs utility will group 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 /fd -exec cksum {} \; | diff check_file -
would achieve the same thing, but would require cksum to be reloaded, once for each file in /fd.
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, in two columns:
find . -print | xargs -n 2 echo