grep -n: Show Line Numbers in Matches
grep -n prints the 1-based line number before each matching line.
When a CI check finds a problem, line numbers turn the output into something a developer can jump to. -n is the flag that adds them.
What it does
grep -n (--line-number) prefixes every output line with its line number within the file, separated by a colon. With multiple files or -r, grep also prints the filename; -H forces the filename prefix even for a single file, and -h suppresses it.
Common usage
grep -n "TODO" main.go
grep -rn "FIXME" src/
grep -nH "deprecated" *.jsOptions
| Flag | What it does |
|---|---|
| -n / --line-number | Prefix matches with the line number |
| -H / --with-filename | Always print the filename |
| -h / --no-filename | Never print the filename |
| -T / --initial-tab | Align output with a leading tab |
| -b / --byte-offset | Print the byte offset instead of/with line number |
In CI
Use grep -rnH in lint-style checks so the log shows file:line:match, which many CI UIs and editors turn into clickable links. The format matches what tools like git grep and compilers emit, so downstream parsers handle it.
Common errors in CI
There is no real failure mode here beyond the universal no-match exit 1. One subtlety: line numbers count lines in each file independently, so when grepping concatenated output (e.g. from cat a b) the numbers restart per file only if grep sees them as separate arguments, not when they are merged in a pipe.