Basic File Search
- Find all files in a directory
find /path/to/dir -type f
Find all regular files. - Find all directories
find /path/to/dir -type d
Find all directories. - Find files by name
find /path/to/dir -name "file.txt"
Search for files with the exact namefile.txt. - Case-insensitive name search
find /path/to/dir -iname "file.txt"
Find files namedfile.txt, ignoring case. - Find files by extension
find /path/to/dir -name "*.txt"
Search for all.txtfiles.
Search by File Size
- Files larger than 10MB
find /path/to/dir -size +10M - Files smaller than 500KB
find /path/to/dir -size -500k - Files exactly 1GB
find /path/to/dir -size 1G
Search by Time
- Find files modified in the last 7 days
find /path/to/dir -mtime -7 - Find files modified more than 30 days ago
find /path/to/dir -mtime +30 - Find files accessed in the last 24 hours
find /path/to/dir -atime -1 - Find files with a specific modification time
find /path/to/dir -newermt "2024-11-01"
Find files modified after a specific date.
User and Permissions
- Find files owned by a specific user
find /path/to/dir -user username - Find files owned by a group
find /path/to/dir -group groupname - Find files with specific permissions
find /path/to/dir -perm 644 - Find executable files
find /path/to/dir -perm /111
Combining Conditions
- Find
.txtfiles modified in the last 7 daysfind /path/to/dir -name "*.txt" -mtime -7 - Find
.logfiles larger than 1MBfind /path/to/dir -name "*.log" -size +1M - Find files owned by a user and writable
find /path/to/dir -user username -perm -u=w
Actions on Found Files
- Delete files matching a condition
find /path/to/dir -name "*.tmp" -delete - Move found files
find /path/to/dir -name "*.log" -exec mv {} /new/path \; - Change permissions
find /path/to/dir -type f -exec chmod 644 {} \; - Print only file names
find /path/to/dir -type f -print
Symbolic Links
- Find symbolic links
find /path/to/dir -type l - Follow symbolic links during search
find /path/to/dir -L -name "*.txt"
Depth and Scope
- Limit search depth
find /path/to/dir -maxdepth 2 -name "*.txt" - Search only current directory
find /path/to/dir -maxdepth 1 -type f - Exclude specific directory
find /path/to/dir -path "/path/to/dir/exclude" -prune -o -name "*.txt" -print
Advanced Examples
- Find empty files
find /path/to/dir -type f -empty - Find files matching multiple patterns
find /path/to/dir \( -name "*.txt" -o -name "*.log" \) - Find recently created files
find /path/to/dir -ctime -7
Files created in the last 7 days. - Count files
find /path/to/dir -type f | wc -l
Examples for Special Cases
- Find files by inode
find /path/to/dir -inum 123456 - Find files with specific file system type
find /path/to/dir -fstype ext4 - Find broken symbolic links
find /path/to/dir -xtype l