Linux / OS Fundamentals Series

🧭 The Top 1% Hands-On for Tracking Down a File or Directory Yourself With find: Training Your Instinct for Where Things Live

Introduction

This article is part of the Top 1% Series Complete Article Guide, the 13th article in the Linux/OS Fundamentals Series.

The Big Picture

This hands-on consists of four steps.

graph LR
    Step1["Step1<br/>Find a file from part<br/>of its name"]
    Step2["Step2<br/>Narrow by<br/>type and location"]
    Step3["Step3<br/>Narrow by<br/>modification time"]
    Step4["Step4<br/>Run an operation on<br/>a file you found"]
    Step1 --> Step2 --> Step3 --> Step4

Hands-On Steps

Step 1: Find a file from part of its name

Try finding where, across the entire system, a file containing the string “bind” lives.

sudo find / -name "*bind*" 2>/dev/null

The -name option accepts a partial-match pattern using a wildcard (*). 2>/dev/null is an incantation that hides the flood of Permission denied error messages that show up from directories you don’t have access to. This result should turn up /etc/bind/, a directory that looks exactly like where configuration would live.

Step 2: Narrow by type and location

Targeting the /etc/bind/ directory you just found, list only files (excluding directories).

find /etc/bind -type f

-type f narrows it down to files only, and -type d to directories only. Narrowing the search directory from / down to /etc/bind shrinks the search scope and makes the result easier to read. “Search broadly across everything first, then once you’ve narrowed it down, search further from there” is the basic real-world approach.

Step 3: Narrow by modification time

Try finding “which file did I edit just now” based on modification time.

find /etc/bind -mmin -30

-mmin -30 is the condition “modified within the last 30 minutes.” Use -mtime -1 for “within the last day.” This condition is extremely powerful when you know you just edited something, but forgot which file it was.

Step 4: Run an operation on a file you found

Run an operation directly on files found by find.

find /etc/bind -name "*.local" -exec cat {} \;

The -exec option lets you run a specified command on each file that’s found. {} is a placeholder meaning “the found file’s path goes here,” and the trailing \; is the fixed syntax marking the end of the command run by -exec.

What a Pro Sees Here (Top 1% Understanding)

The Instinct for What’s Likely Where, From a Directory’s Name

Even more important than how to use find itself is whether you understand the directory naming conventions covered in Understanding /etc and Linux’s Directory Structure (FHS) From a “Top 1%” Perspective. Keep the FHS (Filesystem Hierarchy Standard) convention in mind — configuration goes in /etc, logs in /var/log, variable data in /var — and you can make a good guess about “it’s probably around here” before you even run find. find is a tool for reinforcing this instinct of “making a good guess” — it isn’t a substitute for that instinct itself. Missing either one means wasted time getting to the file you actually need in real-world work.

locate and tree, Commands That Complement find

find scans the filesystem directly every time it runs, so it takes time when the target scope is broad. The locate command searches a pre-built index (database) of filenames, making it far faster than find. But since that index only updates periodically (usually once a day), it can miss a file created just minutes ago. And when you want to survey a directory’s structure as a hierarchy, laid out visually, the tree command is a better fit. The basic real-world division is: “locate for speed when just searching by name,” “tree for visually seeing a hierarchy,” and “find when you need fine-grained conditions — modification time, type, and on-the-spot operations via -exec.”

Common Misconceptions and Pitfalls

Troubleshooting Perspective

  1. find’s result has too much output to read: Narrow the search scope (/etc instead of /), or add a condition like -type f to narrow it down.
  2. A flood of Permission denied shows up: Add 2>/dev/null at the end, or run it with sudo.
  3. locate can’t find a recently created file: Run sudo updatedb to manually refresh the index, or use find for a very recent file.

Summary

Takeaways to Apply Today

  1. When you forget a file’s path, build the habit of tracking it down yourself with find before hunting for a reference document.
  2. When you see a directory name, build the habit of thinking about “what’s likely stored here” against FHS conventions.

References

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).