LoginSignup
841
745

More than 5 years have passed since last update.

【find・grep】特定の文字列を含むファイルのリストを取得する方法。

Last updated at Posted at 2016-10-12

「○○」という文字列を含むファイルをリスト化したい時は、以下のコマンドで。
毎回ぐぐってるので、いいかげんメモ。

■ファイル名に「○○」という文字列が含まれているファイルのリストを取得。

指定フォルダ直下のみ
ls [検索対象フォルダのパス] | grep "[検索したい文字列]"
指定フォルダ配下を再帰検索
find [検索対象フォルダのパス] -type f -name "*[検索したい文字列]*"

■ファイルを開いた中身に、「○○」という文字列が含まれているファイルのリスト。

指定フォルダ配下を再帰検索
grep [検索したい文字列] -rl [検索対象フォルダのパス]

※いままで↓を使っていましたが、コメントで上記grepコマンドを使う方法を教えていただきました。(こっちの方が簡単!)

指定フォルダ配下を再帰検索
find [検索対象フォルダのパス] -type f -print | xargs grep '[検索したい文字列]'
841
745
5

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
841
745