xargs
The command that reads items from its standard input and runs another command with them as arguments, in batches.
Without -0, file names containing spaces or quotes are split or mangled, and commands act on the wrong files.
In more detail
It bridges tools that print file names and tools that only accept arguments, as in find ... | xargs grep. By default it splits on any whitespace and treats quotes specially, so names with spaces break apart; use find -print0 with xargs -0. -n limits how many arguments go to each run.
Example
find data -name "*.log" -print0 | xargs -0 grep -c startRelated terms
- -print0 — The find action that ends each file name with a null byte instead of a newline, for use with xargs -0.
- find command — The find command, which walks a directory tree and prints, or acts on, every entry that passes its tests.
- -exec — The find action that runs a command on the entries it finds, with {} standing for each file name.
- command-line argument — A word given to a command after its name, such as the file names in cp a.txt b.txt.
Taught in
- find And xargs — Bash Scripting & Command Line Automation