Quick take: The find command searches a directory tree for files matching criteria such as name, type, size, or age, and can run an action on each match with -exec. The basic form is find PATH -name 'pattern'.

Introduction

The find command is the most powerful file-search tool in Linux. It walks a directory tree and tests each file against conditions you supply — name, type, size, modification time, ownership, permissions — and can then act on the matches, from deleting them to running any command.

This guide builds from simple name searches up to combined conditions and the powerful -exec action that turns find into a batch-processing engine.

Syntax

The basic syntax of the find command is:

find [PATH...] [EXPRESSION]

Common Options and Parameters

The most useful options and parameters for the find command:

OptionDescription
-name 'pat'Match files by name (case-sensitive); use quotes for wildcards.
-iname 'pat'Match by name, case-insensitive.
-type tMatch a type: f (file), d (directory), l (symlink).
-size nMatch by size, e.g. +100M (over 100 MB), -1k (under 1 KB).
-mtime nModified n days ago; +7 means more than 7 days, -1 within a day.
-mmin nModified n minutes ago.
-user nameFiles owned by a specific user.
-perm modeMatch files with specific permissions.
-emptyMatch empty files and directories.
-maxdepth nLimit how many levels deep to search.
-exec cmd {} \;Run a command on each match ({} is the file).
-deleteDelete each matching file (use with care).

Practical Examples

Real find commands you can run today:

# Find files by name under the current directory
find . -name '*.log'
# Case-insensitive name search
find /etc -iname 'nginx*'
# Find only directories
find /var -type d -name cache
# Files larger than 100 MB
find / -type f -size +100M
# Files modified in the last 24 hours
find . -mtime -1
# Delete .tmp files older than 7 days
find /tmp -name '*.tmp' -mtime +7 -delete
# Run a command on each match
find . -name '*.sh' -exec chmod +x {} \;
# Limit search depth to one level
find . -maxdepth 1 -type f

Advanced find: Combining Conditions

find evaluates conditions left to right and joins them with an implicit AND, but you can build precise queries with OR (-o), negation (!), and grouping with escaped parentheses.

# Files ending in .jpg OR .png
find . \( -name '*.jpg' -o -name '*.png' \)

# Files NOT owned by the current user
find /var/www ! -user $USER

# Large, old log files: over 50 MB AND older than 30 days
find /var/log -type f -size +50M -mtime +30

For actions, prefer -exec cmd {} + over \; when the command accepts many arguments — it batches files into far fewer invocations and runs dramatically faster on large trees.

Running find Safely

find can delete or modify thousands of files at once, so a careless command is dangerous. The golden rule is to preview before you act: run the find with no action and confirm the list, then re-run it with -delete or -exec. For deletions, find … -print first, eyeball the output, then swap in -delete.

Also be deliberate about where you start. find / … walks the entire filesystem and can be slow and noisy; scope the search to the relevant directory and add -maxdepth to limit recursion when you only need the top levels.

Tips and Best Practices

  • Always quote wildcard patterns (-name '*.log') so the shell passes them to find instead of expanding them first.
  • Test destructive searches without the action first — run the find alone, confirm the list, then add -delete or -exec.
  • For very large trees, find ... -exec cmd {} + (note the +) batches arguments and runs far fewer processes than \;.

Final Thoughts

find turns “where is that file?” into a precise, scriptable query. Master the core tests — -name, -type, -size, -mtime — and the -exec action, and you can locate and process files across an entire system. It is one of the highest-leverage commands a Linux administrator can know.

FAQ: find Command in Linux

How do I find a file by name in Linux?+

Use find with -name: find /path -name 'filename'. Add -iname instead of -name to ignore case. Quote the pattern when it contains wildcards.

How do I find files larger than a certain size?+

Use -size with a + prefix: find / -type f -size +100M lists files over 100 MB. Use -size -1k for files under 1 KB.

How do I find files modified in the last N days?+

Use -mtime: find . -mtime -7 finds files changed within the last 7 days, while -mtime +30 finds files older than 30 days.

How do I run a command on every file find returns?+

Use -exec: find . -name '*.sh' -exec chmod +x {} \; runs the command on each match, where {} is replaced by the filename.

What is the difference between find and locate?+

find searches the live filesystem in real time and supports rich conditions. locate is faster but reads a prebuilt database that may be out of date and offers far fewer filters.

Need help with Linux servers or infrastructure?

Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.

Hire Me for Support