tail -f issue

Hi,


With this post I would like to ask a question.


When using the 'Tail" command, the Terminal applications only outputs/monitors the last line of a file.

I would like to read and display all lines of a log file in Terminal. I'm using these commands ...


tail -f zebra.log

tail -f -n 1000 zebra.log

The man page doesn't help...

Doesn anyone have any suggestions ...

Thank you

MacBook Pro with Retina display, macOS Sierra (10.12.5)

Posted on Nov 29, 2017 2:11 AM

Reply
Question marked as Top-ranking reply

Posted on Nov 29, 2017 6:05 AM

If you have a regular Unix file then

tail -n +1 -f zebra.log

should do exactly what you want.


But the assumption is that you have a regular Unix text file. What does the follow command say about your file?

file zebra.log

And if you display zebra.log with the following command are there extra control characters in it?

cat -vte zebra.log

out put from 'cat -vte' should show a $ for the line feed at the end of each line

If you have <CR><LF> formatted file, then you will see ^M$ at the end of each line

If you have <CR> formatted file, then it will be one line lots of ^M symbols between what you think should be each line.


I'm suspecting your file might be a <CR> formatted file. And if I'm guessing correctly, then the 'file zebra.log' command is going to display

zebra.log: ASCII text, with CR line terminators

But until you gather the information and let us know, it is just a guess on my part.

8 replies
Question marked as Top-ranking reply

Nov 29, 2017 6:05 AM in response to tmmls

If you have a regular Unix file then

tail -n +1 -f zebra.log

should do exactly what you want.


But the assumption is that you have a regular Unix text file. What does the follow command say about your file?

file zebra.log

And if you display zebra.log with the following command are there extra control characters in it?

cat -vte zebra.log

out put from 'cat -vte' should show a $ for the line feed at the end of each line

If you have <CR><LF> formatted file, then you will see ^M$ at the end of each line

If you have <CR> formatted file, then it will be one line lots of ^M symbols between what you think should be each line.


I'm suspecting your file might be a <CR> formatted file. And if I'm guessing correctly, then the 'file zebra.log' command is going to display

zebra.log: ASCII text, with CR line terminators

But until you gather the information and let us know, it is just a guess on my part.

Nov 29, 2017 6:05 AM in response to BobHarris

Hi Bob, Many thanks for your feedback. It was very helpfull.

I was using AppleScript to write to the log file and used the wrong line seperator command.


This doesn't work:

set myLogLine to myMessage & return


When using ...

set myLogLine to myMessage & linefeed


the tail command works like expected...


So the type of line terminater/seperator you are using is very important.


Many thanks for all your help.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

tail -f issue

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.