0
2

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 1 year has passed since last update.

ログ調査等で便利なLinuxコマンド組合せ例(grep,less,wc)

Last updated at Posted at 2023-11-30

はじめに

メールサーバー等でログ調査をする際、
自身が頻繁に使用するコマンド概要の覚書を残します。
(正規表現等もっと細かい使用方法を知りたい方向けではありません)

コマンドに登場する以下の箇所は任意に置き換えてください。
・「search_word1」
 ┗ 検索したい文字列1:例/warning xx 等 を指定してください。

・「search_word2」
 ┗ 検索したい文字列2:例/Status = xx 等 を指定してください。

・「dir1/dir2」異なるディレクトリからパスでファイルを指定する場合に使用します。
 ┗ ※cdで移動したカレントディレクトリにファイルが存在する場合は不要です。

・「test.log」ファイルを指定します。
 ┗ 拡張子は .txt 等テキストで内容を確認できる拡張子であれば問題ありません。

コマンド

# 複数条件(AND)で検索し、結果を画面表示する(.txtでも使用可能)
grep "search_word1" /dir1/dir2/test.log | grep "search_word2" | less

# 複数条件(AND)で検索し、該当行数を出力する(.txtでも使用可能)
grep "search_word1" /dir1/dir2/test.log | grep "search_word2" | wc -l

# 複数条件(OR)で検索し、結果を画面表示する(.txtでも使用可能)
grep -e "search_word1" -e "search_word2" /dir1/dir2/test.log | less

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?