Example 1: Write output to stdout, and also to a file The following command displays output only on the screen stdout. Comments on this entry are closed. Ambar Agrawal December 1, , am. Neil Anghan July 29, , pm. Sumit Chauhan September 3, , pm. Pradip Sabhadiya July 2, , pm. Than x for giving explanation I was searching this from many days.. Nice explanation.. Shakthi September 11, , pm. Such as: cat apache.
The tee command reads standard input stdin and writes it to both standard output stdout and one or more files. Note: To process standard inputs in Linux, you can use the xargs command which can be used in combination with other commands. The tee command is used alone or with additional options. The following sections list the available options and provide command usage examples.
The example below demonstrates the use of tee to create a file that stores information about a network interface while providing the same output in the terminal:. The cat command confirms that tee successfully wrote the output of ifconfig to the file example. If the file used for the command already exists, tee overwrites the previous contents of the file. Use argument -a or --append to add the command output to the end of the file. For example, use the echo command to append a line of text to a file:.
Use tee followed by any number of files to write the same output to each of them:. The example below shows writing the output of the echo command to two files:. The ls command shows that tee successfully created files example1. To tell tee to store the command output in a file and skip the terminal output, use the following syntax:.
In the example bellow, tee creates a file containing the network interface data, skipping the standard output:. Use it to forward the output to another command:.
In the following example, tee stores the output of the ls command to example. We've discussed it's basic usage as well as majority of its command line options here. The tool doesn't have a steep learning curve, so just practice all these examples, and you should be good to go.
For more information, head to the tool's man page. This feature is only available to subscribers. Get your subscription here. Log in or Sign up. On this page Linux tee command Q1. How to use tee command in Linux? How to make sure tee appends information in files? How to make tee write to multiple files? How to make tee redirect output of one command to another?
0コメント