cmd line tutorials - gencmd

cmd line tutorials - gencmd

The tee Command

Unix-Linux Mac

The tee is used to redirect the standard output of a command to a file and to standard output. It is a very useful tool for logging the output of commands and for creating backup copies of files.

Syntax

The basic syntax for the tee command is as follows:

tee [options] <file>

The <file> argument is the path to the file where you want to redirect the standard output of the command.

Examples

Redirect the output of the ls command to the file myfile.txt.

ls | tee file.txt

Log the output of the tail command to the file system.log.

tail -f /var/log/syslog | tee system.log

Append to the file instead of overwriting the file.

ls | tee -a file.txt

With gencmd

gencmd -c tee list files on stdout and save it to a file

  • ls -l | tee file.txt
  • ls | tee file.txt