grep -m 5 'pattern' file.txt

Category: Text Processing

grep -m 5 'pattern' file.txt

Stop after finding 5 matches

Stops searching and exits after finding 5 matches. -m means 'max count'.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.