====== xargs command line examples ======
This article provides usage examples of the xargs linux/unix utility.
===== About xargs =====
xargs is a linux/unix command line utility that reads items from the standard input, delimited by blanks or newlines, and executes a command on each item.
===== Usage examples =====
The following are usage examples that show the different ways xargs can be used.
==== Find all .log files and display them on stdout. ====
find /path -name *.log | xargs cat
==== Find all .log files and copy them to /tmp/ ====
find /path -name *.log | xargs -I% cp % /tmp/
The -I //replace-str// option causes xargs to replace occurrences of //replace-str// in the command arguments with items read from standard input.
==== Generate compact user list (replace newline by whitespace) ====
cut -d: -f1 < /etc/passwd | sort | xargs echo
{{tag>unix howto}}
~~DISCUSSION~~