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 mkdir Command: Create Directories and Parent Paths

Linux mkdir Command: Create Directories and Parent Paths

Learn how to create directories with Linux mkdir, build missing parent paths, set permissions, understand umask behavior, and verify results in scripts.

Linux systemctl Command: Manage systemd Services

Linux systemctl Command: Manage systemd Services

Learn how to manage systemd Services with the Linux systemctl command, including practical examples, key options, and important precautions.

Linux alias Command: Create Command Shortcuts

Linux alias Command: Create Command Shortcuts

Learn how to use the Linux alias command to create, inspect, and make shell command aliases persistent, with essential options, practical examples, output interpretation, and common troubleshooting tips.

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.

Bash Command Operators Explained: ;, &&, ||, &, and |

Bash Command Operators Explained: ;, &&, ||, &, and |

Understand how Bash operators run commands sequentially, conditionally, in the background, or through pipelines, with practical examples and precedence guidance.

Linux timedatectl Command: Check Time Zone and Time Synchronization

Linux timedatectl Command: Check Time Zone and Time Synchronization

Learn how to check Time Zone and Time Synchronization with the Linux timedatectl command, including practical examples, key options, and important precautions.

Linux apt-get Command: Run APT Package Operations in Scripts

Linux apt-get Command: Run APT Package Operations in Scripts

Learn how to run APT Package Operations in Scripts with the Linux apt-get command, including practical examples, key options, and important precautions.

Linux locate Command: Search Indexed File Paths Quickly

Linux locate Command: Search Indexed File Paths Quickly

Learn how Linux locate searches a filename database, how updatedb affects freshness, how to limit and filter matches, and when find is the better tool.

Linux xz Command: Compress a File in xz Format

Linux xz Command: Compress a File in xz Format

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

Linux ssh Command: Connect to a Remote Host Securely

Linux ssh Command: Connect to a Remote Host Securely

Learn how to connect to a Remote Host Securely with the Linux ssh command, including practical examples, key options, and important precautions.