The Linux commands I used

Source: Internet
Author: User

I used the Linux command tee-redirect output to multiple file usage notes

When we execute the Linux command, we can redirect the output to the file, such as LS >a.txt, when we can not see the output, if we want to save the output to the file, but also want to see the output on the screen, it is possible to use the tee command. The tee command reads the standard input and outputs the contents to both standard output and (multiple) files (read from, the. Input and write to standards output and files. Copy standard input to the FILE, and also to standard output. If a FILE is-, copy again to standard output.). said in Info tee: The tee command can redirect standard output to multiple files (' tee ': Redirect output to multiple files.  The ' Tee ' command copies standard input to standard output and also to any files given as arguments. This is useful if you want not only to send some data down a pipe, but also to save a copy.). Note that the standard error output of the previous command is not read by the tee when using a pipe line.

Common parameters

Format: Tee

Output to standard output only, because no files are specified.

Format: Tee file

Output to the standard output, save to file. If the file does not exist, it is created or overwritten if it already exists. (If a file being written to does isn't already exist, it is created.) If a file being written to already exists, the data it previously
Contained is overwritten unless the '-a ' option is used.)

Format: Tee-a file

Output to the standard output, appended to the file. If the file does not exist, it is created, or if it already exists, appends the content to the end instead of overwriting it.

Format: Tee-

Output to standard output two times. (A FILE of '-' causes ' tee ' to send another copy of input to standard output, it is typically not useful as the Copies is interleaved.)

Format: Tee file1 file2-

Output to standard output two times, while saving to File1 and file2.

Using the sample example a tee command vs. redirection

[[email protected] ~]# SEQ 5 >1.txt
[email protected] ~]# cat 1.txt
1
2
3
4
5
[email protected] ~]# cat 1.txt >2.txt
[email protected] ~]# Cat 1.txt | Tee 3.txt
1
2
3
4
5
[email protected] ~]# cat 2.txt
1
2
3
4
5
[email protected] ~]# cat 3.txt
1
2
3
4
5
[email protected] ~]# cat 1.txt >>2.txt
[email protected] ~]# Cat 1.txt | Tee-a 3.txt
1
2
3
4
5
[email protected] ~]# cat 2.txt
1
2
3
4
5
1
2
3
4
5
[email protected] ~]# cat 3.txt
1
2
3
4
5
1
2
3
4
5
[Email protected] ~]#

Example two repeating the output string with the tee command

[Email protected] ~]# echo 12345 | Tee
12345

[Email protected] ~]# echo 12345 | Tee-
12345
12345
[Email protected] ~]# echo 12345 | Tee--
12345
12345
12345
[Email protected] ~]# echo 12345 | Tee---
12345
12345
12345
12345
[Email protected] ~]# echo 12345 | Tee----
12345
12345
12345
12345
12345
[Email protected] ~]#

[[email protected] ~]# Echo-n 12345 | Tee

12345[[email protected] ~]# echo-n 12345 | Tee-
1234512345[[email protected] ~]# echo-n 12345 | Tee--
123451234512345[[email protected] ~]# echo-n 12345 | Tee---
12345123451234512345[[email protected] ~]# echo-n 12345 | Tee----
1234512345123451234512345[[email protected] ~]#

Example three using the tee command to save the standard error output to a file

[[email protected] ~]# ls "*"
LS: *: no file or directory
[[email protected] ~]# ls "*" | Tee-
LS: *: no file or directory
[[email protected] ~]# ls "*" | Tee Ls.txt
LS: *: no file or directory
[email protected] ~]# cat Ls.txt
[[email protected] ~]# ls "*" 2>&1 | Tee Ls.txt
LS: *: no file or directory
[email protected] ~]# cat Ls.txt
LS: *: no file or directory
[Email protected] ~]#

Original Reprint Address: http://codingstandards.iteye.com/blog/833695

The Linux commands I used

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.