You can use grep for various types of searches in files. Here are some common usages:
Basic Syntax
grep [options] 'pattern' filename
Common Options
-i: Ignore case (case-insensitive search).-v: Invert match (show lines that do not match the pattern).-ror-R: Recursively search through directories.-n: Show line numbers with output lines.-l: Show only the names of files with matching lines.
Examples
-
Case-Insensitive Search:
grep -i 'pattern' filename -
Search for a Pattern in All Files in a Directory:
grep 'pattern' * -
Recursive Search in a Directory:
grep -r 'pattern' /path/to/directory -
Show Line Numbers:
grep -n 'pattern' filename -
Invert Match:
grep -v 'pattern' filename
Example Usage
To search for the word "error" in a log file, ignoring case:
grep -i 'error' /var/log/syslog
Feel free to ask if you have a specific search in mind or need more examples!
