04. Finding Stuffs
Overview¶
Linux provides multiple tools to search files, directories, and binaries efficiently. Each tool serves a different purpose:
-
locate→ fast search using database -
whereis→ find binary, source, and manual -
which→ find executable in PATH -
find→ advanced and flexible search
locate — Fast File Search¶
Description¶
locate is used to quickly find files and directories using a pre-built database.
Basic Usage¶
Explanation
Searches the system for files matching the given name.
Match All Patterns¶
Explanation
Displays all matches for the given pattern.
Search Within a Path¶
Explanation
Filters results within a specific directory path.
Search by Extension¶
Explanation
-
*→ wildcard for any characters -
Finds all
.txtfiles
Count Matches¶
Explanation
Returns the number of matching results.
Case-Insensitive Search¶
Explanation
Ignores case differences during search.
Important Note¶
-
locaterelies on a database -
If results are outdated, update using:
whereis — Locate Binary, Source, and Manual¶
Description¶
whereis finds:
-
Binary executable
-
Source code
-
Manual pages
Usage¶
Example¶
Output Example¶
Explanation
Shows binary location and associated manual file.
which — Locate Executable in PATH¶
Description¶
which finds the exact path of an executable in the system’s PATH variable.
Usage¶
Example¶
Explanation
Displays the path of the python executable being used.
find — Advanced File Search¶
Description¶
find is the most powerful and flexible search command. It allows searching based on:
-
Name
-
Type
-
Size
-
Permissions
-
User/Group
-
Time
Basic Syntax¶
Search from Root Directory¶
Explanation
-
/→ start from root -
-type f→ search for files -
-name→ specify file name
Search in Current Directory¶
Search in Specific Directory¶
Explanation
Limits search scope, improving speed.
Case-Insensitive Search¶
Explanation
Matches regardless of uppercase/lowercase.
Use Wildcards¶
Explanation
-
*→ matches multiple characters -
Finds files with any extension
Search by File Size¶
Explanation
-
+1M→ files larger than 1 MB -
Use
cfor bytes (e.g.,1024c)
Search by Permissions¶
Explanation
Finds files with exact permission 744.
Search Executable Files¶
Find Non-Executable Files¶
Search by User¶
Search by Group¶
Performance Consideration¶
-
Searching from
/(root) is slow -
Prefer targeted paths like
/etc,/home, etc. -
Use root privileges for full system search:
Comparison of Commands¶
| Command | Purpose |
|---|---|
locate |
Fast search using database |
whereis |
Find binary, source, manual |
which |
Find executable in PATH |
find |
Advanced and flexible search |
Important Notes¶
-
Use
locatefor quick searches -
Use
findfor deep and precise searches -
Use
whichto verify executable paths -
Use
whereisfor system-level binary info
Conclusion¶
Linux provides multiple search utilities tailored for different needs:
-
Quick lookup →
locate -
Binary identification →
which,whereis -
Deep investigation →
find
Mastering these commands is essential for:
-
System administration
-
Cybersecurity analysis
-
File management and automation
These tools significantly improve efficiency when working in Linux environments.