Skip to content

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


Description

locate is used to quickly find files and directories using a pre-built database.


Basic Usage

locate "filename"

Explanation
Searches the system for files matching the given name.


Match All Patterns

locate --all "filename"

Explanation
Displays all matches for the given pattern.


Search Within a Path

locate /path --all "filename"

Explanation
Filters results within a specific directory path.


Search by Extension

locate --all "*.txt"

Explanation

  • * → wildcard for any characters

  • Finds all .txt files


Count Matches

locate --all -c "filename"

Explanation
Returns the number of matching results.


locate --all -i "filename"

Explanation
Ignores case differences during search.


Important Note

  • locate relies on a database

  • If results are outdated, update using:

sudo updatedb

whereis — Locate Binary, Source, and Manual

Description

whereis finds:

  • Binary executable

  • Source code

  • Manual pages


Usage

whereis binary_name

Example

whereis bash

Output Example

bash: /bin/bash /usr/share/man/man1/bash.1.gz

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

which command

Example

which python

Explanation
Displays the path of the python executable being used.


Description

find is the most powerful and flexible search command. It allows searching based on:

  • Name

  • Type

  • Size

  • Permissions

  • User/Group

  • Time


Basic Syntax

find /path -type f -name "filename"

Search from Root Directory

find / -type f -name "filename"

Explanation

  • / → start from root

  • -type f → search for files

  • -name → specify file name


Search in Current Directory

find . -type f -name "filename"

Search in Specific Directory

find /etc -type f -name "filename"

Explanation
Limits search scope, improving speed.


Case-Insensitive Search

find / -type f -iname "filename"

Explanation
Matches regardless of uppercase/lowercase.


Use Wildcards

find /etc -type f -name "filename.*"

Explanation

  • * → matches multiple characters

  • Finds files with any extension


Search by File Size

find / -type f -name "filename" -size +1M

Explanation

  • +1M → files larger than 1 MB

  • Use c for bytes (e.g., 1024c)


Search by Permissions

find /etc -type f -perm 744

Explanation
Finds files with exact permission 744.


Search Executable Files

find / -type f -executable

Find Non-Executable Files

find / -type f ! -executable

Search by User

find / -type f -user username

Search by Group

find / -type f -group groupname

Performance Consideration

  • Searching from / (root) is slow

  • Prefer targeted paths like /etc, /home, etc.

  • Use root privileges for full system search:

sudo find / -type f -name "filename"

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 locate for quick searches

  • Use find for deep and precise searches

  • Use which to verify executable paths

  • Use whereis for 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.