logoalt Hacker News

db48xtoday at 3:18 AM2 repliesview on HN

> Or maybe you pipe into xargs and pray your filenames don’t have spaces…

Always use -0. Most gnu utilities support it. It makes them put a null byte after every filename instead of a newline. Completely eliminates the problem of dealing with whitespace in the filenames.


Replies

AdieuToLogictoday at 3:28 AM

To support your recommendation and redress the strawman the article postulates, the post's author could have replaced:

  find . -name '*.log' | xargs rm
With:

  find . -name '*.log' -print0 | xargs -0 rm
show 1 reply
jsrcouttoday at 7:42 AM

For tools that don't support -0, you can add the NULs yourself without much fuss. It's a one-liner in awk/perl/sed. Very handy.

show 1 reply