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?

More than 1 year has passed since last update.

リアルタイムでログを出す tail -f ファイル名

Posted at

こんな人におすすめ

・サーバー上でlogファイルがどの操作によって発生したのか切り分けをしたい人

tail -f ファイル名

打つコマンドは、「tail -f 追跡したいファイル名」です。
例えば、ログディレクトリに、log01というものがあって、このログファイルを追跡したい場合
「tail -f log.01」と打ちます。

[root@ip-〇〇] tail -f log.01
[2023/01/13 09:00:00]ログ内容       //tail -f log.01を打った時のファイル内容
[2023/01/13 09:00:01]ログ内容       //tail -f log.01を打った時のファイル内容
[2023/01/13 09:00:02]ログ内容       //tail -f log.01を打った時のファイル内容

                         
この後に何かログに吐かれるような動作(操作A)を画面で行うと下記のように操作とファイル内容を切り出しすることが可能です。
tail -fコマンドを使用した後は、Enterを3回ほど押して、操作とログを離しておくとより見やすいかと思います。
そうすると下記のようになります。

[root@ip-〇〇] tail -f log.01
[2023/01/13 09:00:00]ログ内容       //tail -f log.01を打った時のファイル内容
[2023/01/13 09:00:01]ログ内容       //tail -f log.01を打った時のファイル内容
[2023/01/13 09:00:02]ログ内容       //tail -f log.01を打った時のファイル内容



[2023/01/13 09:00:02]ログ内容       //操作Aによって吐き出された内容

この追跡モードを終了したい場合は、Windowsの方は「Ctrl + C」、Macの方は「command + C」で終了することができます。

感想

サーバー上でエラーを見ている時に、どの操作によってどのログが吐かれているのか切り分けたいということは多々あるかと思うので、そういう場合はこのコマンド使用すると便利だなと思いました。

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?