1
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 5 years have passed since last update.

findコマンド

Last updated at Posted at 2019-07-16

findは様々な方法でファイル検索ができる。

xargsとの併用に関しては別スレッド

$ find [directory] [検索方法] [検索正規表現]

ディレクトリは適当なものを。(現階層ならば../*など...)

検索正規表現に関しては、*使用時のみエラー発生することがあるので""で囲む。

# 簡単なファイル名検索であればこれらでOK
$ find . -name "hoge*"
$ find ./* -name "*.rtf"
$ find /test -name "num"

大小文字区別のオプションに関してはgrepと同じくiで対処だがinameと記述する点に注意

$ find /test -iname "HoGe*"

findコマンドで得た結果の一通りの情報を得る場合は-lsを末尾に追加

$ find /test -iname "HO*" -ls

これでアクセス権限等を含めた結果が得られる

64363231536 4 -rw-r--r-- 1 sf213471118 admin 32 7 16 17:06 ./hoge.rtf

ファイル名検索以外で使いそうなものは以下

# ファイルサイズで検索( 50>=size , 50<size)
$ find ./* -size +50
$ find ./* -size -50

# 最新の変更日時で検索( 60<=min , 7>days)
$ find ./* -mmin +60
$ find ./* -mtime -7
1
1
1

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
1
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?