Linux Console print content saved to file __linux

Source: Internet
Author: User

This article describes how to save console print content to a file under Linux.

1. Tee command

The tee command is used to redirect data to a file and, on the other hand, can provide a copy of the redirected data as a stdin for subsequent commands. The simple thing is to redirect the data to a given file and screen. The tee instruction reads data from a standard input device, outputs its contents to a standard output device, and saves it as a file. Examples are as follows:

ls | Tee./log.txt

2. REDIRECT Symbol > ">" or "1>" output redirect: The output from the previous input to the following file, will clear the original contents of the file.

[Root@simile/]# Echo ' a b c c ' >test.txt
[root@simile/]# cat Test.txt A a
b b c c
">>" or "1>>" Append output redirection: Append the previous output to the rear end of the file and do not erase the original contents of the file.
[Root@simile/]# Echo ' The new line ' >>test.txt
[root@simile/]# cat Test.txt
a a B c C-the
new line
"<" or "0<" input redirection: Input redirection is used to change the input of the command, followed by the specified input, followed by the filename.
[Root@simile/]# xargs-n 2 <test.txt
A a
b b
c c

[root@simile/]# tr "" \ n "<test.txt
a
A
b
b
c
c
"<<" or "0<<" Append input redirection: followed by a string, used to indicate "input end", or CTRL + D to end the input.
[Root@simile/]# cat >>test.txt <<eof
Brand new Me
EOF
[root@simile/]# cat Test.txt
a a b b c c the
new line
Brand new Me
"2>" Error Redirect: Entering the wrong information into the file below will delete the original contents of the file. 1 "2>>" error append redirect: Append the wrong information to the file in the back, do not delete the original contents of the file.

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.