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:
| Option | Description |
|---|---|
| -name 'pat' | Match files by name (case-sensitive); use quotes for wildcards. |
| -iname 'pat' | Match by name, case-insensitive. |
| -type t | Match a type: f (file), d (directory), l (symlink). |
| -size n | Match by size, e.g. +100M (over 100 MB), -1k (under 1 KB). |
| -mtime n | Modified n days ago; +7 means more than 7 days, -1 within a day. |
| -mmin n | Modified n minutes ago. |
| -user name | Files owned by a specific user. |
| -perm mode | Match files with specific permissions. |
| -empty | Match empty files and directories. |
| -maxdepth n | Limit how many levels deep to search. |
| -exec cmd {} \; | Run a command on each match ({} is the file). |
| -delete | Delete 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 fAdvanced 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 +30For 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 tofindinstead of expanding them first. - Test destructive searches without the action first — run the
findalone, confirm the list, then add-deleteor-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