Finding files in Linux can be tricky, especially when you need to search through thousands of files across multiple directories. However, this is achievable, using the Linux find command. It lets you search for files in Linux recursively by full name, partial name, or pattern.
Many users waste time manually browsing folders. With the right Linux find command syntax, you can locate anything fast. This guide shows how to use the Linux find command to search files recursively by exact name, extension, regex, and more. You’ll also learn how to combine find with grep for finding which of the files contain a certain string.
ℹ️ The find command in Linux is recursive by default. It searches through all subdirectories, unless you explicitly tell it not to, using the he -maxdepth option.
1. Find file by exact name
Search for a file named “notes.txt” in the current directory:
$ find . -type f -name "notes.txt"
ℹ️ The dot ( . ) represents the current directory in the Linux filesystems.
2. Find file by partial name
Find any file with “error” in its name under /var/log:
$ find /var/log -type f -name "*error*"
3. Find file by extension
List all configuration files ending with “.conf”:
$ find /etc -type f -name "*.conf"
4. Find file using regex
Find all files with a 4-digit number and “.log” extension, under /tmp:
$ find /tmp -regextype posix-extended -regex ".*[0-9]{4}\.log"
More information about posix-extended regular expression syntax can be found here.
5. Find hidden files
Recursively show all hidden files under /home/user:
$ find /home/user -type f -name ".*"
ℹ️ In Linux, hidden files are those whose names begin with a dot ( . ).
6. Find file and search contents
Search for the word “timeout” find inside all “.conf” files:
$ find /etc -type f -name "*.conf" -exec grep "timeout" {} \;
7. Find file and show size
Display “.mp4” files with their sizes in human-readable format:
$ find /videos -type f -name "*.mp4" -exec ls -lh {} \;
Related Articles
Conclusion
The find command is a reliable way to find files by name in Linux. Whether you’re using search the files by name or with regex, these examples cover the basics. For more advanced searches, combine the Linux find command with grep or other tools to save time and reduce frustration.