Labs ICT
โญ Pro Login

Grep

Every day you will find yourself searching through files โ€” log files, configuration files, source code, or a giant CSV export. The grep command is your search engine on the command line. It is fast, flexible, and once you get comfortable with it, you will wonder how you ever lived without it.

Basic search

The simplest use of grep is finding lines that contain a word or pattern. Give it the pattern first, then the file. It prints every matching line.

$ grep "error" server.log
[ERROR] 2026-06-25 10:23: Connection timeout
[ERROR] 2026-06-25 11:45: Database unreachable
Try it Yourself โ†’

Ignore case with -i

By default grep is case-sensitive. "Error" and "error" are different to it. Add the -i flag to ignore case and catch everything.

$ grep -i "error" server.log
[ERROR] 2026-06-25 10:23: Connection timeout
[WARNING] Disk space low โ€” not an error yet but close
[error] 2026-06-25 12:01: Permission denied
Try it Yourself โ†’

Recursive search with -r

When you are not sure which file contains what you are looking for, grep -r searches through every file in a directory tree. Add -n to show line numbers so you know exactly where to look.

$ grep -rn "TODO" src/
src/main.js:42: // TODO: handle edge case
src/utils.js:17: // TODO: refactor this mess
Try it Yourself โ†’

Invert match with -v

Sometimes you want everything except what matches. The -v flag inverts the match. It is great for filtering out blank lines or comments.

$ grep -v "^$" config.ini
[server]
port=8080
host=0.0.0.0
[logging]
level=debug
Try it Yourself โ†’

๐Ÿงช Quick Quiz

Which command searches for a pattern inside files?