0

Is there a command to output a large file and follow on directly in the shell stdout?

I am aware of less +F or I could simply use tail with an ultimately high n like tail -f -n1000000 if the file is already big, when I call tail but I was wondering if there is a proper way to handle this.

less is not handy in my situation because the files I handle contain carriage returns and the like, which less displays instead of moving the cursor. cat heads the CRbut does not follow and tail -f does not give me the whole picture... basically I guess I am looking for cat -f <single-file>

10
  • tail -f doesn't truncate output, it will just keep displaying whatever has come so far while still displaying what was there earlier in the terminal. How would your cat -f handle multiple files?
    – cryptarch
    Feb 14, 2021 at 21:26
  • 1
    It needs not. Actually I use cat most of the time to display a single file not to concatenate multiple files. My bad.I will try to clarify my question further.
    – Björn
    Feb 14, 2021 at 21:49
  • @fra-san thanks for the link but the other question differs in tail being invoked when the file is still small, if I am not mistaken. My use case involves that I want to follow a file that is already big before I make my call.
    – Björn
    Feb 14, 2021 at 21:56
  • 2
    (Deleted my comment because the solution proposed there throws an error if two or more files are given as arguments; it should be tail -n +1 -f file). That will print the full file and will keep following it, regardless of how big it is. I guess I'm not getting how this is different from what your question is asking for.
    – fra-san
    Feb 14, 2021 at 22:05
  • Mixed up -nx and -n +x. Terribly sorry. Would love to accept your answer as solution if you follow up on your comment. Or mark as duplicate if I found a matching question. Open to suggestions :-)
    – Björn
    Feb 14, 2021 at 22:14

1 Answer 1

1

A collection of suggestions:

  • From How do I "cat and follow" a file? (noting that the accepted answer, there, uses the obsolete tail -[num][bcl][f] [file] syntax1):

    tail -n +1 -f file
    

    It prints the whole file and then keeps following it.

    • As noted by user414777 in a comment, tail doesn't need to care about newline characters in your case and starting from the first byte may be a better option:

      tail -c +1 -f file
      
  • As noted by Kamil Maciorowski in a comment, an alternative could be:

    less -r +F 
    

1 See, for reference, the compatibility notes in the GNU tail documentation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .