The fastest way to find a file in Linux
The find command is the most direct way to search for files in Linux. Open your terminal and type find /path/to/search -name "filename", replacing the path with where you want to search and filename with what you're looking for. The command searches that location and every folder inside it, then prints the full path to any matches it finds.
If you're searching your entire home directory and don't know the exact name, use a wildcard: find ~ -name "*part-of-name*". The tilde (~) means your home folder. This finds any file with that text anywhere in its name. For a system-wide search, replace ~ with / — but be aware this takes longer because it searches every directory on your machine.
By default, find is case-sensitive, so searching for "Document" won't find "document". To ignore case, add the -iname flag instead: find ~ -iname "*document*".
Key Takeaways
- The find command searches a folder and everything inside it, so start with a specific location like your home directory (~) rather than the entire system unless you need to.
- Use wildcards (*) around partial filenames to find files when you don't remember the exact name.
- Add the -iname flag instead of -name to search without worrying about uppercase or lowercase letters.
- The locate command is faster for repeated searches because it uses a pre-built database, but it only works if the database was updated recently.
- Combine find with other flags like -type f (files only) or -type d (directories only) to narrow results when you get too many matches.
Using locate for faster repeated searches
If you search for the same files often, the locate command is much faster than find. Type locate filename and it searches a pre-built database instead of scanning your actual folders. Results appear instantly.
The catch: the database only updates once a day on most systems, so newly created files won't show up until tomorrow. To update it manually, run sudo updatedb — this takes a minute or two depending on how many files you have. After that, locate will find the new files immediately.
Locate also searches your entire system by default and is case-insensitive, so locate document finds Document, DOCUMENT, and document all at once. If you get too many results, pipe the output to grep to filter: locate document | grep Desktop shows only matches with "Desktop" in the path.
Narrowing results when you get too many matches
When find returns hundreds of results, add flags to show only what you need. Use -type f for files only or -type d for directories only. For example, find ~ -name "*report*" -type f finds only files named report, not folders.
You can also search by file size or modification date. To find files larger than 100 megabytes, use find ~ -size +100M. To find files changed in the last 7 days, use find ~ -mtime -7. Combine multiple flags to narrow further: find ~ -name "*.log" -type f -mtime -7 finds log files modified in the last week.
If the output is still long, pipe it to less to scroll through results one screen at a time: find ~ -name "*document*" | less. Press the spacebar to move down, and type q to quit.
Searching by file type and extension
When you remember the file type but not the name, search by extension. To find all PDF files in your Documents folder, use find ~/Documents -name "*.pdf". The asterisk matches any characters before the .pdf ending.
Common extensions to search for include .txt (text files), .jpg or .png (images), .mp3 or .wav (audio), .mp4 or .mkv (video), and .zip (archives). You can search for multiple extensions at once by using the -o flag (meaning "or"): find ~ -name "*.jpg" -o -name "*.png" finds both image types.
If you're looking for files without an extension, use find ~ -type f ! -name "*.*". The ! means "not", so this finds files that don't contain a dot in their name.
Searching inside file contents, not just names
Sometimes you remember text from inside a file but not the filename. The grep command searches the contents of files. Type grep -r "search term" /path/to/search to search every file in a folder for that text. The -r flag means "recursive", so it searches subfolders too.
For example, grep -r "invoice number" ~/Documents finds every file in Documents that contains the phrase "invoice number". By default, grep shows the filename and the matching line. To see only filenames, add the -l flag: grep -r -l "invoice number" ~/Documents.
Grep is case-sensitive by default. To ignore case, add the -i flag: grep -r -i "invoice" ~/Documents finds "invoice", "Invoice", and "INVOICE". This is slower than find because it actually reads file contents, so it works best when you're searching a specific folder, not your entire system.
Using the GUI file manager as an alternative
If you prefer not to use the terminal, most Linux desktop environments include a file manager with a built-in search. Open your file manager (usually called Files, Nautilus, or Dolphin depending on your desktop), click the search icon or press Ctrl+F, and type the filename. The search runs in the current folder and subfolders.
GUI search is slower than the command line for large searches, but it's easier if you're not comfortable with terminal commands. You can usually filter results by file type, size, or date modified using buttons or dropdown menus in the search window. Some file managers also let you save searches so you can run them again later without retyping.
The downside is that GUI search varies between desktop environments, so the exact steps depend on which one you're using. If you use the terminal regularly, learning find and locate saves time in the long run.
Frequently Asked Questions
Why does find take so long when I search from the root directory?
Searching from / (the root) means find looks through every folder on your system, including system directories, mounted drives, and sometimes network locations. This can take several minutes. Start with a specific folder like ~ or ~/Documents instead. If you must search the whole system, add -type f to skip directories, which speeds things up slightly.
How do I find a file if I only remember part of the name?
Use wildcards with find: find ~ -name "*part-you-remember*". The asterisks match any characters before and after your search term. If you remember the extension but not the name, search by extension: find ~ -name "*.pdf". If you remember text inside the file, use grep instead of find.
Can I search for files by owner or permissions?
Yes. Use find ~ -user username to find files owned by a specific user, or find ~ -perm 644 to find files with specific permissions. These are advanced options, but they're useful if you're managing multiple user accounts or looking for files with security issues. Check the find manual page (type man find) for the full list of permission codes.
What's the difference between find and locate?
Find searches your actual files in real time, so it always finds newly created files but takes longer. Locate searches a pre-built database, so it's instant but only finds files that existed when the database last updated. Use locate for quick repeated searches and find when you need current results or want to filter by size, date, or permissions.
How do I search for files with spaces in the name?
Spaces in filenames work fine with find and locate — just put the filename in quotes: find ~ -name "my document.txt" or locate "my document.txt". Without quotes, the command might interpret the space as a separator between arguments and fail. Quotes are always safe to use, even for filenames without spaces.