xargs — building arguments from a stream
cheat sheet · GNU findutils https://lab.dimsanych.ru/en/wiki/xargs/Cheat sheet
-
find . -name '*.x' -print0 | xargs -0 rmsafe (spaces) -
... | xargs -I{} cp {} /dst/substitute {} -
... | xargs -P4 -n1 cmdin parallel -
... | xargs -rt cmdskip if empty + show it -
... | xargs -n1one argument at a time
Options
Without -0, xargs splits the input on spaces and newlines — a file
name with a space turns into two separate arguments. The safe path is a
NUL delimiter on both sides of the pipeline: find -print0 (or grep
-Z) together with xargs -0. -I {} implicitly limits the call to one
argument at a time, like -n1, because you can't substitute several
values into one placeholder at once.