Linux Shell script-tee command

Source: Internet
Author: User

Linux Shell script entry-tee command usage instructions when executing Linux commands, We can redirect the output to a file, such as ls> a.txt. Then we cannot see the output, if we want to save the output to a file and view the output on the screen, we can use the tee command. The tee command reads the standard input and outputs the content to both the standard output and (multiple) files (read from standard input and write to standard output and files. copy standard input to each FILE, and also to standard output. if a FILE is-, copy again to standard output .). In info tee, the tee command can Redirect the 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 when you want not only to send some data down a pipe, but also to save a copy .). Note: When Using MPs queue, the standard error output of the previous command is not read by tee. Common parameter format: tee only outputs to standard output, because no file is specified. Format: When tee file is output to the standard output, it is saved to the file. If the file does not exist, it is created. If the file already exists, it is overwritten. (If a file being written to does not already exist, it is created. if a file being written to already exists, the data it previuslycontained is overwritten unless the '-a' option is used .) format: When tee-a file is output to the standard output, it is appended to the file. If the object does not exist, it is created. If the object already exists, it is appended to the end, rather than overwritten. Format: tee-output to standard output twice. (A file of '-'Causes 'TEE' to send another copy of input to standard output, but this is typically not that useful as the copies are interleaved .) format: tee file1 file2-output to the standard output twice and save it to file1 and file2. Example 1 Comparison Between the tee command and redirection [root @ web ~] # Seq 5> 1.txt [root @ web ~] # Cat 1.txt 12345 [root @ web ~] # Cat 1.txt> 2.txt [root @ web ~] # Cat 1.txt | tee 3.txt 12345 [root @ web ~] # Cat 2.txt 12345 [root @ web ~] # Cat 3.txt 12345 [root @ web ~] # Cat 1.txt> 2.txt [root @ web ~] # Cat 1.txt | tee-a 3.txt 12345 [root @ web ~] # Cat 2.txt 1234512345 [root @ web ~] # Cat 3.txt 1234512345 [root @ web ~] # Example 2 use the tee command to repeatedly output the string [root @ web ~] # Echo 12345 | tee 12345 [root @ web ~] # Echo 12345 | tee-1234512345 [root @ web ~] # Echo 12345 | tee-123451234512345 [root @ web ~] # Echo 12345 | tee---12345123451234512345 [root @ web ~] # Echo 12345 | tee--1234512345123451234512345 [root @ web ~] # [Root @ web ~] # Echo-n 12345 | tee12345 [root @ web ~] # Echo-n 12345 | tee-1234512345 [root @ web ~] # Echo-n 12345 | tee-123451234512345 [root @ web ~] # Echo-n 12345 | tee---12345123451234512345 [root @ web ~] # Echo-n 12345 | tee--1234512345123451234512345 [root @ web ~] # Example 3 use the tee command to save the standard error output to the file [root @ web ~] # Ls "*" ls: *: No file or directory [root @ web ~] # Ls "*" | tee-ls: *: No file or directory [root @ web ~] # Ls "*" | tee ls.txt ls: *: No file or directory [root @ web ~] # Cat ls.txt [root @ web ~] # Ls "*" 2> & 1 | tee ls.txt ls: *: No file or directory [root @ web ~] # Cat ls.txt ls: *: No file or directory Example 4 lists the text content, and copies three copies to list the text file slayers. story content, at the same time copy 3 copies, file names are ss-copy1, ss-copy2, ss-copy3: [root @ web ~] # Cat slayers. story | tee ss-copy1 ss-copy2 ss-copy3

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.