0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

findコマンドでできるいろいろな検索方法

Posted at

findコマンドでできるいろいろな検索方法

find コマンドで使用できるいくつかの主要なオプションを以下にまとめました。

ファイル名による検索:

-name:指定したファイル名のファイルを検索するオプション

find /path/to/dir -name "filename"

パス名による検索:

-path:指定したパス名パターンに一致するファイルを検索するオプション

find /path/to/dir -path "path_pattern"

ファイルサイズによる検索:

-size:指定したサイズのファイルを検索するオプション

find /path/to/dir -size [+|-]size[cwbkMG]

ファイルタイプによる検索:

type:指定したファイルタイプのファイルを検索するオプション

find /path/to/dir -type [bcdpfls]

ファイルの更新日時による検索:

mtime:指定した日数以内に更新されたファイルを検索するオプション

find /path/to/dir -mtime [+|-]days

ファイルの所有者による検索:

-user:指定した所有者のファイルを検索するオプション

find /path/to/dir -user "username"

ファイルのグループによる検索:

-group:指定したグループのファイルを検索するオプション

find /path/to/dir -group "groupname"

ファイルの権限による検索:

-perm:指定したパーミッションを持つファイルを検索するオプション

find /path/to/dir -perm mode

複数の検索条件を組み合わせた検索:

find /path/to/dir -name "*.txt" -type f -size +1M -mtime -7

この検索では、以下の条件で指定している。

  • /path/to/dir ディレクトリ以下にある
  • ファイル名が .txt である
  • ファイルタイプがファイルである (type f)
  • ファイルサイズが 1MB 以上である (size +1M)
  • 更新日時が 7日前以降である (mtime -7)
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?