How to search text in files using grep

Answered
Jan 05, 2026 96 views 1 answers
14

I need to find files containing specific text. How do I use grep effectively?

S
Asked by sysadmin
Silver 222 rep

1 Answer

9
# Basic search
grep "pattern" file.txt

# Recursive search in directory
grep -r "pattern" /path/

# Case insensitive
grep -i "pattern" file.txt

# Show line numbers
grep -n "pattern" file.txt

# Show only filenames
grep -l "pattern" *.txt

# Invert match (lines NOT matching)
grep -v "pattern" file.txt

# Regex search
grep -E "error|warning" logfile.log

# Count matches
grep -c "pattern" file.txt
H
Answered by hassan_ops 1 week, 2 days ago
Bronze 565 rep

Your Answer

You need to be logged in to answer questions.

Log In to Answer

Related Questions

Hot Questions

No hot questions available.