Delete Files in Bulk with find -exec

Combine find and rm -f {} + to remove every matching file without an argument-list error.

LinuxFilesfindHigh risk
Run find ./logs -name "*.tmp" -type f -exec rm -f {} + to delete all .tmp files under ./logs in batches.

01Command

Command
$ find ./logs -name "*.tmp" -type f -exec rm -f {} +

02What it does

find builds the list of matches itself and -exec rm -f {} + passes them to rm in large batches, so you avoid the classic 'argument list too long' error from rm *.log on a directory with millions of files. The + form is more efficient than \; which launches one rm per file. Always run the find part without -exec first to preview exactly what will be deleted.

03Risk

RiskHigh risk
!Warning: Preview first: run the command without -exec rm -f {} + to see the file list. A wrong -name pattern starting at the wrong directory can delete a lot very quickly.

04Undo

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

05Sources

  • find(1) — man7.org
    man7.org · community · 2026-09-17
    Evidence: Man page documents the -exec action, the {} placeholder, the + form that batches matches into one invocation, and -delete
  • find(1) — Ubuntu manpage
    Ubuntu · community · 2026-09-17
    Evidence: Ubuntu manpage describes -exec and -execdir actions with {} placeholder and batching with +

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

06Related solutions