{"id":13857,"date":"2019-04-06T11:57:23","date_gmt":"2019-04-06T11:57:23","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13857"},"modified":"2019-04-06T11:57:23","modified_gmt":"2019-04-06T11:57:23","slug":"4-ways-to-watch-or-monitor-log-files-in-real-time","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/06\/4-ways-to-watch-or-monitor-log-files-in-real-time\/","title":{"rendered":"4 Ways to Watch or Monitor Log Files in Real Time"},"content":{"rendered":"<p>How can I see the content of a log file in real time in Linux? Well there are a lot of utilities out there that can help a user to output the content of a file while the file is changing or continuously updating. Some of the most known and heavily used utility to display a file content in real time in Linux is the\u00a0<a href=\"https:\/\/www.tecmint.com\/view-contents-of-file-in-linux\/\" target=\"_blank\" rel=\"noopener\">tail command<\/a>\u00a0(manage files effectively).<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/best-linux-log-monitoring-and-management-tools\/\" target=\"_blank\" rel=\"noopener\">4 Good Open Source Log Monitoring and Management Tools for Linux<\/a><\/p>\n<h3>1. tail Command \u2013 Monitor Logs in Real Time<\/h3>\n<p>As said,\u00a0<strong>tail command<\/strong>\u00a0is the most common solution to display a log file in real time. However, the command to display the file has two versions, as illustrated in the below examples.<\/p>\n<p>In the first example the command\u00a0<strong>tail<\/strong>\u00a0needs the\u00a0<code>-f<\/code>\u00a0argument to follow the content of a file.<\/p>\n<pre>$ sudo tail -f \/var\/log\/apache2\/access.log\r\n<\/pre>\n<div id=\"attachment_27697\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Monitor-Apache-Logs-in-Real-Time.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27697\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Monitor-Apache-Logs-in-Real-Time.png\" sizes=\"auto, (max-width: 788px) 100vw, 788px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Monitor-Apache-Logs-in-Real-Time.png 788w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Monitor-Apache-Logs-in-Real-Time-768x274.png 768w\" alt=\"Monitor Apache Logs in Real Time\" width=\"788\" height=\"281\" aria-describedby=\"caption-attachment-27697\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27697\" class=\"wp-caption-text\">Monitor Apache Logs in Real Time<\/p>\n<\/div>\n<p>The second version of the command is actually a command itself:\u00a0<strong>tailf<\/strong>. You won\u2019t need to use the\u00a0<code>-f<\/code>\u00a0switch because the command is built-in with the\u00a0<code>-f<\/code>\u00a0argument.<\/p>\n<pre>$ sudo tailf \/var\/log\/apache2\/access.log\r\n<\/pre>\n<div id=\"attachment_27698\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Apache-Logs-Monitoring.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27698\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Apache-Logs-Monitoring.png\" sizes=\"auto, (max-width: 870px) 100vw, 870px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Apache-Logs-Monitoring.png 870w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Apache-Logs-Monitoring-768x341.png 768w\" alt=\"Real Time Apache Logs Monitoring\" width=\"870\" height=\"386\" aria-describedby=\"caption-attachment-27698\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27698\" class=\"wp-caption-text\">Real Time Apache Logs Monitoring<\/p>\n<\/div>\n<p>Usually, the log files are rotated frequently on a Linux server by the logrotate utility. To watch log files that get rotated on a daily base you can use the\u00a0<code>-F<\/code>\u00a0flag to\u00a0<strong>tail command<\/strong>.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/manage-linux-system-logs-using-rsyslogd-and-logrotate\/\" target=\"_blank\" rel=\"noopener\">How to Manage System Logs (Configure, Rotate and Import Into Database) in Linux<\/a><\/p>\n<p>The\u00a0<code>tail -F<\/code>\u00a0will keep track if new log file being created and will start following the new file instead of the old file.<\/p>\n<pre>$ sudo tail -F \/var\/log\/apache2\/access.log\r\n<\/pre>\n<p>However, by default,\u00a0<strong>tail command<\/strong>\u00a0will display the last\u00a0<strong>10<\/strong>\u00a0lines of a file. For instance, if you want to watch in real time only the last two lines of the log file, use the\u00a0<code>-n<\/code>\u00a0file combined with the\u00a0<code>-f<\/code>\u00a0flag, as shown in the below example.<\/p>\n<pre>$ sudo tail -n2 -f \/var\/log\/apache2\/access.log\r\n<\/pre>\n<div id=\"attachment_27699\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Watch-Last-Two-Lines-of-Log.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27699\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Watch-Last-Two-Lines-of-Log.png\" sizes=\"auto, (max-width: 776px) 100vw, 776px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Watch-Last-Two-Lines-of-Log.png 776w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Watch-Last-Two-Lines-of-Log-768x105.png 768w\" alt=\"Watch Last Two Lines of Logs\" width=\"776\" height=\"106\" aria-describedby=\"caption-attachment-27699\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27699\" class=\"wp-caption-text\">Watch Last Two Lines of Logs<\/p>\n<\/div>\n<h3>2. Multitail Command \u2013 Monitor Multiple Log Files in Real Time<\/h3>\n<p>Another interesting command to display log files in real time is\u00a0<a href=\"https:\/\/www.tecmint.com\/view-multiple-files-in-linux\/\" target=\"_blank\" rel=\"noopener\">multitail command<\/a>. The name of the command implies that\u00a0<strong>multitail utility<\/strong>\u00a0can monitor and keep track of multiple files in real time. Multitail also lets you navigate back and forth in the monitored file.<\/p>\n<p>To install\u00a0<strong>mulitail utility<\/strong>\u00a0in Debian and RedHat based systems issue the below command.<\/p>\n<pre>$ sudo apt install multitail   [On Debian &amp; Ubuntu]\r\n$ sudo yum install multitail   [On RedHat &amp; CentOS]\r\n$ sudo dnf install multitail   [On Fedora 22+ version]\r\n<\/pre>\n<p>To display the output of two log file simultaneous, execute the command as shown in the below example.<\/p>\n<pre>$ sudo multitail \/var\/log\/apache2\/access.log \/var\/log\/apache2\/error.log\r\n<\/pre>\n<div id=\"attachment_27700\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Multitail-Monitor-Logs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27700\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Multitail-Monitor-Logs.png\" sizes=\"auto, (max-width: 830px) 100vw, 830px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Multitail-Monitor-Logs.png 830w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Multitail-Monitor-Logs-768x589.png 768w\" alt=\"Multitail Monitor Logs\" width=\"830\" height=\"637\" aria-describedby=\"caption-attachment-27700\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27700\" class=\"wp-caption-text\">Multitail Monitor Logs<\/p>\n<\/div>\n<h3>3. lnav Command \u2013 Monitor Multiple Log Files in Real Time<\/h3>\n<p>Another interesting command, similar to\u00a0<strong>multitail command<\/strong>\u00a0is the\u00a0<a href=\"https:\/\/www.tecmint.com\/lnav-watch-and-analyze-apache-logs-in-linux\/\" target=\"_blank\" rel=\"noopener\">lnav command<\/a>.\u00a0<strong>Lnav utility<\/strong>\u00a0can also watch and follow multiple files and display their content in real time.<\/p>\n<p>To install lnav utility in Debian and RedHat based Linux distributions by issuing the below command.<\/p>\n<pre>$ sudo apt install lnav   [On Debian &amp; Ubuntu]\r\n$ sudo yum install lnav   [On RedHat &amp; CentOS]\r\n$ sudo dnf install lnav   [On Fedora 22+ version]\r\n<\/pre>\n<p>Watch the content of two log files simultaneously by issuing the command as shown in the below example.<\/p>\n<pre>$ sudo lnav \/var\/log\/apache2\/access.log \/var\/log\/apache2\/error.log\r\n<\/pre>\n<div id=\"attachment_27701\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Lnav-Real-Time-Logs-Monitoring.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27701\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Lnav-Real-Time-Logs-Monitoring.png\" sizes=\"auto, (max-width: 990px) 100vw, 990px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Lnav-Real-Time-Logs-Monitoring.png 990w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Lnav-Real-Time-Logs-Monitoring-768x217.png 768w\" alt=\"lnav - Real Time Logs Monitoring\" width=\"990\" height=\"280\" aria-describedby=\"caption-attachment-27701\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27701\" class=\"wp-caption-text\">lnav \u2013 Real Time Logs Monitoring<\/p>\n<\/div>\n<h3>4. less Command \u2013 Display Real Time Output of Log Files<\/h3>\n<p>Finally, you can display the live output of a file with\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-more-command-and-less-command-examples\/\" target=\"_blank\" rel=\"noopener\">less command<\/a>\u00a0if you type\u00a0<code>Shift+F<\/code>.<\/p>\n<p>As with\u00a0<strong>tail utility<\/strong>, pressing\u00a0<code>Shift+F<\/code>\u00a0in a opened file in\u00a0<strong>less<\/strong>\u00a0will start following the end of the file. Alternatively, you can also start less with less\u00a0<code>+F<\/code>\u00a0flag to enter to live watching of the file.<\/p>\n<pre>$ sudo less +F  \/var\/log\/apache2\/access.log\r\n<\/pre>\n<div id=\"attachment_27702\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Watch-Logs-Using-Less-Command.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27702\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Watch-Logs-Using-Less-Command.png\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Watch-Logs-Using-Less-Command.png 940w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/Watch-Logs-Using-Less-Command-768x396.png 768w\" alt=\"Watch Logs Using Less Command\" width=\"940\" height=\"485\" aria-describedby=\"caption-attachment-27702\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27702\" class=\"wp-caption-text\">Watch Logs Using Less Command<\/p>\n<\/div>\n<p>That\u2019s It! You may read these following articles on Log monitoring and management.<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/view-contents-of-file-in-linux\/\" target=\"_blank\" rel=\"noopener\">Manage Files Effectively using head, tail and cat Commands in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/install-logrotate-to-manage-log-rotation-in-linux\/\" target=\"_blank\" rel=\"noopener\">How to Setup and Manage Log Rotation Using Logrotate in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/petiti-log-analysis-tool-for-linux-sysadmins\/\" target=\"_blank\" rel=\"noopener\">Petiti \u2013 An Open Source Log Analysis Tool for Linux SysAdmins<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/query-audit-logs-using-ausearch-tool-on-centos-rhel\/\" target=\"_blank\" rel=\"noopener\">How to Query Audit Logs Using \u2018ausearch\u2019 Tool on CentOS\/RHEL<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/manage-systemd-logs-using-journalctl\/\" target=\"_blank\" rel=\"noopener\">Manage Log Messages Under Systemd Using Journalctl [Comprehensive Guide]<\/a><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>In this article, we showed how to watch data being appended in log files in real-time on the terminal in Linux. You can ask any questions or share your thoughts concerning this guide via the comment form below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/watch-or-monitor-linux-log-files-in-real-time\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How can I see the content of a log file in real time in Linux? Well there are a lot of utilities out there that can help a user to output the content of a file while the file is changing or continuously updating. Some of the most known and heavily used utility to display &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/06\/4-ways-to-watch-or-monitor-log-files-in-real-time\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;4 Ways to Watch or Monitor Log Files in Real Time&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13857","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13857","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13857"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13857\/revisions"}],"predecessor-version":[{"id":13858,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13857\/revisions\/13858"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}