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

  1. Find by name:
find /home -name "*.txt"
  1. Find by type:
find /var/log -type f -mtime +7
  1. Find and execute:
find . -name "*.tmp" -exec rm {} \;
  1. Find by size:
find / -size +100M

Tips

  • Use -iname for case-insensitive name matching.
  • find is more flexible than locate, which relies on a database.
  • Combine with xargs for efficient bulk operations.

Common issues

  • Permission denied errors: run with sudo or redirect stderr.
  • Missing -name quotes can cause shell expansion before find runs.