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:
|
|
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:
|
|
Find Files
With the find command, we can find almost all the files we want.
Let’s prepare some 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:
|
|
Let’s look for files or directories that begin with dir01:
|
|
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
|
|
Search for Directories
We can find directory type files with the -type d parameter:
|
|
Search for Regular Files
We can find regular file type files with the -type f parameter:
|
|
Search for Symbolic(Soft) Links
We can find symbolic/soft link type files with the -type l parameter:
|
|
References WHEREIS(1), LOCATE(1), Findutils, 2 Finding Files, 4 File Name Databases,
Author Dong Chen
LastMod Mon Mar 11 2019