[grep] Show line numbers for matches

Created on November 30, 2026

Use -n to print each matching line with its line number. A colon separates the number from the text.

printf 'apple\norange\napple\n' | grep -n 'apple'
1:apple
3:apple
Shell command grep