grep - Search File Contents in Linux
From the Linux Commands cheat sheet · Search & Find · verified Nov 2026
grep - Search File Contents
Search for patterns in file contents
bash
# Search in file
grep "pattern" file.txt
# Case-insensitive
grep -i "pattern" file.txt
# Recursive search
grep -r "pattern" directory/
# Show line numbers
grep -n "pattern" file.txt
# Count matching lines
grep -c "pattern" file.txt
# Invert match (exclude)
grep -v "pattern" file.txt✅ -i ignores case, -r searches recursively
💡 -n shows line numbers for matches
🔍 Use grep with pipes: ps aux | grep process_name
searchgreppatterntext
Continue with Linux Commands
Save the full cheat sheet or work through every related task.