πŸ” Linux/Unix: Searching, Text Processing & Regex
Estimated reading: 3 minutes 273 views

Linux/Unix: File Location – find, locate, which, whereis Explained with Examples

Introduction – Why Learn File Location Commands in Linux/Unix?

On a Linux/Unix system, locating files quickly is essential for system administration, scripting, troubleshooting, and software development. Tools like find, locate, which, and whereis let you search files by name, type, location, and moreβ€”saving time and boosting productivity.

In this guide, you’ll learn:

  • How to use find for detailed and recursive searches
  • How to use locate for fast lookups via indexing
  • How which and whereis help identify command paths and binaries
  • Practical examples and output explanations

find – Locate Files in Real-Time

Syntax:

find [path] [options] [expression]

Description:

Searches directories recursively based on name, type, size, permissions, etc.

Examples:

find /home -name "*.txt"           # Find all .txt files under /home
find . -type f -size +1M           # Files larger than 1MB
find /etc -perm 644                # Files with specific permissions
find / -name "config.php" 2>/dev/null  # Suppress permission errors

Real-time search, very accurate but slower for large file systems.


locate – Fast File Lookup Using Index

Syntax:

locate filename

Description:

Searches from an indexed database (/var/lib/mlocate/mlocate.db) for fast results.

Example:

locate passwd

Much faster than find, but results may be outdated unless the database is updated.

Update Database:

sudo updatedb

which – Show Executable Path in $PATH

Syntax:

which command

Description:

Displays the full path of a command or executable from the PATH variable.

Example:

which python

Returns something like:

/usr/bin/python

Helpful in scripts to verify whether a command is available.


whereis – Locate Binary, Source, and Manual

Syntax:

whereis command

Description:

Locates the binary, source code, and man page locations for a command.

Example:

whereis ls

Output:

ls: /bin/ls /usr/share/man/man1/ls.1.gz

Useful for system auditing and documentation lookup.


Comparison Table

CommandPurposeSpeedUses Indexed DBSearches
findReal-time file searchSlower NoBy name, size, type, perms
locateFast indexed file lookupFast YesBy name only
whichPath of command in $PATHFast Yes (PATH)Executables only
whereisPath to binary, source, and manFast YesCommands/binaries

Summary – Recap & Next Steps

Locating files efficiently is key to system management. Whether you need to find a config file, check if a command exists, or inspect a manual pathβ€”find, locate, which, and whereis offer precise tools for the task.

Key Takeaways:

  • find = real-time recursive search with filters.
  • locate = lightning-fast indexed search.
  • which = path to executable in current $PATH.
  • whereis = binary, source, and man page locations.

FAQs

When should I use find vs locate?
Use find when you need real-time and filtered results. Use locate for quick file name lookups.

How do I update locate results?
Run:

sudo updatedb

How do I find files owned by a specific user?
Use:

find / -user username

What’s the difference between which and whereis?
which shows the command’s location in $PATH. whereis shows binary + source + man pages.

Can I search by file size using find?
Yes:

find . -size +10M

Finds files larger than 10 MB.


Share Now :
Share

πŸ”΅ Linux/Unix: File Location (find, locate, which, whereis)

Or Copy Link

CONTENTS
Scroll to Top