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>

Björn
  • 158
  • 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 '21 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 '21 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 '21 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 '21 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 '21 at 22:14
  • Considering that questions are often considered duplicates if they share the same answers (regardless of the specific issues they try to solve), I'd personally make this a duplicate of that one. – fra-san Feb 14 '21 at 22:23
  • How about less -r +F? – Kamil Maciorowski Feb 14 '21 at 22:25
  • @fra-san I'd suggest you make it an answer. The other question uses a syntax that will not work for everybody and it relates another problem. If I were trying to solve the OP's question I'd rather have the straight answer here and not have to get to the comments of the accepted solution to find out the right syntax is -n +1 -f. – Eduardo Trápani Feb 14 '21 at 22:48
  • @Björn instead of tailing by lines (which is causing tail to pointlessly "parse" your file, unlike cat), tail it by bytes: tail -fc+1 file. –  Feb 15 '21 at 00:43
  • @user414777, I don't expect tail -fc+1 and tail -fn+1 will be much different, the first one tells tail to skip 0 byte before starting the tail -f loop and the second one to skip 0 line before starting the tail -f loop. In both cases, that just tells tail to enter the tail -f loop straight away. – Stéphane Chazelas Feb 15 '21 at 18:16

1 Answers1

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.

fra-san
  • 10,205
  • 2
  • 22
  • 43