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 -r also searches node_modules — narrow the path to avoid slow results
  • find / 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.

Looking for reliable cloud infrastructure? Check out these developer-friendly services.