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?

ログをリアルタイムで追いかける tail -f コマンドの使い方

Posted at

アプリケーションの動作状況をログで確認したくなることがあります。
そんなときに便利なのが、tail -f コマンドです。

tail コマンドとは?

tail は、ファイルの「末尾(tail)」を表示するコマンドです。
デフォルトでは、指定したファイルの最後の10行を出力します。

tail example.log

上記のように実行すると、example.log の末尾10行が表示されます。

-f オプションでリアルタイム追跡

tail-f オプションをつけると、ファイルが更新されるたびに新しい行をリアルタイムで表示してくれます。

tail -f example.log

これにより、ログが更新され続ける様子をリアルタイムで監視できます。
たとえば、リクエストが来たタイミングや、エラーが発生した瞬間をその場で確認できるようになります。

tail -f のリアルタイム追跡を終了するには、Control+C を押します。

応用例

grep と組み合わせることで、特定の行だけを追うこともできます。

tail -f example.log | grep ERROR

上記を実行すると example.log の中で「ERROR」を含む行だけを追跡します。
特に、エラー発生時のログだけをリアルタイムで確認したいときに便利です。

おわりに

tail -f はアプリケーションがどんな動きをしているかを素早く把握できる便利なコマンドです。
ログ監視やデバッグの場面でぜひ活用してみてください。

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?