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
Find every TODO in the src folder, with line numbers
grep -rn "TODO" srcsame as:
grep -nr "TODO" src,grep -rn TODO src,grep -nr TODO srcgrep— search text-r— in every file of the folder-n— with line numbers"TODO" src— what to find and where
Find lines in app.log with the word error in any case
grep -i error app.logsame as:
grep -i "error" app.log,grep --ignore-case error app.loggrep— search text-i— ignore case: Error, ERRORerror app.log— what to find and where