概要
ファイル検索する際に、少し複雑で覚えていないけどよく使うコマンド一覧。
ファイル名に特定の文字列を含むファイルリスト
通常
/path/to/dir
にある、word
という文字列をファイル名に含むファイルリスト
find [検索対象ディレクトリパス] -type f -name "*word*"
特定ディレクトリ除外
/path/to/dir
にある、word
という文字列をファイル名に含むファイルリストで/path/to/dir/backup
と/path/to/dir/error
を除外する場合
find /path/to/dir -type f -name "*word*" | grep -E -v "^/path/to/dir/(backup|error)/"
特定の文字列をファイル内に含むファイルリスト
通常
/path/to/dir
にある、word
という文字列をファイル内に含むファイルリスト
grep [検索したい文字列] -rl [検索対象フォルダのパス]
特定ディレクトリ除外
/path/to/dir
にある、word
という文字列をファイル内に含むファイルリストで/path/to/dir/backup
と`vendorとnode_modulesを除外する場合
grep 'word' -rl /path/to/dir --exclude-dir={vendor,node_modules}