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

More in This Category
Linux nc Command: Test TCP and UDP Connections

Linux nc Command: Test TCP and UDP Connections

Learn how to test TCP and UDP Connections with the Linux nc command, including practical examples, key options, and important precautions.

Linux column Command: Format Text as a Table

Linux column Command: Format Text as a Table

Learn how to format Text as a Table with the Linux column command, including practical examples, key options, and important precautions.

Linux apt Command: Manage Packages on Debian and Ubuntu

Linux apt Command: Manage Packages on Debian and Ubuntu

Learn how to manage Packages on Debian and Ubuntu with the Linux apt command, including practical examples, key options, and important precautions.

Linux machine-id: How to Check and Reset It for Cloned Systems

Linux machine-id: How to Check and Reset It for Cloned Systems

Learn what the Linux machine-id identifies, how to check it, and how to prepare cloned system images for unique IDs. Understand the difference between an empty file and first-boot initialization.

Linux awk Command: Analyze Text by Fields

Linux awk Command: Analyze Text by Fields

Learn how to analyze Text by Fields with the Linux awk command, including practical examples, key options, and important precautions.

Linux sed Command: Search and Replace Text Streams

Linux sed Command: Search and Replace Text Streams

Learn how to search and Replace Text Streams with the Linux sed command, including practical examples, key options, and important precautions.

Linux gzip Command: Compress a File in gzip Format

Linux gzip Command: Compress a File in gzip Format

Learn how to compress a File in gzip Format with the Linux gzip command, including practical examples, key options, and important precautions.

Linux printf Command: Print Values with a Defined Format

Linux printf Command: Print Values with a Defined Format

Learn how to print Values with a Defined Format with the Linux printf command, including practical examples, key options, and important precautions.

Linux xargs Command: Pass Standard Input as Command Arguments

Linux xargs Command: Pass Standard Input as Command Arguments

Learn how to pass Standard Input as Command Arguments with the Linux xargs command, including practical examples, key options, and important precautions.

Linux htop Command: Explore Processes Interactively

Linux htop Command: Explore Processes Interactively

Learn how to explore Processes Interactively with the Linux htop command, including practical examples, key options, and important precautions.