How to find files in Linux with find
· Category: Linux
Short answer
find traverses directories and locates files matching criteria such as name, type, size, and time.
Steps
- Find by name:
find /home -name "*.txt"
- Find by type:
find /var/log -type f -mtime +7
- Find and execute:
find . -name "*.tmp" -exec rm {} \;
- Find by size:
find / -size +100M
Tips
- Use
-inamefor case-insensitive name matching. findis more flexible thanlocate, which relies on a database.- Combine with
xargsfor efficient bulk operations.
Common issues
- Permission denied errors: run with
sudoor redirect stderr. - Missing
-namequotes can cause shell expansion beforefindruns.