Skip to content

Find Command Builder

Quick Answer

The find command searches a directory tree for files matching tests you combine: -name for a quoted glob, -type f or -type d, -mtime for age in days, -size for size, and -path to include or exclude subtrees. The order of the expression is the program — find evaluates left to right, so an action like -delete or -exec must come after the tests that narrow the matches, or it runs on everything find walks. Two traps cause most accidents: an unquoted -name *.log is expanded by the shell before find sees it, so always quote the pattern; and the age sign is easy to reverse — -mtime +30 means older than 30 days while -mtime -1 means within the last day. This builder assembles the command with tests before actions, quotes patterns for you, explains every flag in plain English, and flags -delete and -exec as the destructive actions to preview with -print first.

How to use the Find Command Builder

  1. 1Set the starting path, then add tests (-name, -type, -mtime, -size) to narrow what matches before adding any action.
  2. 2Leave name patterns to the builder — it quotes -name values so the shell does not expand the glob before find runs.
  3. 3Pick an action last: -print to list, -print0 to pipe into xargs -0, -delete to remove, or -exec to run a command.
  4. 4Preview destructive jobs: generate the -print version, read the file list, then switch the action to -delete.

Run this script on a real Linux server

Get $200 free credit — DigitalOcean

Get $200 Free →

Affiliate link · we earn a commission

Need a domain for your next project?

Register with Namecheap — free WHOIS privacy included

Check Domain Prices →

Affiliate link · we earn a commission

PAID RESOURCE — $9

The Production Bash Toolkit

6 scripts + shared library + 52-page field guide. The production layer the free snippets don't cover.

Get the Toolkit →

Frequently Asked Questions

faq — tool

Why does find -name *.log not work?

The shell expands *.log before find ever runs, so find receives a filename instead of a pattern. Quote it — find -name "*.log" — so find does the matching.

faq — tool

What is the difference between -mtime +30 and -mtime -1?

+30 matches files modified more than 30 days ago; -1 matches files modified within the last day; a bare 30 means exactly day 30. Reversing the sign on a -delete job deletes the wrong files.

faq — tool

How do I delete files found by find without a mistake?

Run the command with -print first and read the list. -delete is an action and must come after the tests; placed before them it deletes everything find walks.

faq — tool

What is the difference between -exec command \; and -exec command +?

\; runs the command once per file; + batches many files into one invocation, which is faster and the right default when the command accepts multiple arguments.

Related Snippets