One of the most common questions Linux beginners ask is:
- “Where is this file?”
- “How do I find a specific error in logs?”
- “Where is this command installed?”
Linux has powerful tools to answer these questions quickly.
In this guide, you’ll learn the most useful search commands.
Finding Files vs Searching Text
These are two different tasks:
-
Finding files = Locating a file or directory on the system →
find -
Searching text = Looking for words inside files →
grep
1. Find Files with find
# Find a specific file
find /home -name "nginx.conf"
# Search entire system (ignore permission errors)
find / -name "*.log" 2>/dev/null
# Find only directories
find . -type d
# Find only files
find . -type f
# Find files larger than 100MB
find / -type f -size +100M 2>/dev/null
Useful for:
- Finding configuration files
- Locating log files
- Finding large files
- Searching project directories
Best Tip: Always try to narrow the search path instead of searching from / whenever possible.
2. Search Text Inside Files with grep
# Search for a word
grep error app.log
# Case insensitive search
grep -i error app.log
# Search recursively in directory
grep -r "database" /etc/
# Show line numbers
grep -n "listen" nginx.conf
# Count matches
grep -c "failed" auth.log
Useful for:
- Searching logs
- Finding configuration values
- Looking for error messages
- Debugging applications
3. Find Executable Location with which
which python3
which docker
which nginx
Shows the full path of the command that will be executed.
Useful for:
Finding executable locations
Checking which version of a command Linux will run
Verifying software installation
4. Find Program Files with whereis
whereis nginx
whereis python3
It can show:
Binary location
Source files (if available)
Manual pages
Useful when you want to know where a program and its documentation are stored.
Bonus: Fast File Search with locate
locate nginx.conf
Much faster than find because it uses a database.
If it doesn't return recent files, Update database:
sudo updatedb
Note: locate may not be installed by default on every Linux distribution.
Real-World Troubleshooting Example
Nginx is not starting.
# Find config file
find /etc -name nginx.conf 2>/dev/null
# Search for errors in logs
grep -i error /var/log/nginx/error.log
# Check executable
which nginx
# See all related files
whereis nginx
This is a common workflow during Linux troubleshooting.
Common Beginner Mistakes
- Using
find /instead of a specific directory - Forgetting
2>/dev/nullwhen searching the whole system - Confusing
findwithgrep - Not knowing the difference between
whichandwhereis - Forgetting that
locatemay require an updated database
Simple Mental Model
| Command | Use For |
|---|---|
find |
Locate files and directories |
grep |
Search text inside files |
which |
Find executable path |
whereis |
Find program + docs |
locate |
Fast filename search |
Summary
In this guide you learned:
- How to find files with
find - How to search text with
grep - How to locate commands with
whichandwhereis - How to perform fast filename searches with
locate
Next Post:
Viewing Files in Linux (cat, less, head, tail & wc)
Question for You
Which command do you use most while troubleshooting — find, grep, or something else?
Top comments (0)