Practical Linux Commands
Essential File Search Commands
1. find
Command
The most powerful and flexible file search utility in Linux.
## Basic case-insensitive search
find /path -iname "filename.txt"
## Search with multiple criteria
find / -type f -iname "*.log" -size +1M
2. locate
Command
Fast database-based search method.
## Update locate database
sudo updatedb
## Case-insensitive search
locate -i "filename"
Advanced Search Techniques
Combining Search Criteria
Command |
Description |
Example |
find + grep |
Complex pattern matching |
`find / -type f |
find + exec |
Perform actions on found files |
find . -iname "*.txt" -exec grep -l "keyword" {} \; |
Search Workflow Visualization
graph TD
A[Start Search] --> B{Choose Search Method}
B --> |Comprehensive| C[find Command]
B --> |Quick| D[locate Command]
B --> |Pattern Match| E[grep Command]
C --> F[Apply Filters]
D --> F
E --> F
F --> G[Display/Process Results]
Practical Search Scenarios
1. Finding Large Files
## Find files larger than 100MB
find / -type f -size +100M
2. Search by Modification Time
## Find files modified in last 7 days
find /home -type f -mtime -7
3. Complex File Search
## Find Python files containing specific text
find /project -name "*.py" -exec grep -l "import numpy" {} \;
- Limit search paths
- Use specific file type filters
- Utilize indexed searches when possible
Command Comparison
Command |
Speed |
Flexibility |
Use Case |
find |
Moderate |
High |
Complex, detailed searches |
locate |
Fast |
Low |
Quick file location |
grep |
Fast |
Medium |
Text pattern matching |
LabEx Recommended Workflow
- Start with
locate
for quick searches
- Use
find
for complex file location
- Combine with
grep
for advanced filtering
By mastering these practical Linux commands, users can efficiently manage and search files in Ubuntu and other Linux environments.