locate vs. find vs. whereis: Linux Search Commands Compared

locate vs. find vs. whereis: Linux Search Commands Compared

Linux offers more than one way to find what you’re looking for, including commands like locate, find, and whereis. Knowing when and which command to use can save you time and frustration. Let’s dive into each one and see which performs better in different situations.

Related

How to Use All Linux’s Search Commands

Learn which of the six different Linux search tools you should use, and why.

The locate Command

The locate command is designed to find files and directories based on their names, or parts of their names—almost instantly. It’s incredibly fast because it doesn’t actually search your file system in real time. Instead, it queries a pre-built database, commonly named mlocate.db, plocate.db, or simply locate.db, depending on your distribution.

This database isn’t updated in real time. If you’ve just created or deleted a file, locate might not know about it until the next database update. The database is refreshed regularly by a system process, typically via a cron job that runs daily. You can also manually update the database using “sudo updatedb”, although indexing the entire file system can take some time.

The basic syntax is refreshingly simple:

locate -i filename 
Locating the file using its name with locate command in Ubuntu terminal.

If the file exists and the database is up-to-date, locate will list all paths containing “my_script.sh”. The -i option makes your search case-insensitive.

You can also search for all files with a specific extension, count matches using the -c option, or limit the output with the -n option. The locate command supports wildcard pattern matching and even basic regular expressions, offering more control over your searches.

locate vs. mlocate vs. plocate

Over time, the original locate utility was replaced in most distributions by mlocate, which introduced important improvements—such as respecting user permissions, so you only see files you’re allowed to access.

When mlocate is installed, it provides the locate command itself. So even if you’re typing locate, you’re actually running mlocate in the background. You can confirm this by checking the version:

locate --version
Checking the version of locate command line tool on Ubuntu terminal.

This will show which locate version is handling your searches.

More recently, a newer implementation called plocate has started replacing mlocate in some distributions. plocate is faster and more efficient, using a compressed index to reduce search time and disk usage—especially helpful on systems with a large number of files. Fedora, for example, now uses plocate by default, and many other distributions are beginning to follow.

You can also install plocate using your default package manager like on Ubuntu, run:

sudo apt install plocate
Installing plocate command line tool in Ubuntu using APT manager.

Again, even when plocate is installed, the command you type remains locate, so nothing changes in how you use it. For most users, the functionality and syntax are the same. However, a few advanced options may differ slightly between mlocate and plocate.

Related

How to Find Files and Folders in Linux Using the Command Line

Most people use a graphical file manager to find files in Linux, such as Nautilus in Gnome, Dolphin in KDE, and Thunar in Xfce.

The find Command

Unlike the locate command, the find command searches for files and directories in real time by directly traversing your specified directory hierarchy. It doesn’t rely on a database, which means it always returns the most up-to-date information. However, this also means it can be slower than locate, especially when searching for large file systems.

Related

How to Use the find Command in Linux

Use find with xargs and exec to take your Linux file searches to the next level.

What makes find stand out is its ability to search based on a wide range of criteria—not just name, but also type, size, permissions, ownership, modification time, and much more. As if that weren’t enough, find can also execute arbitrary commands (like rm, cp, or chmod) on the files it finds using the -exec option.

Here is the basic syntax:

find [path] [options] [expression]
  • path: Where to start the search (use . for the current directory)
  • options & expression: What to look for and how to filter the results

For example, to find a file named config.xml within your home directory and its sub-directories, run:

find /home/your_username -name "config.xml"

Similar to locate, find can perform case-insensitive searches using the -iname (insensitive name) option:

find /var/log -iname "error*.log"
Finding error specific files using find command

This would find files like error.log, Error.Log, and ERROR-messages.log within /var/log.

Related

How to Recursively Search Directory Names in Linux

Everything in Linux is stored in directories, and when writing bash scripts, it’s often useful to search for directories by name.

You can also search for specific types of files. For example, to find all directories (d) in the current path, use:

find . -type d

Or you can find files larger than any size, like 100 MB (+100M) in your /opt directory with:

find /opt -size +100M
Finding files based on the specified size using find command.

Further, you can search for empty files, empty directories, or items based on their specific modification times. You can also run other commands on each file found using find, such as, deleting all .tmp files with this:

find . -name "*.tmp" -exec rm {} \;

The whereis Command

The whereis command is quite different from locate and find. While the first two are general-purpose file search tools, whereis has a very specific mission: to locate the binary (executables), source files, and manual pages for a given command.

It’s particularly useful when you’re trying to understand how a command is installed on your system or when you’re troubleshooting issues with program execution.

Related

These 4 Linux Commands Show You the Path of an Executable File

Learn how to find executable paths in Linux using which, whereis, type -a, and command -v commands with clear examples and syntax.

Unlike locate and find, whereis searches only in a predefined set of directories where these types of files are typically stored—places like /bin, /usr/bin, and /usr/local/bin for binaries; /usr/share/man for manual pages; and various source code directories.

For example, if you want to find the ls binary, its source code (if available), and its man pages, you can run:

whereis ls
Finding executables path using the whereis command

This will tell you the ls binary is located at “/bin/ls” and its man page is at “/usr/share/man/man1/ls.1.gz.”

If you only care about the executable path, use the -b (binary) option:

whereis -b ls

To find just the manual pages, use the -m (man) option:

whereis -m bash

You can also ask whereis about multiple commands at once:

whereis grep sed awk
Finding executables path of multiple commands using whereis utility.

Often, source files aren’t installed by default. In such cases, the output may include only the command name if no source is found in the standard locations.

When to Use Each Command

You can use the locate command when you want a fast, system-wide overview of where specific files with a certain name exist. Also, it works best when you’re reasonably sure the file isn’t brand new, or you’ve recently refreshed the database.

On the other hand, the find command is more suitable when you need to search based on criteria other than just the name, such as file size, type, permissions, or modification date. It’s especially useful when you want to search a specific directory tree deeply, or when the file you’re looking for might be new and not yet included in the locate database. find also shines when you need real-time results or want to perform actions like deleting, copying, or changing permissions on the files you find.

The whereis command comes in handy when you specifically need to locate a command’s executable binary, source files, or manual pages. It’s particularly useful when you’re troubleshooting issues with your system’s PATH or trying to understand where and how a program is installed.


Sometimes, your needs may overlap among all three commands. For example, if locate returns too many results, you can use its output to narrow down a starting path for a more precise find search. These commands aren’t mutually exclusive—they work best when used together as part of your Linux toolkit.

Leave a Reply

Your email address will not be published. Required fields are marked *