LoginSignup
0
0
はじめての記事投稿

【Linux】ディレクトリ内の全ファイルからテキスト検索

Last updated at Posted at 2023-07-20

結論

find 検索対象ディレクトリPATH -type f | xargs grep -a 検索対象テキスト --color=auto

実行環境

NAME="AlmaLinux"
VERSION="9.2 (Turquoise Kodkod)"

各コマンド説明

find 検索ディレクトリPATH -type f
ファイルのみのPATH一覧を表示

xargs grep -a 検索文字列 --color=auto
xargs : パイプ(|)前の出力を受け取って、引数として渡す。
実行されるコマンド:grep -a 検索対象テキスト --color=auto 標準出力(ファイルPATH)

grep
grep 検索文字列 ファイル名でファイル内で検索文字列を含む行を返す

-a オプション:テキストファイルであることを明示する。
       付けないとgrep: (standard input): binary file matchesと表示された。

--color=auto オプション:検索結果がハイライト表示されて分かりやすい

参考

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