5 ms·
find ./ -name '*.log' -print0 | xargs -0 rm Fixes that issue and xargs is far more efficient, it doesn't launch a new process for each line like exec does, but
by gnaritas 14y ago
find ./ -name '*.log' -print0 | xargs -0 rm
Fixes that issue and xargs is far more efficient, it doesn't launch a new process for each line like exec does, but far more importantly, xargs is generalizable to all commands so you only have to learn it once; exec is just an ugly hack on find, you can't generalize it across all commands; xargs is much more unixy.
- masklinn 14y ago> it doesn't launch a new process for each line like exec does Exec doesn't either if you use "+" as a terminator: find . $(options) -exec command {} \; executes one command per match, find . $(options) -exec command {} + executes a single command with all matches > exec is just an ugly hack on find Obvious and complete nonsense, -exec is both an important predicate of find and a useful and efficient tool. -print0/xargs -0, now that is a hack.
- gnaritas 14y agoYou apparently missed the part where I said "but far more importantly".
- ralph 14y agoWanting to remove the files was so common that some finds have it built-in. Avoids even the overhead of -exec rm {} +. find -name '*.log' -delete
- gnaritas 14y agoTrue, but the issue isn't removing files, the issue is generalizing a command for mapping output of a command to another command. rm was just a simple example. xargs is far more useful than simply deleting files.