To run a command on each file find matches, use -exec with {} as the placeholder and a terminator.
The Fix
find . -name "*.log" -exec rm {} \;
For thousands of files, batch them into fewer invocations with + instead of \;:
find . -name "*.log" -exec rm {} +
Why {} and \; Are Needed
{} gets replaced with the matched file’s path. find needs a terminator to know where the -exec command ends, and ; is a shell special character, so it must be escaped (\;) or quoted (';'). Ending with + instead runs the command once with as many matched paths appended as fit, like xargs does, rather than once per file.
Gotchas
- An unescaped
;gets eaten by the shell beforefindever sees it, producingfind: missing argument to '-exec'. \;runs the command once per file (correct but slow for large trees).+batches them (fast), but only works if the command accepts multiple trailing arguments;rmdoes, not everything does.{}must come before the terminator:find . -exec cmd \; {}is invalid syntax, not just bad style.