How to find files and directories

Overview

find walks a directory tree and tests every item against conditions. Start in a narrow directory to keep output and runtime manageable.

Examples

find ~/Documents -name 'notes.txt'
find . -iname '*.jpg'
find . -type d -name 'backup*'
find ~/Downloads -type f -size +100M

Useful tests

  • -name matches case-sensitively; -iname ignores case
  • -type f selects files; -type d selects directories
  • -maxdepth 2 limits traversal depth
  • -mtime -7 selects items modified in the last seven days
  • -size +100M selects items larger than 100 MiB

Tips and safety

Quote wildcard patterns so the shell does not expand them before find sees them. Add 2>/dev/null only if you understand that it hides error messages.

Preview matches before combining find with deletion or other modifying actions.