Bash script display log file on screen continuously

I am creating an application that writes to a log file, and I need to know how in Linux / Bash to continuously display the log file on the screen (screen update with each new line placed in the log).

As an example, let's say I want to constantly update the current apache/error.log on the screen (ssh terminal).

+52
linux bash logging
May 26 '11 at 19:14
source share
5 answers

Try the tail command:

 tail -f filename 
+79
May 26 '11 at 19:16
source share

Another solution is

  less +F filename 

or just less filename and typing "F" in it (by pressing shift + f ). It may be better than tail , as it allows you to temporarily cancel continuous printing, go back to see something, and turn it on again with "F" ( shift + f ) again

+20
May 26 '11 at 19:24
source share

The watch command can also be useful.

 watch tail logfile 

Will show you the last 5 lines of the log file. It can be expanded to any command that prints material to standard output.

Yes, using tail -f is a traditional solution, but depending on what you are trying to do, this may work better.

+8
May 26 '11 at 19:28
source share

ssh {remotehost} tail -n0f {logfile}

This will give you zero lines initially and will continuously print any new lines that appear in the file.

+5
May 26 '11 at 19:17
source share

You also can:

 less filename.txt and press 'F' 

has one plus - you can CTRL-C at any time and scroll back in the log and look again with "F".

+5
May 26 '11 at 19:25
source share



All Articles