grep

Find the lines with some text in files

What it does

grep prints the lines that contain the text you look for. What to find comes first, then where: grep error app.log. If the text has spaces or special characters, put it in quotes.

-i ignores case, -n adds line numbers, -r searches every file in a folder and its subfolders, and -v does the opposite, keeping the lines without a match. Without a file, grep reads what comes in through a pipe.

Syntax

grep <text> <file>
grep -rn <text> <folder>
grep -i <text> <file>

Examples

Related commands

Practise · All commands