How to Find a File in Linux: Commands, Options, and What Works When

Finding a file in Linux sounds simple — until you're staring at a terminal with no idea where to start. Linux gives you several powerful tools to locate files, and each one works differently depending on what you know about the file, where it might be, and how quickly you need the answer.

The Main Tools for Finding Files in Linux

Linux doesn't have one universal file search command. Instead, it offers a set of purpose-built utilities, each suited to a different situation.

find — The Most Flexible Option

The find command searches your filesystem in real time. It's thorough, highly configurable, and works without any pre-built index. The basic syntax looks like this:

find /path/to/search -name "filename.txt" 

To search your entire system from root:

find / -name "filename.txt" 

To make the search case-insensitive, swap -name for -iname:

find / -iname "filename.txt" 

find can also search by file type, size, modification date, permissions, and more:

find /home -name "*.log" -mtime -7 

This finds all .log files in /home modified within the last 7 days. The flexibility is find's biggest strength — and its learning curve.

locate — Fast Search Using a Database

The locate command searches a pre-built index of your filesystem rather than scanning directories in real time. This makes it significantly faster for simple lookups:

locate filename.txt 

The trade-off: locate depends on a database that's typically updated once a day via a scheduled job called updatedb. If you created a file recently, locate may not know about it yet. You can manually refresh the database with:

sudo updatedb 

locate is best when you need a quick answer and the file isn't brand new.

which and whereis — For Finding Programs and Commands

If you're looking for an executable or command rather than a regular file, which tells you where a program lives in your PATH:

which python3 

whereis goes further, returning the binary, source files, and manual pages associated with a command:

whereis grep 

Neither of these is designed for general file searching — they're specifically for locating installed programs and system binaries.

fd — A Modern Alternative

fd is a third-party command-line tool that offers a faster, more user-friendly syntax than find. It ignores hidden files and directories by default, respects .gitignore rules, and uses color-coded output. It isn't installed by default on most Linux distributions, but it's widely available in package managers.

fd filename 

For users who work with codebases or frequently search large directory trees, fd can be noticeably more ergonomic.

Comparing the Core File Search Tools 🔍

ToolSpeedReal-Time?Best For
findSlower on large trees✅ YesPrecise, filtered searches
locateVery fast❌ Depends on indexQuick lookups of existing files
whichInstant✅ YesFinding executable locations
whereisInstant✅ YesLocating binaries + docs
fdFast✅ YesDeveloper-friendly file search

Narrowing Your Search: Useful find Filters

Because find is the most commonly used tool for general-purpose file searching, it's worth knowing its most practical filters:

By file type:

find /home -type f # files only find /home -type d # directories only 

By size:

find / -size +100M # files larger than 100MB 

By owner:

find /var -user www-data 

By permissions:

find / -perm 644 

You can also combine find with other commands using -exec to act on results directly — for example, deleting, moving, or inspecting files as they're found.

Searching Inside Files vs. Searching for Files

It's worth drawing a clear line here: find and locate search for files by name or attribute. If you need to search inside files for a specific word or pattern, that's a job for grep:

grep -r "search term" /path/to/directory 

The -r flag makes it recursive. grep is often used together with find — for example, finding all .conf files that contain a specific setting.

Variables That Affect Which Tool You Should Use

The right command depends on factors specific to your situation:

  • How recently was the file created? If it's brand new, locate won't find it without a database update. find will.
  • Do you know part of the filename or just the extension? Wildcards work in both find and locate, but find gives more control.
  • How large is the filesystem you're searching? On very large systems, find without filters can be slow. locate stays fast regardless.
  • Are you on a shared or restricted system? Some environments disable locate or restrict find access to certain directories.
  • Are you searching for a command or a data file? That distinction changes which tool is appropriate entirely. 🖥️
  • Is fd available on your system? It's not standard, so scripts meant to be portable should rely on find.

No single command is universally superior. A system administrator managing a production server, a developer working through a code repository, and someone trying to find a document in their home folder are all solving meaningfully different versions of the same problem — and may reach for different tools to do it.

What the right approach looks like for you depends on what you know about the file, what's installed on your system, and how often you'll need to run searches like this. 📁