Lv.1 0 XP

Grep vs Glob — The Commonly Confused Code Navigation Tools

⚡ Exam Tested 6 min +25 XP
💡
THE ANALOGY

The difference between a metal detector and a map. A metal detector (grep) scans through soil looking for signals inside it — it searches CONTENT. A map (glob) shows you where paths lead based on their structure — it matches FILE PATHS by pattern.

⚠️ EXAM TRAP — The Wrong Answer People Choose

Using grep when you need glob or vice versa. The exam tests this with specific scenarios — 'find all files named *.test.tsx' needs glob, 'find all files containing the function callRefund' needs grep.

KEY POINTS
1 Grep searches FILE CONTENTS for a pattern — it opens files and looks inside them. Use when you know what the code says but not where it lives.
2 Glob matches FILE PATHS by pattern — it looks at file names and directory structure without opening files. Use when you know where code lives by its naming convention.
3 Grep use cases: find all callers of a function, find all files that import a module, find error messages, find TODO comments.
4 Glob use cases: find all test files (*.test.tsx), find all files in a directory (src/**/*.ts), find all config files.
5 Combining them is powerful: glob to find candidate files, grep to filter by content.