LoginSignup
28
23

More than 5 years have passed since last update.

複数ファイルでも tail -f がしたい

Last updated at Posted at 2014-03-04

概要

複数のファイルをまとめて tail -f しようとしたらスクリプト作成後に、まとめを見つけた。

仕方ないので、リンク先を日本語で紹介してお茶をにごします。

tailコマンドをそのまま使う

tail コマンドは複数のファイルを受け取れるので以下のように書けます。

tail -f f1.log f2.log f3.log

そうすると出力は

==> f1.log <==
hoge

==> f2.log <==
hoge
piyo

==> f3.log <==
hoge

==> f1.log <==
huga

となり、少なければ見やすい反面、ログが多いと読みづらい

multi-tail.sh を作る

出力をまとめて読むのであれば、そういうスクリプトを作ってしまうのが楽。

multi-tail.sh
#!/bin/bash

trap 'kill $(jobs -p)' EXIT
for f in "$@"; do
  tail -f "$f" &
done
wait
bash multi-tail.sh f1.log f2.log f3.log

multitail コマンドをインストール

aptとかHomebrewmultitailというのがある(homebrewしか確認してない)

multitail f1.log f2.log f3.log

出力はtopコマンドみたいに、画面全体を書き換えながら表示されます。

28
23
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
28
23