Connect find -print0 and xargs -0
find
parameter -print0
and xargs
parameter -0
must work together. man
the page find
says:
-print0 .... This option corresponds to the -0 option for xargs.
Well, they work for me while find
producing some output. How can I make it work when find produces NO output?
find /dev /sys /usr -maxdepth 0 -print0 | xargs -0 -n1 | wc -l # 3 - OK
find /dev /sys -maxdepth 0 -print0 | xargs -0 -n1 | wc -l # 2 - OK
find /dev -maxdepth 0 -print0 | xargs -0 -n1 | wc -l # 1 - OK
find /dev -maxdepth 0 -name "x" -print0 | xargs -0 -n1 | wc -l # 1 instead of 0 - Fail
Some bad things can happen, such as
find -type d -name ... -print0 | xargs -0 du -sh
when no directories are found xargs
calls du
with no arguments, but du
accepts.
PS I know about the -exec
parameter find
, I just want to connect find
and correctly xargs
.
source to share