Displaying standard output and copying to file (tee command)

Command tee writes the standard output and copies it into the specified file or files. Use the tee command to view your output immediately and at the same time, store it for future use.

For example, the following will display the out and write to the ziabs.txt file
ls | tee ziabs.txt
If we want copy to the multiple file just pass the file names in sequence
ps -aux | tee ziabs.txt ps.log

tee with append option

We can use tee with append option for that need to pass the -a flag
ls | tee -a ziabs.txt

Manual page of tee (man tee)

NAME
       tee - read from standard input and write to standard output and files
SYNOPSIS
       tee [OPTION]... [FILE]...
DESCRIPTION
       Copy standard input to each FILE, and also to standard output.
       
       -a, --append
              append to the given FILEs, do not overwrite
        -i, --ignore-interrupts
              ignore interrupt signals
        -p     diagnose errors writing to non pipes
        --output-error[=MODE]
              set behavior on write error.  See MODE below
       --help display this help and exit
       --version
              output version information and exit


Technology Python Programming Entertainment Python3 Linux Web-development Linux-mint Centos 7 Book
ziabs @ 16 Sep 2022