find Command
Intermediate File Viewing & Searching man(1)Search for files and directories in a directory hierarchy
👁 13 views
📅 Updated: Mar 15, 2026
SYNTAX
find [PATH] [EXPRESSION]
What Does find Do?
The find command searches for files and directories in a directory hierarchy based on various criteria including name, type, size, permissions, modification time, and more. It is one of the most powerful and versatile commands in Linux.
find traverses directory trees recursively, testing each file against the specified criteria. When matches are found, it can print paths, execute commands on them, or perform other actions. Unlike locate which uses a pre-built database, find searches the actual filesystem in real-time.
find supports complex logical expressions with AND, OR, and NOT operators, allowing sophisticated search queries. It pairs excellently with xargs and -exec for batch operations on found files.
find traverses directory trees recursively, testing each file against the specified criteria. When matches are found, it can print paths, execute commands on them, or perform other actions. Unlike locate which uses a pre-built database, find searches the actual filesystem in real-time.
find supports complex logical expressions with AND, OR, and NOT operators, allowing sophisticated search queries. It pairs excellently with xargs and -exec for batch operations on found files.
Options & Flags
| Option | Description | Example |
|---|---|---|
| -name | Search by filename (case-sensitive, supports wildcards) | find /var -name '*.log' |
| -iname | Case-insensitive name search | find . -iname '*.jpg' |
| -type | Filter by type: f(file), d(directory), l(symlink) | find /etc -type f |
| -size | Filter by file size (+larger, -smaller) | find /var -size +100M |
| -mtime | Filter by modification time in days | find /tmp -mtime +30 |
| -perm | Filter by permissions | find / -perm -4000 -type f |
| -exec | Execute command on each result | find . -name '*.tmp' -exec rm {} \; |
| -maxdepth | Limit directory traversal depth | find / -maxdepth 2 -name "*.conf" |
| -empty | Find empty files or directories | find . -type f -empty |
| -newer | Find files newer than reference file | find . -newer reference.txt |
Practical Examples
#1 Find all PHP files
Searches recursively for PHP files in the src directory.
$ find src/ -name '*.php' -type f#2 Find large files
Finds files larger than 100MB, suppressing permission errors.
$ find /var -type f -size +100M 2>/dev/null#3 Find recently modified files
Finds files modified in the last 7 days.
$ find /etc -type f -mtime -7#4 Find and delete old temp files
Deletes files in /tmp older than 30 days.
$ find /tmp -type f -mtime +30 -delete#5 Find files with specific permissions
Finds all SUID files on the system (security audit).
$ find / -perm -4000 -type f 2>/dev/null#6 Find and execute command
Compresses all log files found.
$ find . -name '*.log' -exec gzip {} \;#7 Complex search with AND/OR
Finds JPEG or PNG files larger than 1MB.
$ find . \( -name '*.jpg' -o -name '*.png' \) -size +1M#8 Find empty directories
Lists all empty directories for cleanup.
$ find . -type d -emptyTips & Best Practices
Use -print0 with xargs: Always use find -print0 | xargs -0 for filenames with spaces. Without it, files like 'my file.txt' will break.
-exec + vs \;: Use -exec cmd {} + instead of -exec cmd {} \; to batch arguments like xargs, significantly improving performance.
find vs locate: find searches the live filesystem (slower but current). locate uses a pre-built database (faster but may be stale). Run updatedb to refresh locate's database.
Frequently Asked Questions
How do I find files by name?
Use find /path -name 'filename'. Use wildcards: find / -name '*.conf'. For case-insensitive: find / -iname '*.conf'.
How do I find files modified in the last N days?
Use find /path -mtime -N for files modified within N days. Use +N for files older than N days. For minutes instead of days, use -mmin.
How do I find and delete files?
Use find /path -name 'pattern' -delete, or find /path -name 'pattern' -exec rm {} \;. Always test with -print first before using -delete.
Related Commands
More File Viewing & Searching Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books →