Linux Command: find
Search for files and directories in a directory hierarchy
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 fFind large files
find /var -type f -size +100M 2>/dev/nullFind recently modified files
find /etc -type f -mtime -7Pro 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 โ