The tee command reads the standard input and simultaneously writes to a standard output, into the file(s).
command | tee options filenames
It takes the following parameters:
options: -a: Appends to the file instead of overriding it.--help: Displays the help message and exits.--version: Displays the version and exits.filename(s): Single or multiple file names separated by a space.Let's take a look at an example.
echo "List of files before executing the tee command"#list files in present directorylsecho "Creating the how_to_ls text file with the tee command"#create a text file with the tee commandman ls | tee how_to_ls.txtecho "List of files after executing the tee command"#list files in present directoryls
In the above code snippet:
tee command with the ls command.man ls and write it into a file how_to_ls.txt using the tee command.tee command with the ls command. We can see in the output, how_to_ls.txt is created.