find Command Builder

Build correct find commands without memorizing every flag. Set the search path, name glob (with case-insensitive option), file type, maximum depth, size filter, modification time, and action — print, -delete, or -exec cmd {} \;. The command updates live and uses proper quoting for the glob pattern.

How to use the find Command Builder

Fill in the fields to compose your find command:

  • Path — where to start searching. Use . for the current directory, /var/log for an absolute path, or multiple paths separated by spaces.
  • Name glob — a shell glob pattern like *.log or access_*. Check Case-insensitive to use -iname instead of -name.
  • Type — restrict results to files (f), directories (d), or symbolic links (l).
  • Max depth — limits recursion depth; 1 means only the immediate children of the search path.
  • Size — filter by size using + (larger than), - (smaller than), or exact. Units: c bytes, k kilobytes, M megabytes, G gigabytes.
  • Mtime — filter by modification time in days. -7 means modified in the last 7 days; +30 means not modified in the last 30 days.
  • Actionprint (default, lists paths), -delete (removes matching files), or -exec (runs a command on each match, with {} replaced by the file path).

How Linux find Works

find is the most powerful file-search utility on Unix/Linux systems. Unlike ls, which lists the immediate contents of a directory, find recursively walks a directory tree and evaluates each file against a set of predicates (tests). The results can be acted on in-place with -delete or -exec, making find the backbone of many maintenance scripts, log rotation systems, and build tools.

The name glob (-name / -iname) uses shell-style wildcards (* matches any string, ? matches one character, [...] matches a character class) but the glob is evaluated by find itself — it must be quoted to prevent the shell from expanding it before find sees it. The generator always outputs the glob in single quotes.

The -exec action runs a command for each matching file. The {} placeholder is replaced by the file path and the command must be terminated by ; (escaped as \; to prevent shell interpretation). For better performance on large result sets, -exec cmd {} + groups files into a single command invocation instead of one per file — equivalent to piping through xargs. The -delete action is faster than -exec rm {} \; but always test with print first before switching to -delete.

Common use cases

  • Log cleanup — delete log files older than 30 days: find /var/log -name "*.log" -mtime +30 -delete.
  • Security audits — find SUID/SGID binaries or world-writable files using -perm predicates (extend the generated command).
  • Build artifacts — locate all *.pyc or __pycache__ directories for cleanup before packaging.
  • Large file discovery — find files over 100MB that might be filling a disk: find / -type f -size +100M.
  • Batch processing — use -exec to compress, move, or transform every file matching a pattern in a directory tree.
  • Recently modified files — find files changed in the last 24 hours (-mtime -1) for change auditing or incremental backups.

Frequently asked questions

Why must the glob pattern be quoted?

Without quotes, the shell expands *.log to the matching filenames in the current directory before find runs. If no files match in the current directory you get an error; if they do match you get unexpected results. Always quote globs with single quotes: -name '*.log'.

What is the difference between -mtime, -atime, and -ctime?

-mtime matches by content modification time, -atime by last access time, and -ctime by inode change time (which includes metadata changes like permissions). For most cleanup tasks, -mtime is what you want.

How do I exclude a directory from find results?

Use -not -path '*/node_modules/*' or the more efficient -path '*/node_modules' -prune -o -print pattern. The -prune approach skips descending into the directory entirely, which is much faster on large trees.

Is -delete safe to use?

Always run your find command with the default print action first to see exactly what will be deleted. Then add -delete. Note: -delete implies -depth (deepest first), which changes traversal order; this matters when deleting directories.

Why does find / run slowly?

Searching from / visits every file on every mounted filesystem, including network mounts, proc, and sys. Add -xdev to stay on the same filesystem, or specify a more targeted path. Use -maxdepth to limit recursion depth when you only need a shallow search.