Basic find Structure
Bash
find [path] [] []Search by Name and Extension
Bash
# Exact filename match
find /var/log -name "nginx.log"
# Wildcard (case-sensitive)
find . -name "*.log"
# Case-insensitive
find . -iname "*.Log"
# Exclude a specific directory
find . -name "*.js" -not -path "*/node_modules/*"Filter by Type, Size, and Date
Bash
# Files only (-type f), directories only (-type d)
find /opt -type f -name "*.conf"
# Size condition (files larger than 100MB)
find /var -type f -size +100M
# Modified within the last 7 days
find /home -type f -mtime -7
# Files not accessed in 30+ days
find /tmp -type f -atime +30Apply Commands to Results with exec
Bash
# Delete all matching files
find /tmp -type f -name "*.tmp" -exec rm {} \;
# Change permissions on matching files
find /var/www -type f -exec chmod 644 {} \;
# Change directory permissions only
find /var/www -type d -exec chmod 755 {} \;
# Process in one go with xargs (faster)
find . -name "*.log" -mtime +30 | xargs rm -fPractical Patterns
Bash
# Find empty files
find . -type f -empty
# Find and delete empty directories
find . -type d -empty -delete
# Files with the SUID bit set (security audit)
find / -perm -4000 -type f 2>/dev/null
# Files changed within the last hour
find /etc -type f -newer /tmp/checkpoint
# Compress log files then delete
find /var/log -name "*.log" -mtime +7 -exec gzip {} \; -exec mv {}.gz /archive/ \;Cautions
- When combining with
rm, first verify the targets with-exec ls -la {} \;before running - Restrict
/procand/syswith-xdevso you do not cross mount boundaries - For large directories, sample first with
find ... | head -20
Editorial note
AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us
Topic-related official docs (auto-linked · not per-claim sources)Linux man pages ↗
Questions & answers
Ask a question about this guide. We'll review and reply.