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.