0Pricing
Linux Command Line Mastery · บทเรียน

การค้นหาไฟล์: `find` และ `locate`

ค้นพบเครื่องมือทรงพลังสำหรับค้นหาไฟล์และไดเรกทอรีทั่วทั้งระบบอย่างมีประสิทธิภาพตามเกณฑ์ต่าง ๆ

การค้นหาไฟล์: `find` และ `locate` เป็นบทเรียน Linux Command Line Mastery ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Linux Command Line Mastery และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Linux Command Line Mastery มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Find Your Files!

Ever lost a file or needed to find all documents of a certain type on your Linux system? It happens to everyone!

The Linux terminal offers powerful tools to help you search for files and directories efficiently. In this lesson, we'll explore two essential commands: locate and find.

`locate`: The Quick Search

First up is locate. This command is incredibly fast because it doesn't search your filesystem directly in real-time. Instead, it queries a pre-built database of all files on your system.

Think of it like searching an index in a book – it's quick, but the index might not always be perfectly up-to-date.

Basic `locate` Usage

Using locate is straightforward. Just type locate followed by the filename or pattern you're looking for. It will show you all paths that contain that string.

For example, to find all files named "my_document.txt":

locate my_document.txt

Updating `locate`'s Database

Since locate uses a database, its results can sometimes be outdated if new files have been created or deleted since the last database update.

To refresh the database, you can run the updatedb command. This usually requires administrator (root) privileges:

sudo updatedb

`find`: The Real-Time Search

While locate is fast, find is much more powerful and always up-to-date. Instead of a database, find actively traverses your filesystem in real-time, checking every file and directory against your criteria.

This makes find slower than locate for simple searches, but it's perfect for complex, real-time, and precise searches.

`find` Command Structure

The basic syntax for find is:

find [path] [expression]

`find` by Name

One of the most common ways to use find is to search for files by their name. You use the -name option, and you can include wildcards like * (any characters) and ? (any single character).

To find all files ending with .log in your home directory:

find /home -name "*.log"

`find` by File Type

find can also filter results by file type. This is super useful when you only want to see directories or regular files.

  • -type f: Searches for regular files.
  • -type d: Searches for directories.

To find all directories starting with "project" in the current location:

find . -type d -name "project*"

`find` by File Size

Need to find large files taking up space? The -size option is your friend! You can specify sizes using suffixes like c (bytes), k (kilobytes), M (megabytes), G (gigabytes).

  • +: Greater than specified size.
  • -: Less than specified size.
  • No prefix: Exactly specified size.

Example: Find files larger than 10MB in the current directory.

find . -size +10M -name "*.zip"

Comparing Search Tools

You've learned about locate and find. Which of the following statements about these commands are TRUE?

Recap: Finding Files

Great job! You now have two powerful tools for searching files on your Linux system:

  • locate: Fast, database-driven searches. Great for quick checks but needs updatedb for freshness.
  • find: Slower but real-time, powerful, and highly customizable. Essential for complex searches by name, type, size, and more.

Practice using both commands to become a master file finder!

คำถามที่พบบ่อย

บทเรียน “การค้นหาไฟล์: `find` และ `locate`” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การค้นหาไฟล์: `find` และ `locate`” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Linux Command Line Mastery ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Linux Command Line Mastery มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การค้นหาไฟล์: `find` และ `locate`”

ค้นพบเครื่องมือทรงพลังสำหรับค้นหาไฟล์และไดเรกทอรีทั่วทั้งระบบอย่างมีประสิทธิภาพตามเกณฑ์ต่าง ๆ คุณปฏิบัติ Linux Command Line Mastery ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Linux Command Line Mastery หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Linux Command Line Mastery บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “การค้นหาไฟล์: `find` และ `locate`” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Linux Command Line Mastery นี้ได้ไหม

ได้ บทเรียน Linux Command Line Mastery ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การดูเนื้อหาไฟล์: `cat`, `less`, `more`
  2. การค้นหาไฟล์: `find` และ `locate`
  3. สิทธิ์และเจ้าของ: `chmod`, `chown`
  4. การสร้างและใช้งานลิงก์สัญลักษณ์
← กลับไปที่ Linux Command Line Mastery