0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Linux初心者 自分用find / grep の学習

Posted at

find

ファイルやフォルダを検索するためのコマンド

bash
find 検索する場所 条件

$ find . "*.text"

便利なオプション

-name

ファイル名を指定(大文字小文字区別あり)

-iname

ファイル名を検索(大文字小文字区別なし)

-type f

ファイルのみ探す

-type d

ディレクトリのみ探す

grep

ファイルの中から特定の文字列を探す

bash
grep "探したい文字列" ファイル名

$ grep "password" config.txt

便利なオプション

-r

再帰的に検索(サブディレクトリまで)
##### -n
秒番号も表示

-i

大文字小文字を区別しない

--color

見つけた部分を色付きで表示

組み合わせの例

bash
$ grep -rin --color "error" /home

おまけ エラーを非表示に

bash
2>/dev/null


※つかってみるとこんな感じ

$ grep -r "error" . 2>/dev/null

$ find /home -name "test.txt" 2>/dev/null

おわりに

暗記するというよりも何度も使って徐々に覚える
この辺が余裕になってきたら新しい知識をインプットする
急いで全部一気にインプットしない
無意識に打てるように繰り返し使う

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?