I am asking this question because I remember very clearly having seen someone I worked with do this before I had a very good understanding of linux and the command line.
I am looking for a way to have the content of a file that is being updated sent directly to a terminal rather than simply logged. The closest approximation I have to this is using watch with tail. What I would like is to have the updates written directly to the terminal at the same time the file is updated.
Anyone seen something like this?
The simplest way to view text files in Linux is the cat command. It displays the complete contents in the command line without using inputs to scroll through it. Here is an example of using the cat command to view the Linux version by displaying the contents of the /proc/version file.
The '>' symbol is used for output (STDOUT) redirection. Here the output of command ls -al is re-directed to file “listings” instead of your screen. Note: Use the correct file name while redirecting command output to a file.
In Linux, we can use the inotify interface to monitor a directory or a file. We do this by adding a watch to the directory or file.
I often redirect both stdout and stderr of some command, e.g (in abatch
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'll get it shown in the terminal.
Use the command tee
- from it's man
page,
Synopsis
tee [OPTION]... [FILE]...
Description
Copy standard input to each FILE, and also to standard output.
Or, you could run tail -f
on the written file to watch as it is being written (-f
is follow).
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 a the same time. It is an old UNIX tool and also available from GNU coretutils
.
Redirect output of process
to a file and display it on terminal at the same time:
process | tee output.file
If you want to append to output.file use the option -a
:
process | tee -a output.file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With