Saturday, May 4, 2024
37
rated 0 times [  37] [ 0]  / answers: 1 / hits: 25712  / 1 Year ago, wed, january 25, 2023, 4:25:28

Via command line, I have a log file I'd like to keep track of.



What I want is to have, basically, a tail that refreshes when the log is updated making the text scroll upwards as new lines are appended to the log file.



Is there anything out there that does that without having to write some code?


More From » command-line

 Answers
4

tail has the -f option:



From the man page:




-f, --follow[={name|descriptor}]
output appended data as the file grows; -f, --follow,
and --follow=descriptor are equivalent




Thus if you type:



tail -f [path_and_name_of_logfile] - you will see the output in the terminal as the log file itself is appended to.



N.B. [path_and_name_of_logfile] is the parameter, so to give an example:



tail -f /var/log/messages



If you combine with the -n [number_of_lines] option you can start the output from the last [number_of_lines] in the file - for example



tail -n 10 -f /var/log/Xorg.0.log



enter image description here






Some programs will periodically change their log file, moving the old one to a new name (e.g. log.0) and starting over.



N.B. logrotate does this to log files for other programs that don't do it themselves.



tail -f will continue to follow the old file after it's renamed.



tail -F will follow the file by name, so will switch to follow the new file.


[#43514] Friday, January 27, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aveerakfas

Total Points: 106
Total Questions: 148
Total Answers: 129

Location: Monaco
Member since Sun, Jan 1, 2023
1 Year ago
;