2

I know I can redirect all terminal output to a file, but does that work the other way around?

Can I have a terminal window open, in Tmux or elsewhere, that is receiving redirected output from a file in real time? IE if another process is writing to the file, this is being directed to a terminal window?

Use case: REPL swamped by output

The reason I would like this is I would like to see the output of some code in a REPL (Erlang it turns out) which has many processes creating terminal output stuff in background, but this output is very rapid and I "lose" my REPL command line constantly as it is drowned by the output. So I'd like those processes to output to a file instead, but, in another terminal, I still want to see what that output is in real time.

Thomas Browne
  • 316
  • 2
  • 7
  • 24
  • 1
    Possibly related: [Displaying a “scrolling” log file](https://askubuntu.com/questions/61283/displaying-a-scrolling-log-file) – steeldriver Oct 28 '18 at 18:22
  • Interestingly, while `tail -f` works fine with appending to the fille using `>>`, if I open the file in Vim and add to it, it doesn't work. Just sayin'. Haven't tested with Erlang yet but it's coming up. – Thomas Browne Oct 28 '18 at 18:31
  • aha! I need to use `-F` in that case, because it appears that vim closes and then reopens the file. Okay good news. Isn't Linux foxtrot wonderful! – Thomas Browne Oct 28 '18 at 18:32
  • @cat though the answers are the same, I think my question is phrased for a much broader use case than "watching a log file" and so may find better traction on search engines. – Thomas Browne Oct 28 '18 at 19:44
  • "Traction on search engines" is exactly why we have duplicates. – muru Oct 28 '18 at 21:07
  • @muru. I don't understand. So even if my question is erased, it will still "hang around" somewhere invisible and point to the original answer in some search engine-trackable way? – Thomas Browne Oct 28 '18 at 21:11
  • Closing as a duplicate doesn't automatically delete them. So, they'll hang around perfectly visible. – muru Oct 28 '18 at 21:12

1 Answers1

3

tail -f is what I was looking for.

touch ~/foo
tail -f ~/foo

now in another terminal:

echo "hello" >> ~/foo
echo "there" >> ~/foo

Works a charm. Now some programs (vim for example) will close and reopen the file and tail -f will not work, so you will not see additions when you save from vim. In this case, use tail -F, which explicitly follows the filename rather than the descriptor.

Thomas Browne
  • 316
  • 2
  • 7
  • 24
  • 1
    Don't forget to [accept your own answer](https://askubuntu.com/help/self-answer) when you're able :) – cat Oct 28 '18 at 19:39