LoginSignup
0
0

More than 5 years have passed since last update.

Linux 特定文字を含むファイルを検索するには

Posted at

【Linux】複数あるファイルの中から特定の文字列を検索するコマンド

$ find ./ -type f -print | xargs grep 'hoge'

【上記コマンドの説明】

find

find の次で指定したディレクトリ以下のファイルを検索する。 ファイル検索の構文は「find [path] [検索条件] [アクション]」

./

今いるディレクトリ以下が検索対象。「~/」とするとホームディレクトリ以下が検索対象となる。 ./ の代わりにフルパスでも可。この場合も指定したディレクトリ以下が検索対象になる。

-print

検索結果を標準出力する。このとき結果をフルパスで表示する

-type f

指定したファイルタイプを検索する。fが通常ファイルを,cまたはdとするとディレクトリを,lとするとシンボリック・リンクを検索します。

xargs

標準入力からコマンドラインを作成し、それを実行する

grep

ファイルから文字列を検索する。grep の後に検索したい文字列を指定する。

0
0
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
0