0Pricing
Linux Command Line Mastery · レッスン

ファイルの検索:`find`と`locate`

さまざまな条件に基づいて、システム全体からファイルやディレクトリを効率的に検索する強力なツールを学びます。

「ファイルの検索:`find`と`locate`」はCoddyKit上の無料Linux Command Line Masteryレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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`」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Linux Command Line Masteryコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Linux Command Line Masteryコースには全4レッスンが含まれています。

「ファイルの検索:`find`と`locate`」で何を学びますか?

さまざまな条件に基づいて、システム全体からファイルやディレクトリを効率的に検索する強力なツールを学びます。 ブラウザで直接実行するハンズオンコードでLinux Command Line Masteryを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Linux Command Line Masteryを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのLinux Command Line Masteryは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン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に戻る