How to read live writing logs

As a server administrator, we should know this small geek, because we have to use this tail command asa much as possible. For example, if any of hosted site shows some error means, first of all we have to check apache error_log, so that we will come to know, what is happening there and its exact issues.

Now, I’m going to perform this action to apache error_log file. If we face any issues on hosted website, we have to check apache error_log file first, to know the facts and going on issues. All the log files continuously writing, so if we want to view those file’s live update, we need to use tail command.As default, tail command will shows the last 10 lines.

Syntax :

The common syntax for tail command.

Syntax :# tail [-Options] [File-Name]

Options :

Two major option is available.

f : output appended data as the file grows.
n : output the last N lines, instead of the last 10.

1) How to use tail command by default ?

Use the below command to view the apache error_log using tail command.

[email protected] [~]# tail -f /usr/local/apache/logs/error_log
[Fri Feb 28 12:35:08 2014] [error] [client 149.126.76.1] File does not exist: /home/2daygeekc/public_html/new/site/jquery.ui.resizable.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:35:08 2014] [error] [client 149.126.76.1] File does not exist: /home/2daygeekc/public_html/new/site/jquery.ui.selectable.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:35:08 2014] [error] [client 149.126.76.1] File does not exist: /home/2daygeekc/public_html/new/site/jquery.ui.accordion.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:35:09 2014] [error] [client 149.126.76.1] File does not exist: /home/2daygeekc/public_html/new/site/jquery.ui.autocomplete.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:35:09 2014] [error] [client 149.126.76.1] File does not exist: /home/2daygeekc/public_html/new/site/jquery.ui.button.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:35:09 2014] [error] [client 149.126.76.1] File does not exist: /home/2daygeekc/public_html/new/site/jquery.ui.dialog.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:35:09 2014] [error] [client 149.126.76.1] File does not exist: /home/2daygeekc/public_html/new/site/jquery.ui.slider.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:35:09 2014] [error] [client 149.126.76.1] File does not exist: /home/2daygeekc/public_html/new/site/jquery.ui.tabs.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:35:09 2014] [error] [client 149.126.76.1] File does not exist: /home/2daygeekc/public_html/new/site/jquery.ui.progressbar.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:35:19 2014] [error] [client 198.143.38.1] File does not exist: /home/2daygeekc/public_html/new/site/jquery.ui.progressbar.css, referer: https://www.2daygeek.com/test-mail-script.php

The above output shows only last 10 lines.

2) How to use tail command with (-n) Option ?

Use the below command to view the apache error_log using tail command with (-n) Option.

[email protected] [~]# tail -n 20 -f /usr/local/apache/logs/error_log
[Fri Feb 28 12:38:15 2014] [error] [client 198.143.38.33] File does not exist: /home/2daygeekc/public_html/new/loading2.gif, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:38:19 2014] [error] [client 198.143.44.1] File does not exist: /home/magesh/public_html/new/quizdashboard_viewdb.php, referer: http://www.magesh.co.in/myaccount_js.php
[Fri Feb 28 12:38:25 2014] [error] [client 149.126.76.1] File does not exist: /home/2daygeekc/public_html/new/loading2.gif, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:38:29 2014] [error] [client 198.143.44.33] File does not exist: /home/2daygeekc/public_html/new/base/jquery.ui.resizable.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:38:29 2014] [error] [client 198.143.44.33] File does not exist: /home/2daygeekc/public_html/new/base/jquery.ui.selectable.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:38:30 2014] [error] [client 198.143.44.33] File does not exist: /home/2daygeekc/public_html/new/base/jquery.ui.accordion.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:38:31 2014] [error] [client 198.143.44.33] File does not exist: /home/2daygeekc/public_html/new/base/jquery.ui.button.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:38:31 2014] [error] [client 198.143.44.33] File does not exist: /home/2daygeekc/public_html/new/base/jquery.ui.autocomplete.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:38:32 2014] [error] [client 198.143.44.1] File does not exist: /home/magesh/public_html/new/css/images, referer: http://www.magesh.co.in/myaccount_js.php
[Fri Feb 28 12:38:33 2014] [error] [client 198.143.44.33] File does not exist: /home/2daygeekc/public_html/new/base/jquery.ui.dialog.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:38:33 2014] [error] [client 198.143.44.33] File does not exist: /home/2daygeekc/public_html/new/base/jquery.ui.slider.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:38:33 2014] [error] [client 198.143.44.33] File does not exist: /home/2daygeekc/public_html/new/base/jquery.ui.tabs.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:38:36 2014] [error] [client 198.143.44.33] File does not exist: /home/2daygeekc/public_html/new/base/jquery.ui.progressbar.css, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:38:40 2014] [error] [client 198.143.44.1] File does not exist: /home/magesh/public_html/new/css/images, referer: http://www.magesh.co.in/myaccount_js.php
[Fri Feb 28 12:38:45 2014] [error] [client 198.143.44.1] File does not exist: /home/magesh/public_html/new/css/images, referer: http://www.magesh.co.in/myaccount_js.php
[Fri Feb 28 12:39:21 2014] [error] [client 198.143.44.33] File does not exist: /home/2daygeekc/public_html/new/icons, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:39:22 2014] [error] [client 198.143.44.33] File does not exist: /home/2daygeekc/public_html/new/loading2.gif, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:39:22 2014] [error] [client 198.143.44.33] File does not exist: /home/2daygeekc/public_html/new/icons, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:39:36 2014] [error] [client 198.143.38.33] File does not exist: /home/2daygeekc/public_html/new/loading2.gif, referer: https://www.2daygeek.com/test-mail-script.php
[Fri Feb 28 12:39:37 2014] [error] [client 198.143.38.33] File does not exist: /home/magesh/public_html/new/job-vacancies, referer: http://www.magesh.co.in/myaccount_js.php

The above output shows only last 20 lines.

3) How to stop tail command ?

Use ctrl+c key to exit the tail command.

We are preparing all articles in-depth to understand by all level/stage Linux administrators. If the article is useful for you, then please spend less than a minute to share your valuable comments in our commenting section.

Please stay tune with us…Good Luck 🙂

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...