grep - Search File Contents in Linux
From the Linux Essential Commands cheat sheet · Search & Find · verified Jul 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 matches
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