Linux find Command: Search Files by Name, Type, Size, and Time

The find command walks one or more directory trees and evaluates conditions for every entry. It can match names, types, sizes, timestamps, permissions, and other metadata, then print results or run an action on matching paths.

This guide explains the basic syntax, key options, practical examples, related commands, common cautions, and frequently asked questions for find.

What Is the find Command?

Its command line consists of starting paths followed by an expression. The expression contains tests, logical operators, and actions evaluated from left to right. If no action is specified, matching paths are printed. Because it reads the live filesystem, results reflect the state encountered during the walk.

Basic Syntax

find [STARTING-POINT]... [EXPRESSION]

Options and edge cases can vary by implementation and version. Check find --help and man find on the target system before relying on implementation-specific behavior.

Basic find Usage

Search by name

Quote wildcard patterns so the shell does not expand them before find receives the pattern.

find . -name '*.log'

Filter by type and size

Here -type f selects regular files and -size +100M selects files larger than 100 MiB in GNU find.

find /var -type f -size +100M

Filter by modification time

-mtime uses rounded 24-hour periods. Use -mmin when minute-level windows are more appropriate.

find /srv/app -type f -mmin -60

Check search scope and result paths

find actually searches under the specified starting directory. Enclose the pattern in quotes so the shell does not expand it first.

mkdir -p demo-find
touch demo-find/a.txt
find demo-find -name '*.txt'

Example output:

demo-find/a.txt

The default output shows paths including the starting path. Before combining with -delete or -exec, first verify that the search results include only the intended files.

Key Options

Option Purpose
-name PATTERN Match a case-sensitive basename pattern.
-iname PATTERN Match a basename pattern without case sensitivity.
-type TYPE Restrict results to regular files, directories, links, or another type.
-maxdepth N Limit descent below each starting point.
-mtime N Test modification age in 24-hour units.
-size N Test file size with an optional unit suffix.
-exec COMMAND {} + Pass batches of matching paths safely as command arguments.
-delete Delete matching entries after carefully validating the expression.

Practical Examples

Find empty directories

Combine -empty with a type test because empty regular files can also match.

find . -type d -empty -print

Process matching files safely

The {} + form builds batches and preserves filenames that contain spaces or newlines.

find . -type f -name '*.tmp' -exec ls -l -- {} +

Review before deleting

Run the exact path and tests with -print first. Add -delete only after the output is correct.

find ./cache -type f -mtime +30 -print
find ./cache -type f -mtime +30 -delete

find and Related Commands

Command Primary role Best fit
find Walk the live filesystem Detailed metadata tests and actions
locate Search a filename index Fast name lookup
which Search PATH for executables Finding an external command
grep -R Search file contents Finding text patterns

Important Cautions

Quote wildcard patterns

An unquoted pattern such as *.log can be expanded by the current shell and change the expression.

-delete acts immediately

Validate the starting points and tests with -print, and consider mount and symbolic-link behavior.

Understand expression precedence

When combining -o with other tests, group conditions explicitly and escape parentheses from the shell.

FAQ

Does find search subdirectories automatically?

Yes. It recursively walks below each starting point unless depth options restrict it.

How do I ignore case in a filename match?

GNU find provides -iname.

How do I handle spaces safely?

Use -exec COMMAND {} + or NUL-delimited output with a compatible consumer.

Why is find slower than locate?

Find visits the live directory tree, while locate queries a prebuilt database.

Related Resources