Online Linux Terminal Logo
OnlineLinuxTerminal
File OperationsCLI Reference

$find

Search for files and directories in a directory hierarchy based on name, type, size, or modification date.

Syntax DefinitionPOSIX standard
find [PATH] [OPTIONS] [EXPRESSION]
Linux Community2.4k Online

Chat with real Linux users, learn new commands & get free cheat sheet PDFs.

Try `find` Live in Interactive Sandbox

Zero-install client simulation with real-time feedback.

Open in Fullscreen Workspace↗
bash — terminal

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 / OptionDescription
-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

Example #1Find files by exact name or extension
find /var/log -name "*.log"

Recursively scans the /var/log directory for all files ending with the .log extension.

Sample Output:
/var/log/syslog /var/log/auth.log /var/log/nginx/access.log
Example #2Find all directories in the home folder
find /home/user -type d

Filters and outputs only directory paths inside the user home folder.

Sample Output:
/home/user /home/user/projects /home/user/docs
Example #3Find files modified in the last 24 hours
find . -type f -mtime -1

Locates recently created or modified files in the current working directory.

Sample Output:
./welcome.txt ./notes.txt

Common Errors & Troubleshooting

find: Paths must precede expression
Cause: Options were specified before the target search path.
Solution: Always place the directory path immediately after the find command (e.g., `find /path -name "test"`).
find: Permission denied
Cause: Attempting to search system directories without superuser privileges.
Solution: Use `sudo find /root -name "*.conf"` or redirect stderr using `2>/dev/null`.

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.