find – search for files in directory hierarchy

find searches for files and directories based on various criteria like name, size, time, and permissions.
Synopsis
find [PATH...] [EXPRESSION]
Common Options
| Option | Description |
|---|---|
-name PATTERN | Match filename (case-sensitive) |
-iname PATTERN | Match filename (case-insensitive) |
-type f | Files only |
-type d | Directories only |
-size +100M | Larger than 100MB |
-mtime -7 | Modified in last 7 days |
-user USERNAME | Owned by user |
-perm 755 | With specific permissions |
-exec CMD {} \; | Execute command on results |
-delete | Delete matching files |
Examples
Find by name
$ find /home -name "*.txt"
$ find . -iname "readme*" # Case-insensitive
Find by type
$ find /var/log -type f # Files only
$ find . -type d -name "test" # Directories named "test"
Find by size
$ find /home -size +100M # Larger than 100MB
$ find . -size -1k # Smaller than 1KB
$ find /tmp -size 0 # Empty files
Find by time
$ find . -mtime -7 # Modified in last 7 days
$ find . -mtime +30 # Modified more than 30 days ago
$ find . -mmin -60 # Modified in last 60 minutes
Find and execute command
$ find . -name "*.log" -exec rm {} \;
$ find . -type f -exec chmod 644 {} \;
$ find . -name "*.txt" -exec grep "error" {} +
Find and delete
$ find /tmp -type f -mtime +7 -delete
$ find . -name "*.tmp" -delete
Find by permissions
$ find /var/www -perm 777 # Exactly 777
$ find . -perm -u+x # User executable
Find by owner
$ find /home -user greys
$ find /var -group www-data
Combine conditions
# AND (default)
$ find . -name "*.log" -size +1M
# OR
$ find . -name "*.jpg" -o -name "*.png"
# NOT
$ find . -type f ! -name "*.txt"
Limit depth
$ find . -maxdepth 1 -type f # Current dir only
$ find . -maxdepth 2 -name "*.md"
Find empty files/directories
$ find . -type f -empty
$ find . -type d -empty
Common Patterns
Find and count
$ find . -name "*.py" | wc -l
Find recently modified
$ find . -mmin -30 -type f # Last 30 minutes
Find large files
$ find / -type f -size +500M 2>/dev/null
Find and archive
$ find . -name "*.log" -exec tar -rvf logs.tar {} \;
Find duplicate names
$ find . -type f -name "*.txt" | xargs -I{} basename {} | sort | uniq -d
Tips
- Use -print0 with xargs -0 for filenames with spaces
- Redirect errors:
2>/dev/nullto hide permission denied - Use locate for speed: It uses a database (but may be outdated)
- Modern alternative:
fdis faster and simpler for common cases - Test before -delete: Run without
-deletefirst to verify matches
See Also
Related Commands
- locate — Fast file search using database
- grep — Search file contents
- xargs — Build commands from input






