tail -f
指定したフォルダ内のログイン ファイルを追跡するために使用しようとしています。簡単なコマンドでこれを行うtail -f [path to file]
ことができますが、フォルダ内の最新/最終変更ファイルを実行して追跡するコマンドを使用する方法はありますか。この分野の専門家ではないので、助けていただければ幸いです。
答え1
コマンドを実行してls -tp | sort | grep -v / | tail -n 1
、for
ループして、tail -F
最新のファイルに対してのみコマンドを実行し、コンテンツの変更を監視します。ls -tpr | grep -v / | tail -n 1
代わりに コマンドの使用も検討してください。
for VAR in $(ls -tp | sort | grep -v / | tail -n 1); do tail -F $VAR; done
または
for VAR in $(ls -tpr | grep -v / | tail -n 1); do tail -F $VAR; done
その他のリソース
-
-t sort by modification time, newest first -p, --indicator-style=slash append / indicator to directories -r, --reverse reverse order while sorting
-
-v, --invert-match Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX .)
-
-n, --lines=[+]NUM output the last NUM lines, instead of the last 10; or use -n +NUM to output starting with line NUM
答え2
使用できる マルチテール多くのディストリビューションで標準パッケージとして利用可能です。
例 1: 2 つのログファイルを異なる色で 1 つのウィンドウにマージする
multitail -ci green /var/log/yum.log -ci yellow -I /var/log/mysqld.log
例 2: 5 つのログファイルを表示し、2 つを 1 つの列にマージする
multitail -s 2 -sn 1,3 /var/log/mysqld.log -I /var/log/xferlog /var/log/monitorix /var/log/ajenti.log /var/log/yum.log