Watch file output in bash terminal as it is being written to file

I ask this question because I remember very well that I saw someone I was working with and did it before I had a very good understanding of linux and the command line.

I am looking for a way so that the contents of a file that is being updated are sent directly to the terminal, and not just registered. The closest approximation to this is the use of a watch with a tail. I would like updates to be written directly to the terminal while updating the file.

Has anyone seen something like this?

+5
source share
3 answers

Use the tee command - from it man ,

Summary

  tee [OPTION]... [FILE]... 

Description

  Copy standard input to each FILE, and also to standard output. 

Or you can run tail -f in the recorded file to see how it is written ( -f follow).

+7
source

The tee program does exactly what you want. It reads from stdin and displays the data on the terminal, while redirecting it to a file. This is an old UNIX tool and is also available with GNU coretutils .

Redirect the output of process to a file and simultaneously display it on the terminal:

 process | tee output.file 

If you want to add output.file to the file, use the -a option:

 process | tee -a output.file 
+3
source

I often redirect both stdout and stderr of some command, for example (in a batch job)

 make >& _make.out 

then in another terminal I can run

 tail -f _make.out 

it will continuously display the last lines of _make.out , so I will show it in the terminal.

+2
source

Source: https://habr.com/ru/post/1201516/


All Articles