Master Linux File Search: Find, Locate, Whereis, Which, and Type Explained
This guide explains how to use Linux's primary file‑search utilities—find, locate, whereis, which, and type—detailing their syntax, options, and practical examples, while highlighting differences such as database reliance, PATH searching, and builtin versus external command identification.
find
find is the most commonly used and powerful search command in Linux, capable of locating any file that matches specified criteria.
Basic syntax: find <directory> <expression> <action> If no arguments are given, it searches the current directory and all sub‑directories and returns every file.
Examples: find /home -name 'a*' – list all files in /home whose names start with “a”. find /home -name 'a*' -ls – same as above but also display detailed information. find /home -type f -mmin -10 – show regular files in /home that were modified in the last 10 minutes. Omitting -type f would also match directories and special files.
locate
locate works like find -name but is much faster because it searches a pre‑built database (/var/lib/locatedb) that contains information about all files on the system.
The database is updated automatically once a day; therefore newly created or moved files may not be found until updatedb is run manually.
Examples: locate /etc/sh – find all files under /etc whose names start with “sh”. locate ~/m – find all files in the home directory whose names start with “m”. locate -i ~/m – same as above but case‑insensitive.
whereis
whereis is essentially a shortcut for find -name that only searches for program files. It can return the binary ( -b), manual page ( -m), and source code ( -s) locations. If no option is given, all available information is shown.
Example: whereis grep – display the locations of the grep binary, its man page, and source files.
which
which searches the directories listed in the PATH environment variable and returns the first matching executable. It is useful for confirming whether a command exists and where it will be executed from.
Example: which grep – show the full path of the grep executable that will be run.
type
type tells whether a command is a shell builtin or an external executable. With the -p option it behaves like which, printing the path of an external command.
Examples: type cd – outputs “cd is a shell builtin”. type grep – shows that grep is an alias for grep --color=auto. type -p grep – prints the path of the grep executable, equivalent to which grep.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
