39. Find Utilities - Commands & Files Searching Basics
Contents
Linux provides us with tools that make it easy for us to find the location of files and commands quickly and efficiently.
Find Commands
whereis
We can use the whereis command to get the location of a command’s binary, source, and user manual.
Here are some options provided by the whereis command:
Option | Meaning |
---|---|
-s | Only search for source files. |
-b | Only search for binary files. |
-m | Only search for manual files. |
By default, all three options are used:
|
|

Outputs the sources, binaries and manuals of the ls command
locate
We can also use the locate command to find the location of a command.
Here are some options provided by the locate command:
Option | Meaning |
---|---|
-b or ‑‑basename | Search by the filename. |
-w or ‑‑wholename | Search by the path + filename. |
-i or ‑‑ignore-case | The path or filename can be lowercase or uppercase. |
By default, the option -w is used:
|
|

Outputs the filename that starts with ls under the /bin directory
Find Files
With the find command, we can find almost all the files we want.
Let’s prepare some directories:
|
|

Create multiple multilevel directories
Here are some options provided by the find command:
Option | Meaning |
---|---|
-name | Search by the filename. |
-path | Search by the pathname. |
-type d | Search for directories. |
-type f | Search for regular files. |
-type l | Search for symbolic(soft) links. |
Find By Name
Iterate over all files or directories in a subdirectory whose names start with dir:
|
|

Finds all the directories or files whose names starts with dir
Let’s look for files or directories that begin with dir01:
|
|

Finds all the directories or files whose names starts with dir
Find By Path
If we want to find the directory we want more effectively, we can use the path option.
Let’s look for directories that are structured like this: 01_02/dir
|
|

Finds all the directories or files whose names starts with dir
Search for Directories
We can find directory type files with the -type l parameter:
|
|

Finds all the directories
Search for Regular Files
We can find regular file type files with the -type l parameter:
|
|

Finds all the regular files
Search for Symbolic(Soft) Links
We can find regular file type files with the -type l parameter:
|
|

Finds the created symbolic(soft) links
References WHEREIS(1), LOCATE(1), Findutils, 2 Finding Files, 4 File Name Databases,
Author Dong Chen
LastMod Mon Mar 11 2019