Find by name, type, and path
Find files by name pattern
find . -name "*.log"
Example:
find /var/www -type f -name "*.php"
Find directories only
find . -type d -name "node_modules"
Example:
find /etc -maxdepth 2 -type d
Find by time and size
Files modified in last day
find . -mtime -1
Example:
find /var/log -type f -mmin -30
Large files over 100MB
find / -type f -size +100M
Example:
find . -type f -size +10M -name "*.sql"
Execute actions safely
Delete matched files
find . -type f -name "*.tmp" -delete
Example:
find /tmp -type f -mtime +7 -print -delete
Run command on matches
find . -name "*.sh" -exec chmod +x {} \;
Example:
find . -name "*.log" -exec grep -H "ERROR" {} \;
Common mistakes / Pitfalls
- Running find from / without constraints can be very slow and noisy.
- Using -exec rm without preview can delete critical files accidentally.
- Path patterns differ between -name and -path; test with -print first.
Last updated: February 2026