Bash script log file display to screen continuously
LinuxBashLoggingLinux Problem Overview
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 to the screen (updating the screen with every new line put into the log).
So as an example, lets say I want to push a running log of apache/error.log
to the screen (ssh terminal) continuously updating.
Linux Solutions
Solution 1 - Linux
Try the tail command:
tail -f filename
Solution 2 - Linux
Another solution is
less +F filename
or just less filename
and typing "F" into it (pressing shift+f). It can be better than tail
, because it allows you to cancel continuous printing temporary, go backward to look something and reenable it with "F" (shift+f) again
Solution 3 - Linux
The watch command can also be of use.
watch tail logfile
Would show you the last 5 lines of the log file. It can be extended to any command which prints stuff to stdout.
Yes, using tail -f
is the traditional solution, but depending on what you are trying to do, this might work better.
Solution 4 - Linux
ssh {remotehost} tail -n0f {logfile}
This will give you zero lines initially, and continuously print any new lines that appear in the file.
Solution 5 - Linux
You can also:
less filename.txt
and press 'F'
has one plus - you can anytime CTRL-C and scroll back in log and start watching again with the 'F'.