Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script log file display to 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 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.

like image 510
Aaron Murray Avatar asked May 26 '11 19:05

Aaron Murray


People also ask

How do I view continuous logs in Linux?

Press Shift-F. This will take you to the end of the file, and continuously display new contents. In other words, it behaves just like tail -f. To scroll backwards, you must first exit the follow mode by pressing Control-c.

What is $@ in bash script?

bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.

How do you keep a script running in Linux?

Running shell command or script in background using nohup command. Another way you can run a command in the background is using the nohup command. The nohup command, short for no hang up, is a command that keeps a process running even after exiting the shell.


2 Answers

Try the tail command:

tail -f filename 
like image 158
Hai Vu Avatar answered Oct 11 '22 02:10

Hai Vu


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

like image 26
osgx Avatar answered Oct 11 '22 02:10

osgx