File search by name, type, size, time, permissions & actions
Linux / Command# Syntax
find [path] [expression]
find . # list everything
find /var/log # search in /var/log
find . -maxdepth 1 # current dir only
find . -maxdepth 2 # 2 levels deep
find . -mindepth 2 # skip first levelfind . -name "*.py" # exact pattern (case sensitive)
find . -iname "*.py" # case insensitive
find . -name "test*" # starts with "test"
find . -not -name "*.log" # exclude pattern
# Path pattern
find . -path "*/src/*.js"
find . -not -path "*/node_modules/*"
# Regex
find . -regex ".*\.(py|js)"# Type
find . -type f # regular files
find . -type d # directories
find . -type l # symlinks
# Size
find . -size +100M # larger than 100MB
find . -size -1k # smaller than 1KB
find . -size 50M # exactly 50MB
find . -empty # empty files/dirs
# Size units: c(bytes) k(KB) M(MB) G(GB)# Modified time (days)
find . -mtime -7 # last 7 days
find . -mtime +30 # more than 30 days ago
find . -mtime 0 # today
# Modified time (minutes)
find . -mmin -60 # last 60 minutes
# Access time / Change time
find . -atime -7 # accessed in last 7 days
find . -ctime -7 # status changed
# Newer than file
find . -newer reference.txtfind . -perm 644 # exact permissions
find . -perm -644 # at least these perms
find . -perm /111 # any execute bit
find . -user username
find . -group groupname
find . -uid 1000
find . -nouser # no matching user# Execute command
find . -name "*.log" -exec rm {} \;
find . -name "*.py" -exec grep -l "TODO" {} +
# Print (default)
find . -name "*.txt" -print
find . -name "*.txt" -print0 # null-delimited
# Delete
find . -name "*.tmp" -delete
# Confirm before action
find . -name "*.log" -ok rm {} \;
# With xargs
find . -name "*.txt" -print0 | xargs -0 grep "pattern"# Find large files
find / -type f -size +500M 2>/dev/null
# Find and delete old logs
find /var/log -name "*.log" -mtime +90 -delete
# Count files by extension
find . -type f | sed 's/.*\.//' | sort | uniq -c | sort -rn
# Find duplicate filenames
find . -type f -printf "%f\n" | sort | uniq -d
# Fix permissions
find . -type f -exec chmod 644 {} +
find . -type d -exec chmod 755 {} +
# Find recently modified
find . -type f -mmin -30 -ls