The fastest way to find a file in Linux

The find command is the most direct route. Open a terminal, type find /home -name "filename", and Linux searches that directory and all folders inside it for an exact match. If you do not know the exact name, use a wildcard: find /home -name "*.txt" finds all text files. The search runs in the background and prints results to your terminal as it finds them.

For speed, locate works faster because it searches a pre-built database instead of scanning the disk each time. Type locate filename and get results instantly. The trade-off is that the database updates once a day by default, so newly created files may not show up until the next update. Run updatedb manually to refresh it immediately.

If you want to search by file type, size, or modification date instead of name, find handles that too. The command grows more complex, but the basic structure stays the same: find /path -type f -size +10M finds all regular files larger than 10 megabytes in that path.

Key Takeaways

  • The find command searches your disk in real time and works with partial names using wildcards like *.txt.
  • The locate command returns results instantly but searches a database that updates once daily, so new files may not appear right away.
  • Both commands need a starting directory — /home for user files, / to search the entire system, or a specific folder path.
  • You can narrow searches by file type, size, or how recently it was modified by adding options to the find command.

Using find with wildcards and partial names

The find command accepts patterns, not just exact filenames. A single asterisk * matches any number of characters. Type find /home -name "*report*" to find any file with "report" anywhere in its name — "report.txt", "monthly_report.pdf", "reports_2024" all match. A question mark ? matches exactly one character, so find /home -name "file?.txt" finds "file1.txt" and "fileA.txt" but not "file12.txt".

By default, find is case-sensitive: "Report.txt" and "report.txt" are different. Use the -iname option instead of -name to ignore case: find /home -iname "report.txt" finds both versions.

Searching by file type, size, and date

The find command can filter results beyond the filename. Use -type f for regular files, -type d for directories, and -type l for symbolic links. Combine it with other options: find /home -type f -name "*.log" finds only files (not directories) named with the .log extension.

For size, -size takes a number followed by a unit. find /home -type f -size +100M finds files larger than 100 megabytes. Use - for smaller than, + for larger than, and no sign for exactly that size. Units are c for bytes, k for kilobytes, M for megabytes, and G for gigabytes.

To find files by modification date, use -mtime. The number represents days: find /home -type f -mtime -7 finds files changed in the last 7 days. Use -mtime +30 to find files not touched in more than 30 days. For more precise control down to the minute, use -mmin instead.

When to use locate instead of find

The locate command is faster for simple name searches because it queries a database instead of scanning the disk. On a system with millions of files, locate report.txt returns results in milliseconds, while find / -name "report.txt" may take several seconds or longer.

The database updates automatically once per day, usually at night. If you just created a file and need to find it immediately, locate will not see it yet. Run sudo updatedb to refresh the database manually. After that, locate will find the new file.

locate also searches the entire system by default, so you do not need to specify a starting path. Type locate filename and it searches everywhere. This makes it simpler for quick lookups, but you cannot filter by size, type, or date the way find does.

Combining search options for precise results

You can chain multiple conditions together in a single find command. Each condition narrows the results further. For example, find /home -type f -name "*.pdf" -size +5M -mtime -30 finds PDF files larger than 5 megabytes that were modified in the last 30 days. Linux evaluates all conditions and returns only files that match every one.

Use -o to search for files matching any of several conditions instead of all of them. The command find /home -name "*.txt" -o -name "*.md" finds both text files and markdown files. Without -o, the command would look for files with both extensions at once, which is impossible.

You can also pipe find results to other commands. Type find /home -type f -name "*.log" | wc -l to count how many log files exist, or find /home -type f -mtime +365 | xargs rm to delete files older than a year (use this carefully).

Searching in specific directories

Both find and locate let you narrow the search area. With find, specify the starting directory as the first argument: find /home/username/Documents -name "*.pdf" searches only that folder and its subfolders. Use . to search the current directory: find . -name "report.txt".

locate searches the entire system by default and does not accept a directory argument. Instead, pipe the results to grep to filter by path: locate report.txt | grep Documents shows only matches inside a Documents folder. This is less precise than find but still faster for a quick check.

If you have permission issues, find may skip directories you cannot read. Run find with sudo to search system directories: sudo find /etc -name "config.txt". Be cautious with sudo — it grants full access and can modify or delete files if you chain commands incorrectly.

Frequently Asked Questions

Why does find take so long on a large system?

find scans the disk in real time, checking every file and folder. On systems with millions of files or slow storage, this can take minutes. If you search the entire system with find /, it checks every directory including system folders. Start with a specific directory like /home instead, or use locate for faster results.

Can I search for files by owner or permissions?

Yes. Use -user username to find files owned by a specific person, or -perm 644 to find files with exact permissions. The command find /home -type f -user john finds all regular files owned by the user john. Permissions use octal notation, so this requires some familiarity with Linux file permissions.

What does the error "Permission denied" mean when I use find?

find prints this when it encounters a directory you cannot read. It continues searching other directories and still returns results from places you can access. To suppress these messages, redirect errors to nowhere: find /home -name "file.txt" 2>/dev/null. The 2>/dev/null part hides error messages but does not change what files are found.

How do I find files that were deleted recently?

find cannot recover deleted files — it only searches files that still exist. If you need to recover a deleted file, you need a recovery tool like testdisk or photorec, which scan the disk for data that was not yet overwritten. These tools are separate from find and require different steps.

Can I search for files by content instead of filename?

No, but you can combine find with grep to search file contents. The command find /home -type f -name "*.txt" | xargs grep "search term" finds all text files, then searches inside each one for your term. This is slower than searching by name because it reads every file, so use it only when you need to search inside files.