Week 3 of 12 🔍

Search & Navigation: Grep & Glob

การค้นหาและนำทาง: Grep และ Glob

Search & Navigation: Grep & Glob

1. Introduction / บทนำ

การค้นหาโค้ดในโปรเจกต์ขนาดใหญ่เป็นสิ่งจำเป็น Claude Code มีเครื่องมือค้นหาที่ทรงพลังสองตัว: Grep (ค้นหาข้อความภายในไฟล์) และ Glob (ค้นหาไฟล์ตามรูปแบบชื่อ) ช่วยให้คุณนำทางโค้ดเบสได้อย่างรวดเร็ว
Finding code in a large project is essential. Claude Code provides two powerful search tools: Grep (search inside files for text patterns) and Glob (find files by name patterns). Together, they help you navigate any codebase quickly.

Fun Facts / ข้อเท็จจริงที่น่าสนใจ

  • Grep supports full regex patterns like 'function\s+\w+'.
  • Glob uses patterns like **/*.ts to find all TypeScript files.
  • The Explore agent combines both tools for deep codebase research.

2. Vocabulary / คำศัพท์

Click a card to flip it. คลิกการ์ดเพื่อพลิก

search
ค้นหา
To look for something
pattern
รูปแบบ
A regular expression or glob to match
match
ตรงกัน
When a search finds a result
result
ผลลัพธ์
What a search returns
directory
ไดเรกทอรี
A folder containing files
glob
กลอบ
A pattern to match file names (e.g., *.js)
grep
เกรป
A tool to search text inside files
regex
เรกซ์
Regular expression — a search pattern
filter
กรอง
To narrow down results
codebase
โค้ดเบส
All the source code in a project
explore
สำรวจ
To look through code to understand it
navigate
นำทาง
To move through files and folders

3. Grammar Focus / ไวยากรณ์

Question Words (What, Where, How many) / คำถาม (What, Where, How many)

Thai:
คำถาม (Wh-words) ใช้ถามข้อมูลเฉพาะ What = สิ่งของ, Where = สถานที่, How many = จำนวน, Which = ตัวเลือก ตัวอย่าง: 'What does Grep search for?' 'Where are the config files?'
English:
Question words (Wh-words) are used to ask for specific information. What = things, Where = places, How many = quantity, Which = choice. Example: 'What does Grep search for?' 'Where are the config files?'
ไฟล์อะไรตรงกับรูปแบบ *.js?
What files match the pattern *.js?
ไฟล์ configuration หลักอยู่ที่ไหน?
Where is the main configuration file?
การค้นหาคืนผลลัพธ์กี่รายการ?
How many results did the search return?

Section Check 1

Which tool searches inside files?

เครื่องมือใดค้นหาภายในไฟล์?

Section Check 2

What does **/*.py match?

**/*.py ตรงกับอะไร?

Section Check 3

Which question word asks about quantity?

คำถามใดถามเกี่ยวกับจำนวน?

4. Tutorial Steps / ขั้นตอนการเรียนรู้

1
Search for text in files / ค้นหาข้อความในไฟล์
Ask: 'Find all files that contain the word error' — Claude uses Grep.
2
Find files by pattern / ค้นหาไฟล์ตามรูปแบบ
Ask: 'Find all .json files in the config directory' — Claude uses Glob.
3
Use regex patterns / ใช้รูปแบบ regex
Ask: 'Search for function definitions matching function\s+handle' — Grep supports regex.
4
Filter results / กรองผลลัพธ์
Grep can show file names only, line content, or match counts.
5
Use the Explore agent / ใช้ Explore agent
For complex searches, Claude can spawn an Explore subagent to research the codebase.

5. Hands-On Activity / กิจกรรมลงมือทำ

แบบฝึกหัด: ขอให้ Claude ค้นหาไฟล์ Python ทั้งหมดในโปรเจกต์ จากนั้นค้นหาไฟล์ที่มีคำว่า 'import'
Practice: Ask Claude to find all Python files in your project, then search for any file containing the word 'import'.

6. Reference Table / ตารางอ้างอิง

Command / ToolEnglishภาษาไทย
GrepSearch text inside filesค้นหาข้อความภายในไฟล์
GlobFind files by name patternค้นหาไฟล์ตามรูปแบบชื่อ
**/*.jsAll .js files recursivelyไฟล์ .js ทั้งหมดแบบ recursive
Explore agentDeep codebase researchวิจัยโค้ดเบสเชิงลึก

7. Summary / สรุป

Grep ค้นหาภายในไฟล์ Glob ค้นหาไฟล์ตามชื่อ ใช้คำถาม (What, Where, How many) เพื่อถามเกี่ยวกับผลการค้นหา Explore agent จัดการงานวิจัยที่ซับซ้อน
Grep searches inside files. Glob finds files by name. Use question words (What, Where, How many) to ask about search results. The Explore agent handles complex research tasks.

Homework / การบ้าน

1. ค้นหาคอมเมนต์ TODO ทั้งหมดในโปรเจกต์
2. ค้นหาไฟล์ทั้งหมดที่ลงท้ายด้วย .md
3. เขียนคำถาม 5 ข้อโดยใช้ Wh-words เกี่ยวกับโค้ดเบส
1. Search for all TODO comments in a project.
2. Find all files ending in .md.
3. Write 5 questions using Wh-words about a codebase.