The fastest way to find a file in Linux
The find command is the standard tool for locating files in Linux. It searches through directories and subdirectories for files matching the criteria you give it. Unlike searching through a file manager by clicking folders, find works from the command line and can search your entire system in seconds.
The basic structure is simple: type find, tell it where to start looking, then tell it what to search for. For example, find /home -name "document.txt" searches your home directory and all folders inside it for a file called document.txt. The forward slash at the start of a path means "start here and look in all subdirectories too."
Key Takeaways
- The find command searches your entire system or just one folder, depending on where you tell it to start.
- Use -name to search by filename, -type f for files only (not folders), and -type d for folders only.
- Wildcards like *.txt find all files ending in .txt without typing the exact name.
- The locate command is faster for files you have searched for before, because it uses a database instead of scanning the whole system.
- If a search returns "Permission denied," you do not have access to that folder, and running the command with sudo will not change that.
Using find with the -name option to search by filename
The -name option tells find to look for files with a specific name. Type the command exactly as it appears, with the path first, then -name, then the filename in quotes if it contains spaces.
find /home -name "myfile.txt" searches your home directory for a file called myfile.txt. If you want to search your entire system instead, replace /home with a single forward slash: find / -name "myfile.txt". Searching the whole system takes longer because it checks every directory, including system folders.
If you do not remember the exact filename, use a wildcard. find /home -name "*.pdf" finds all PDF files. find /home -name "*report*" finds any file with "report" anywhere in the name. The asterisk means "match anything here."
Narrowing your search to files or folders only
By default, find returns both files and folders. If you want only files, add -type f. If you want only folders, add -type d. You can combine this with -name to be more specific.
find /home -type f -name "*.txt" finds only text files, not folders named something.txt. find /home -type d -name "Documents" finds only folders called Documents, not files with that name. The order of the options does not matter — find understands them either way.
Searching by file size or modification date
Sometimes you remember roughly when you created a file or how large it is, but not the name. The find command can search by these details too.
Use -size to search by file size. find /home -type f -size +10M finds files larger than 10 megabytes. The plus sign means "larger than." Use a minus sign for smaller: find /home -type f -size -1M finds files smaller than 1 megabyte. You can use k for kilobytes, M for megabytes, or G for gigabytes.
Use -mtime to search by how recently a file was changed. find /home -type f -mtime -7 finds files modified in the last 7 days. find /home -type f -mtime +30 finds files not modified in the last 30 days. The plus and minus signs work the same way as with size.
Using locate for faster searches of files you have found before
The locate command is faster than find because it searches a database of filenames instead of scanning your entire system. However, the database only includes files that existed the last time it was updated, which is usually once a day.
Type locate filename.txt to search for a file. You do not need to specify a path or use quotes unless the filename contains spaces. locate *.pdf finds all PDF files in the database. If locate returns no results but you know the file exists, it may not be in the database yet. Run sudo updatedb to update the database manually, then try locate again.
locate is useful when you are searching for files you have already found before or when you want results instantly. find is better when you need to search by size, date, or other details, or when you need to find very recent files that may not be in the locate database yet.
Understanding common error messages
If you see "Permission denied" in your results, it means find encountered a folder you do not have permission to read. This is normal and does not mean the file is not there — it just means you cannot see inside that folder. Running the command with sudo does not change this; the permission rules stay the same.
If find returns no results, the file may not exist, or it may be in a folder you do not have permission to search. Try searching a smaller area first, like just your home directory, to narrow down the problem. If you are searching for a very new file and using locate, remember that the database may not include it yet.
Frequently Asked Questions
Can I search for a file by part of its name if I do not remember the whole thing?
Yes. Use wildcards with -name. find /home -name "*part*" finds any file with "part" anywhere in the name. find /home -name "report*" finds files starting with "report." You can put the asterisk at the beginning, end, or both sides of the text you remember.
How do I search my entire system instead of just one folder?
Start the path with a single forward slash instead of a folder name. find / -name "filename" searches from the root of your system. This takes longer than searching a single folder because it checks every directory. If you only need to search your home directory, use /home or ~ instead.
What is the difference between find and locate?
find scans your system in real time and can search by name, size, date, and other details. locate searches a pre-built database and is much faster, but only knows about files that existed when the database was last updated. Use locate for quick searches of older files, and find when you need to search by details other than name or when you need to find very recent files.
Why does find show "Permission denied" for some folders?
Your user account does not have permission to read those folders. This is a security feature and is normal. The file you are looking for may still exist in that folder, but find cannot see inside to check. You cannot override this with sudo unless you are searching as the root user, which is not recommended for routine file searches.
Can I search for files by the person who created them?
Yes, with the -user option. find /home -type f -user username finds all files owned by a specific user. find /home -type f -user root finds files owned by the root user. You can combine this with other options like -name or -mtime to narrow the search further.