|
|
|
|
|
by tom_alexander
11 days ago
|
|
> Or maybe you pipe into xargs and pray your filenames don’t have spaces: > find . -name '*.log' | xargs rm No need for prayer: find . -name '*.log' -print0 | xargs --null rm
That uses null as a delimiter instead of linebreaks. |
|
--null/-0 is portable and helps, but it means the input has to be NUL-delimited, which is... rare. Sure, find has -print0 but (a) I wish I didn't need to do that, and (b) sometimes it's nice to just pipe `ls` output into xargs, without a `... | while read i; do echo -ne "${i}\0"; done | ...` kludge in the pipeline.
Because spaces in filenames is just common enough to be something that will bite you eventually, but newlines in filenames are a straight evil that you can basically always say is the filename's fault.