LoginSignup
25
17

More than 5 years have passed since last update.

mac で高速にファイル検索 / 全文検索するコマンドmdfind

Posted at

ファイル名検索の使い方

~/(ホームディレクトリ)から、ファイル名に "yamazon"を含むファイルを検索
-name にファイル名を指定します

# コマンド
mdfind -onlyin ~/ -name yamazon

# 結果(ファイル名に"yamazon"を含むファイルを抽出)
/Users/t-yamamoto/yamazon
/Users/t-yamamoto/Downloads/old/yamazon_work-20181001T081335Z-001.zip

全文検索の使い方

~/(ホームディレクトリ)から、ファイルの中身に"yamazon"を含むファイルを検索
-name を外し、引数にファイルの中身に含む文字列を書きます

# コマンド
mdfind -onlyin ~/ "yamazon"

# 結果(ファイルの中身に"yamazon"を含むファイルが出る)
/Users/t-yamamoto/yamazon
/Users/t-yamamoto/Library/Mobile Documents/com~apple~Keynote/Documents/powershell勉強会.key
/Users/t-yamamoto/Downloads/old/yamazon_work-20181001T081335Z-001.zip

組み合わせる(全文検索 + ファイル名検索)

全文検索した結果のファイルリストをgrepするしかないです

# コマンド
mdfind -onlyin ~/ yamazon |grep -e ".key$"

# 結果(ファイルの中身に"yamazon"を含むファイルのうち、拡張子.keyのファイルが出る)
/Users/t-yamamoto/Library/Mobile Documents/com~apple~Keynote/Documents/powershell勉強会.key

以上

25
17
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
25
17