M10 - Search and Find
Search and Find
Find programs and files in a way that matches the real problem: command lookup, live recursive search, or fast indexed search.
- Check which executable the system will run.
- Search the live file system by name.
- Understand when an index is faster than a live scan.
Why This Matters
“Search” is really three different jobs:
- find the executable behind a command
- search the live file system for a file or folder
- search an index when speed matters more than immediate freshness
If you choose the wrong kind of search, you either miss the file or wait longer than necessary.
1. Find the Program Behind a Command
When you type a command, the shell searches a set of directories in your PATH.
where.exe pwsh where.exe node
which bash whereis python3
Use this when a command behaves strangely and you want to know which installed copy is actually running.
2. Search the Live File System
If the file may be new, moved recently, or outside any index, search the real directory tree.
Get-ChildItem -Path .\Project -Filter “*.log” -Recurse
Get-ChildItem -Path C:\ -Filter “hosts” -Recurse -ErrorAction SilentlyContinue
find ./Project -iname “*.log”
find /etc -name “hosts” 2>/dev/null
This is slower than indexed search, but it reflects the file system as it is right now.
3. Use Indexed Search When Speed Matters
Some systems keep a database of files so they can answer quickly.
Windows Search is mostly surfaced through the desktop interface. In practice, many learners still use File Explorer or the Start menu for indexed lookup on Windows.
locate ssh_config
Refresh the database when needed
sudo updatedb
Indexed search is fast because it reads a prepared database, not the live tree. That is why it can miss files created only moments ago.
Decision Rule
If you need what exists right now, use a live recursive search. If you need speed on a large system and the file is not brand new, an index can be the better tool.
What to Ignore for Now
- advanced
findactions like-exec - complicated regular expressions
- platform-specific indexing internals
The important skill is choosing the right search category before you type the command.
Before You Move On
You are ready when you can answer these from memory:
- Which tool tells you where a command comes from?
- Which tool searches the live file system?
- Why can indexed search be fast but slightly stale?
The next step is to apply the whole file-system block in a short practical scenario.