Difference between locate, which and find Command in Linux
Last Updated :
12 Jul, 2025
In Linux, there are multiple utilities available to locate files efficiently within a system. Three of the most commonly used commands for this purpose are:
Each command serves a similar function but differs in the way they search and the data they return. In this article, we'll explore the differences between these commands, how they work, and examples of their usage.
Locate Command
cate is a Unix utility which serves to find files on filesystems. It searches through a prebuilt local database of all files on the filesystem generated by the updatedb command. Note it is essential to update the database as recent files saved over a period of fewer than 24 hours are not updated into the database by default and the database is updated once within 24 hour span.
Syntax
locate [OPTION]... PATTERN...
Example:
Let us create a file on desktop named findme.txt. Using locate command without updating the database returns no output however after updating the local database of all files on the filesystem, we are finally able to locate the file.
1. Creating a new file findme
echo "findme" >> findme

2. Using locate before updating the database:

3. Unable to find the file. The local database of all files on the filesystem is updated.

4. Trying locate command again locate findme

5. File location shown.
Hence it is essential to update the database prior to using the locate command.
Which Command
The whichcommand searches through the directories that are defined in the $PATH environment variable for a given filename. If a match is found, which returns the full path to the executable file
Syntax
which [-a] filename ...
Example:
which aircrack-ng
Returns the path to the aircrack-ng executable file.
Key Points:
- which is used to determine the location of executable programs.
- It searches through directories listed in the $PATH variable.

Find Command
The find command is a more aggressive search tool than locate or which. Find is able to recursively search any given path for various files. Using the file command we can search for files by name, owner, group, permissions, type, size, time modified, date and various other criteria. The find command is highly efficient but this efficiency comes at a cost of time.
Syntax
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression]
The -H, -L and -P options control the treatment of symbolic links. The options -H -L -P -D -O must appear before the first pathname if needed. The part of the command line after the list of starting points is the expression. This is a kind of query specification describing how we match files and what we do with the files that were matched.
Entering file or file. will display the pathnames of all files in the current directory and all subdirectories. The default directory is current directory and default expression is -print.
. represents current directory
/ represents root directory
- Searching a file by its name
# find / -name findme

- Searching a text file only
# find / -name "*.txt"

- Searching a file ignoring case.
# find / -iname fIndMe

# find / -type f -name findme

- Searching for directories only.
# find / -type d -name find

- Searching for file based on permission.
# find / -type f -perm 0777 -print

- Changing permission of a file.
# find / -type f -perm 0777 -exec chmod 755 {} \;

- Files modified more than 10 days.
# find / -mtime 10
- Files modified less than 10 days.
# find / -mtime -10

- Files modified more than 1 minute.
# find / -mmin 1

- Files modified less than 1 minutes.
# find / -mmin -1

- Files with size more than 10MB.
# find / -size 10M

- Search for empty files and directories
# find / -empty

Conclusion
The locate and find commands each have their own strengths and weaknesses for finding files in a Linux system. The locate command is faster because it searches a pre-built database rather than the live filesystem, but it may not include newly added files until the database is updated.
Additionally, locate doesn't index every part of the filesystem, excluding certain paths, mounts, and file types as defined in /etc/updatedb.conf. On the other hand, find offers more accuracy by searching the filesystem live, providing up-to-the-moment results. Although find is slower, it allows greater flexibility with attribute-based searches and can be limited to specific directories to improve speed.