๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

๐Ÿ’ก File Viewing & Searching October 17, 2026 14

Linux Command: find

Search for files and directories in a directory hierarchy

Terminal โ€” File Viewing & Searching
Command
$ find src/ -name '*.php' -type f

The find command searches for files and directories in a directory hierarchy based on various criteria including name, type, size, permissions, modification time, and more. It is one of the most powerful and versatile commands in Linux. find traverses directory trees recursively, testing each file against the specified criteria. When matches are found, it can print paths, execute commands on them, or perform other actions. Unlike locate which uses a pre-built database, find searches the actual filesystem in real-time. find supports complex logical expressions with AND, OR, and NOT operators, allowing sophisticated search queries. It pairs excellently with xargs and -exec for batch operations on found files.

Syntax

find [PATH] [EXPRESSION]

Key Options

  • -name โ€” Search by filename (case-sensitive, supports wildcards)
  • -iname โ€” Case-insensitive name search
  • -type โ€” Filter by type: f(file), d(directory), l(symlink)
  • -size โ€” Filter by file size (+larger, -smaller)
  • -mtime โ€” Filter by modification time in days
  • -perm โ€” Filter by permissions

Examples

Find all PHP files

find src/ -name '*.php' -type f

Find large files

find /var -type f -size +100M 2>/dev/null

Find recently modified files

find /etc -type f -mtime -7

Pro Tips

  • Always use find -print0 | xargs -0 for filenames with spaces. Without it, files like 'my file.txt' will break.
  • Use -exec cmd {} + instead of -exec cmd {} \; to batch arguments like xargs, significantly improving performance.
  • find searches the live filesystem (slower but current). locate uses a pre-built database (faster but may be stale). Run updatedb to refresh locate's database.

Learn more: Full find reference โ†’

Share this tip