0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Linux][command] ファイル検索_find, locate, updatedb, which, whereis, type

Last updated at Posted at 2025-02-08

一覧

コマンド 検索対象 参照先
find ファイル 指定したディレクトリ
locate ファイル 事前に作成されたデータベース(通常 /var/lib/mlocate/mlocate.db
which 実行可能ファイル $PATH 環境変数内のディレクトリ
whereis 実行可能ファイル、関連ファイル(ライブラリ、マニュアル、ソースコード) 特定のディレクトリ(/bin, /usr/bin, /usr/share/man など)
type コマンドの種類(シェル組み込み、関数、エイリアス、外部コマンド) $PATH 環境変数内のディレクトリ

findコマンド

# find [検索ディレクトリ] [検索式]
検索式 英語の由来 説明
デフォルト find はカレントディレクトリ以下でファイルを検索
-name name ファイル名が指定したパターンに一致するファイルを検索
-atime access time 最終アクセス時刻でファイルを検索
-mtime modification time 最終更新時刻で変更されたファイルを検索
-perm permission 指定したパーミッションを持つファイルを検索
-size size ファイルサイズを指定して検索(+ = より大きい, - = より小さい)
-type type ファイルタイプを指定して検索(f = 通常ファイル, d = ディレクトリなど)
-user user 所有者が指定したユーザーのファイルを検索
-exec execute 検索したファイルに対して指定したコマンドを実行
-print print 検索結果を改行で区切って表示(デフォルトで有効)
-print0 print null-terminated 検索結果をNULL文字(¥0)で区切って表示(空白や改行を含むファイル名も対応)
-maxdepth maximum depth 指定した階層まで検索を制限(例:-maxdepth 2 で2階層まで検索)
-mindepth minimum depth 指定した階層以上の深さから検索(例:-mindepth 2 で2階層目から検索)

whichコマンド

# which コマンド名

whereisコマンド

$ whereis [オプション] コマンド
オプション 英語の由来 説明
デフォルト すべてのカテゴリ(バイナリ → ライブラリ → マニュアル → ソースコード)を検索
-b binary バイナリファイル(実行可能ファイル)のみを検索
-m manual マニュアルファイル(man ページ)のみを検索
-s source ソースコードファイルのみを検索

typeコマンド

$ type コマンド

補足

バイナリファイル、ライブラリディレクトリ、マニュアルファイル、ソースコードファイルの違い

種類 内容 格納場所の例 コマンド例
バイナリファイル 実行可能な機械語のプログラム /bin, /usr/bin, /sbin whereis -b ls
ライブラリディレクトリ プログラムが利用するライブラリやモジュール /usr/lib/, /lib/, /usr/local/lib/ -
マニュアルファイル man で参照できる説明文書 /usr/share/man/ whereis -m ls / man ls
ソースコードファイル 人間が読めるプログラムコード /usr/src/ whereis -s ls

whichとwhereisの違い

# which python
// 出力結果
/usr/bin/python  (実行可能ファイルの場所)

# whereis python
// 出力結果
python: /usr/bin/python /usr/lib/python3.8 /usr/share/man/man1/python.1.gz  (バイナリ + ライブラリ + マニュアル)

Ping-t

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?