Поиск файлов: `find` и `locate`
Узнайте о мощных инструментах для эффективного поиска файлов и каталогов в системе по различным критериям.
«Поиск файлов: `find` и `locate`» — бесплатный урок Linux Command Line Mastery на CoddyKit. Это урок 2 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 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.txtUpdating `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 needsupdatedbfor 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`» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Linux Command Line Mastery, подпишись на CoddyKit PRO. Курс Linux Command Line Mastery содержит 4 уроков всего.
Чему я научусь в уроке «Поиск файлов: `find` и `locate`»?
Узнайте о мощных инструментах для эффективного поиска файлов и каталогов в системе по различным критериям. Ты практикуешь Linux Command Line Mastery с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 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 — локальная установка не требуется.
Все уроки этого курса
- Просмотр содержимого файлов: `cat`, `less`, `more`
- Поиск файлов: `find` и `locate`
- Права доступа и владельцы: `chmod`, `chown`
- Создание и использование символических ссылок