テールコマンドについて
tailコマンドは、ファイルの最後の部分、つまり「tail」を出力します。また、ファイルに書き込まれた新しい情報をリアルタイムで監視し、たとえばシステムログに最新のエントリを表示することもできます。 tailは、Unix、Unixライクなシステム、FreeDOSおよびMSX-DOSで使用できるプログラムで、テキストファイルまたはパイプデータの末尾を表示するために使用されます。デフォルトでは、tailは入力の最後の10行を標準出力に出力します。コマンドラインオプションを使用すると、出力量と単位(行、ブロック、またはバイト)を変更できます。
構文 テールコマンドの
tail [options] <filename>
Code language: HTML, XML (xml)
基本的な使用例 出力と監視用
# Output the default 100 lines
tail /var/log/apache2/access.log
# Outputs the last 10 lines of the file
tail -n 30 /var/log/apache2/access.log
# Outputs the last 100 lines of the file
tail -f /var/log/apache2/access.log
# Outputs the last 100 lines of the file where something
tail -f /var/log/apache2/access.log | grep something
Code language: PHP (php)
テールの使用法出力:
root@webleit:~# tail -n 10 /var/log/auth.log
Feb 23 13:16:36 webleit sshd[5526]: Received disconnect from 172.92.151.71 port 55252:11: Bye Bye [preauth]
Feb 23 13:16:36 webleit sshd[5526]: Disconnected from invalid user 172.92.151.71 port 55252 [preauth]
Feb 23 13:17:01 webleit CRON[5528]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 23 13:17:01 webleit CRON[5528]: pam_unix(cron:session): session closed for user root
Feb 23 13:25:12 webleit sudo: root : TTY=pts/0 ; PWD=/root ; USER=root ; COMMAND=/bin/su
Feb 23 13:25:12 webleit sudo: pam_unix(sudo:session): session opened for user root by sonik(uid=0)
Feb 23 13:25:12 webleit su[5551]: Successful su for root by root
Feb 23 13:25:12 webleit su[5551]: + /dev/pts/0 root:root
Feb 23 13:25:12 webleit su[5551]: pam_unix(su:session): session opened for user root by sonik(uid=0)
Feb 23 13:25:12 webleit su[5551]: pam_systemd(su:session): Cannot create session: Already running in a session
Code language: PHP (php)
結論
この記事では、tailコマンドの使用方法の例をいくつか確認しました。他の良い例を知っている場合は、以下のコメントで教えてください。
この記事を楽しんでいただけたでしょうか。その場合は、このページを以下の星で評価し、YouTubeチャンネルに登録するか、ツイッターでフォローしてください。