Tools & Commands · Linux and Windows Commands
grep
Files · Beginner
A Unix text search that prints lines matching a pattern. Administrators use it to find an error in a log or a setting in a configuration file they are allowed to read.
You give it a word or pattern and a file. It prints the matching lines. It searches text you can already read; it does not grant access.
Example: grep -n "error" app.log prints each matching line with its line number.
Command
Platform: Linux and macOS
grep -n "error" app.log
-n adds line numbers. Each printed line matched the pattern. No output means nothing matched, not that the file is missing.
Common misconception
- A pattern is not automatically a literal word if special characters are involved. Quotes keep a simple search predictable.