0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【find】こんなコマンドあったら嬉しいと思っていたら見つけた

0
Last updated at Posted at 2020-04-02

はじめに

ターミナルから、自分が探したいソースを探せたらいいのになと思ってた時に
見つけたコマンド。

コマンド

# 検索したいディレクトリの、検索したい拡張子かつ、そのファイル内の'ほげ'が何行目に書かれているか探す。
find ファイルパス -name "*.php" | xargs grep 'ほげ' -ns

ファイルパス
検索したいディレクトリを指定。

-name
拡張子がphpのものに絞る。

パイプ(|)
コマンドとコマンドを繋ぐもの

xargs
パイプで繋いだ前のコマンド(コマンド1)で取得した値を利用してxargsで指定した別のコマンド(コマンド2)に引数として渡して実行させる事ができるコマンド。

grep
ファイルの中の文字列を検索

-n
行番号を表示

-s
ファイルがない時、エラーを表示させないようにする。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?