grep: Search Inside Files
grep "error" app.log # Lines containing "error"
grep -r "keyword" src/ # Recursive search in a directory
grep -i "error" app.log # Case-insensitive
grep -n "error" app.log # Show line numbers
grep -A 3 -B 3 "error" app.log # Show 3 lines of context
find: Locate Files
find . -name "*.log" # Search by extension
find . -type d -name "node_modules" # Find directories
find . -mtime -1 # Modified within 1 day
Combine find and grep
find . -name "*.js" | xargs grep "console.log"
Common Pitfalls
grep -ralso searchesnode_modules— narrow the path to avoid slow resultsfind /starts from the root filesystem and can be very slow
To monitor a log file in real time and filter with grep, combine with Monitor Linux Logs in Real Time with tail -f.
Related Posts
- Linux Basic Commands (ls/cd/mkdir/rm)
- Monitor Linux Logs in Real Time with tail -f
- How to Fix “Permission Denied” on Linux
- Install WSL2 on Windows
Recommended Cloud Hosting
Looking for reliable cloud infrastructure? Check out these developer-friendly services.
- Cherry Servers - High-performance VPS and dedicated servers
- Cloudways - Managed cloud hosting for developers