Operations 6 min read

Master Linux File Search: find, locate, which, and whereis Explained

This guide introduces the essential Linux file‑search utilities—find, locate, which, and whereis—explaining their core syntax, speed trade‑offs, database dependencies, and useful options so you can quickly locate scripts, executables, source files, and manuals on any system.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux File Search: find, locate, which, and whereis Explained

find

The classic find command can recursively search directories. A simple example to locate all shell scripts in the current directory and its sub‑directories is: find . -name "*.sh" This command walks the file tree and prints matching paths.

locate

locate

searches a pre‑built index file ( /var/lib/mlocate/mlocate.db) that contains paths for every file on the system. The database is refreshed each morning by a cron job, making locate much faster than find because it does not scan the filesystem in real time.

Example output shows absolute paths of matching files. However, newly created files are invisible until the database is updated. To refresh the index manually, run: sudo updatedb After updating, locate can find the new files.

which

The which command looks for executable files in the directories listed in the $PATH (and optionally $MANPATH) environment variables. By default it returns the first match: which ls Use the -a option to list all locations where the executable exists, and you can query multiple commands at once, e.g., which gcc make.

whereis

whereis

searches standard system directories (e.g., /bin, /sbin, /usr/bin, /usr/lib, /usr/local/man) for binary files, source files, and manual pages related to a given name.

Typical options include: -b – search only for binaries -B <em>path</em> – specify additional search directories -f – display file information -s – limit search to source files -m – limit search to man pages -M – specify a custom source‑path search

For example, to find the binary location of ls only, run: whereis -b ls The command will output the path(s) to the executable, its source (if available), and its manual page.

These four utilities together cover most everyday file‑search needs on Linux, from exhaustive directory walks ( find) to instant lookups in an index ( locate), and from locating executables ( which) to retrieving binaries, sources, and manuals ( whereis).

command-linefindlocatewhereiswhichfile-search
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.