Batch-process matched files with find -exec

find -exec turns every search result into an argument of another command, replacing fragile shell loops and xargs plumbing for tasks like deleting all .DS_Store files in a tree.

macOScleanup-execfindHigh risk
Run `find . -name "*.tmp" -exec rm {} +` to delete every matching file found under the current folder.

01Command

Command
$ find . -name "*.tmp" -exec rm {} +
find . -name "*.DS_Store" -type f -exec rm -v {} \;

02What it does

The {} placeholder is replaced by the found path, and the terminator matters: \; runs the command once per file, while + batches many files into one invocation, which is dramatically faster for rm. The modern alternative is find's own -delete primary, but -exec remains necessary when the command needs arguments beyond a path.

03Risk

RiskHigh risk
!Warning: -exec rm has no trash and no confirmation — a bad -name pattern deletes the wrong files instantly; run the find alone first to preview what matches.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

Last verified: 2026-09-17 · Category: Files & Folders

06Related solutions