Overview

find is the most powerful file search tool on Linux. Unlike locate, which relies on a prebuilt index, find walks the filesystem in real time and can filter by name, size, modification time, ownership, permissions, and more. This tutorial covers the patterns you will actually use.

Basic Syntax

find [path] [expression] [action]

If no path is given, find searches the current directory.

Search by Name

# Exact name
find . -name "config.json"

# Case-insensitive
find . -iname "readme.md"

# Wildcard
find /var/log -name "*.log"

# Exclude a directory
find . -path ./node_modules -prune -o -name "*.js" -print

Search by Type

FlagType
-type fRegular file
-type dDirectory
-type lSymbolic link
find /etc -type f -name "*.conf"

Search by Size

# Larger than 100 MB
find / -type f -size +100M

# Smaller than 1 KB
find . -type f -size -1k

# Exactly 512 bytes
find . -type f -size 512c
SuffixUnit
cBytes
kKilobytes
MMegabytes
GGigabytes

Search by Modification Time

# Modified in the last 24 hours
find . -type f -mtime -1

# Modified more than 30 days ago
find . -type f -mtime +30

# Modified in the last 60 minutes
find . -type f -mmin -60

# Newer than a reference file
find . -type f -newer reference.txt

Search by Permissions and Ownership

# World-writable files
find /var/www -type f -perm -o+w

# Files with exactly mode 644
find . -type f -perm 644

# Files owned by a specific user
find /home -user alice

# Files in a specific group
find /srv -group developers

Combining Conditions

find . -type f -name "*.log" -size +10M -mtime +7

Multiple conditions are AND-ed by default. Use -o for OR:

find . -type f \( -name "*.jpg" -o -name "*.png" \)

Actions

ActionEffect
-printPrint the path (default)
-lsPrint with ls details
-deleteDelete the match
-exec cmd {} \;Run a command on each match
-exec cmd {} +Batch matches into one command call
# Delete log files older than 30 days
find /var/log -type f -name "*.log" -mtime +30 -delete

# Compress all logs in one command
find /var/log -type f -name "*.log" -exec gzip {} +

# Change permissions
find /var/www -type d -exec chmod 755 {} +

Performance Tips

  • Use -exec ... + instead of -exec ... \; to avoid spawning a process per file.
  • Prune large directories like node_modules or .git to save time.
  • Narrow the starting path rather than searching from /.