Skip to content
All writing

My daily grep commands

The grep commands I actually use every day — recursive search, excluding folders and file types, and listing matching file names only.

#snippetsdev-toolsserverlinuxgrep

This is my command history. Not my Uber Eats orders, thankfully. My grep commands. 🥁

Whatever you work on, grep earns its place, even if you usually search from your editor. If you know Linux like the back of your hand, this post isn't for you.

Forgot a flag? Check man7.org or run man grep.

The basics: search every file in a folder and its subfolders.

grep -r "pattern" .

Exclude folders

Exclude one folder, or several at once with braces.

grep -r --exclude-dir=node_modules "pattern" .
grep -r --exclude-dir={node_modules,vendor} "pattern" .

Include or exclude file types

grep -r --exclude="*.min.css" "pattern" .
grep -r --include="*.php" "pattern" .

Show file names only

Useful when you only need to know where something is, not every matching line.

grep -rl "pattern" .

Get new posts by email

New writing in your inbox. Unsubscribe anytime.