Week 3 of 12 🔍
การค้นหาและนำทาง: Grep และ Glob
搜索与导航:Grep 和 Glob
Click a card to flip it. คลิกการ์ดเพื่อพลิก 点击卡片翻面。
Which tool searches inside files?
เครื่องมือใดค้นหาภายในไฟล์?
哪个工具在文件内部搜索?
What does **/*.py match?
**/*.py ตรงกับอะไร?
**/*.py 匹配什么?
Which question word asks about quantity?
คำถามใดถามเกี่ยวกับจำนวน?
哪个疑问词用来询问数量?
How to do it
Grep and returns file names plus the matching lines with line numbers.How to do it
Glob with a pattern like config/**/*.json.* means "any name", ** means "any folder depth". Glob finds files by name, not content.How to do it
function\s+handle — \s+ means "one or more spaces", so it matches function handle and function handleClick.How to do it
How to do it
Glob matches file names and paths. Three symbols do all the work:
* = any name inside one folder, ** = any depth of folders,
? = exactly one character.
Regex matches text inside files. It describes a pattern, not an exact word:
\d = a digit, \s = a space, \b = a word edge,
^ = line start, $ = line end, | = or,
+ = one or more, ? = optional. A real dot must be written \.
| Pattern | Finds |
|---|---|
*.py | every Python file in the current folder |
**/*.py | every Python file in any folder |
src/*.js | JS files directly inside src/ |
src/**/*.js | JS files anywhere under src/ |
*.test.js | test files by their suffix |
config/**/*.json | JSON anywhere under config/ |
**/test_* | files starting with test_ in any folder |
*.md | every Markdown file here |
**/.env* | env/config dotfiles anywhere |
photos/202?.jpg | ? = one character: 2020.jpg … 2029.jpg |
| Pattern | Matches |
|---|---|
error | the word error anywhere in a line |
^import | lines that START with import |
TODO|FIXME | either word |
\bclass\b | the whole word class only (not classroom) |
function\s+\w+ | function, spaces, then a name |
\d+ | one or more digits (7, 42, 2026) |
"[^"]*" | anything inside double quotes |
\.png$ | lines that END with .png |
user_?name | username or user_name (? = optional _) |
(GET|POST) /api | API lines with either verb |
Tip: you never have to remember these — describe what you want in plain English and Claude writes the pattern. This table is for reading what Claude wrote back to you.
Step by step
claude in a project that has some code files.✓ You did it right if: you get a file list, then matches with line numbers you can open and check.
> Find all Python files in this project
* Glob(**/*.py)
app.py
tests/test_app.py
> Which of those files contain the word import?
* Grep("import")
app.py - 2 matches
tests/test_app.py - 1 match
> Show the matching lines in app.py with line numbers
1: import os
2: import json
| Command / Tool | English | ภาษาไทย | 中文 |
|---|---|---|---|
Grep | Search text inside files | ค้นหาข้อความภายในไฟล์ | 在文件内搜索文本 |
Glob | Find files by name pattern | ค้นหาไฟล์ตามรูปแบบชื่อ | 按文件名模式查找文件 |
**/*.js | All .js files recursively | ไฟล์ .js ทั้งหมดแบบ recursive | 递归匹配所有 .js 文件 |
Explore agent | Deep codebase research | วิจัยโค้ดเบสเชิงลึก | 深入研究代码库 |
Search a tiny fake project with real patterns — Grep for content, Glob for names. / ลองค้นหาด้วย Grep และ Glob / 用 Grep 和 Glob 实际搜索
Three fake files. Type a word (or tick regex) and watch Grep find it live.