$find
Search for files and directories in a directory hierarchy based on name, type, size, or modification date.
find [PATH] [OPTIONS] [EXPRESSION]Try `find` Live in Interactive Sandbox
Zero-install client simulation with real-time feedback.
Overview & How find Works
The `find` command is one of the most powerful and frequently used command-line utilities in Linux and Unix-like operating systems. It recursively searches through directories and subdirectories to locate files matching specific criteria such as filename patterns, file extensions, permission modes, file types, modification dates, and size thresholds. Unlike the `locate` command which queries a pre-built database index, `find` searches the live filesystem in real-time, ensuring 100% accurate results even for newly created or modified files.
Common Flags & Command Options
| Flag / Option | Description |
|---|---|
| -name [pattern] | Search for files matching the specified filename or wildcard pattern (case-sensitive). |
| -iname [pattern] | Search for files matching the pattern ignoring case distinctions. |
| -type [f|d|l] | Filter results by file type: f (regular file), d (directory), l (symbolic link). |
| -size [+|-][n] | Search by file size: +10M (larger than 10MB), -1k (smaller than 1KB). |
| -mtime [n] | Find files modified n*24 hours ago (+7 for older than a week, -1 for last 24h). |
| -exec [cmd] {} \; | Execute a specific shell command on each matching file found. |
Practical Real-World Examples
find /var/log -name "*.log"Recursively scans the /var/log directory for all files ending with the .log extension.
find /home/user -type dFilters and outputs only directory paths inside the user home folder.
find . -type f -mtime -1Locates recently created or modified files in the current working directory.
Common Errors & Troubleshooting
Frequently Asked Questions
How do I search for files ignoring uppercase and lowercase?
Use the `-iname` flag instead of `-name`, for example: `find . -iname "readme.txt"` matches README.txt, Readme.TXT, and readme.txt.
How do I delete all found files automatically?
You can use the `-delete` action or `-exec rm -f {} \;`. Always test your search query first before running the delete flag.
Related Linux Commands
Search for matching string patterns or regular expressions inside text files.
List directory contents including file sizes, permissions, ownership, and modification timestamps.
Concatenate and print file contents directly to the terminal standard output.
Change file access permission mode bits for owner, group, and other users.
Create new directories and folder hierarchies.
Remove files or directories from the filesystem.