The xargs command
build and execute command lines from standard input 14 examples from the lessons of the IVski Linux Playground — try them in the terminal next to them.
Options in the examples
-n max-args, --max-args=max-args- Use at most max-args arguments per command line.
-P max-procs, --max-procs=max-procs- Run up to max-procs processes at a time; the default is 1.
-0, --null- Input items are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is…
-r, --no-run-if-empty- If the standard input does not contain any nonblanks, do not run the command.
Examples
find . -name "*.txt" | xargs catCat all .txt files
find . -name "*.log" | xargs rmDelete all .log files
echo "file1 file2 file3" | xargs ls -la
find . -name "*.txt" -print0 | xargs -0 rm
cat urls.txt | xargs -P 4 wgetDownload 4 at a time
find . -name "*.jpg" | xargs -P 8 -I{} convert {} {}.png
find . -name "*.txt" | xargs -I{} cp {} /backup/{}
cat names.txt | xargs -I{} echo "Hello, {}!"
xargs -n 1 commandOne arg per command call
xargs -n 3 commandThree args per call
find /var/log -name '*.log' -mtime +7 | xargs gzip
find . -name '*.py' | xargs wc -l
find /etc -name '*.conf' | xargs grep -l 'ServerName'
ls -t ~/backups/docs-*.tar.gz | tail -n +4 | xargs -r rm…deleted (-r: not when there are none)