↑↓ move Enter open Esc close

How to Use grep Recursively in Linux

Search every file under a directory with grep, show filenames and line numbers, and skip noisy folders.

Recursive grep is the classic Linux answer to “where is this text used?”. Start with the smallest useful directory and add filters to reduce noise.

Step by step

1 Search recursively

$ grep -rn "TODO" .

Prints the filename, line number and matching line.

2 Search a project directory

$ grep -rn "DATABASE_URL" ./src

A narrower start path makes results faster and easier to inspect.

3 Ignore case

$ grep -rni "error" logs/

Combine recursion, line numbers and case-insensitive matching.

4 Exclude noisy folders

$ grep -rn "TODO" . --exclude-dir=.git --exclude-dir=node_modules

Avoid dependency and repository metadata content.

5 List matching files

$ grep -rl "deprecated-api" src/

Use -l when you only need filenames.

Tips worth knowing

Frequently asked questions

What does grep -r do?

It recursively searches files below the directory you provide.

How do I ignore node_modules?

Add `--exclude-dir=node_modules`.

How do I get line numbers?

Add `-n`, for example `grep -rn "text" .`.

The commands behind it

Concepts involved: Regular expression · Pipe (|)

More how-to guides