Problem description: For example, the content of file 11 is: hello Copy the contents of file 22 to the end of file 11. The effect of file 11 is: hello Solution: cat 22 >> 11 >> means to add > means redirection, which will overwrite the original content Tips: To clear the contents of a.txt file and make the file size 0 without deleting the file, you can: cat /dev/null > a.txt Knowledge point expansion: Linux outputs the end of a file to another file ">" redirection overwrites the original file; ">>" appends to the end of the file. 1. To redirect standard output, you can use the ">" symbol, for example: Will redirect the standard screen output of the dir command to the text file filelisting.txt 2. To redirect standard error, you can use the structure "2>", for example: The above command will send standard output to the screen. If there are no error messages, no information will be written to the errorlisting.txt file. If an error occurs, nothing is output to the screen and the file errorlisting.txt contains the error information. 3. dir my_dir > file_and_error_listing.txt 2> & 1 (&1 means the same as before) The above command first redirects the standard output to the text file, and then redirects the standard error to the same location as the standard output. 4. You can also use the symbol “|” (pipe command) to send the standard output of one command to the standard input of another command. In the following example, the standard output of the dir command is piped into the more command (which automatically pauses when the output fills the screen): dir | more 5. Use the "tee" command to write standard output to the file and the screen at the same time: dir | tee filelisting.txt 6. There is also a special file /dev/null under Linux. All information redirected to it will disappear without a trace. When we don't need to echo all the information of the program When , you can redirect the output to /dev/null. 7. The following command directs both standard output and error to files "&" here represents standard output and standard error. Both normal output and error information are written to filename. 8. To redefine a file identifier, you can use the i>&j command, which means redirecting the file identifier i to j. You can understand "&" as "get address" Please see the following example Indicates that file identifier 5 is directed to standard output. This command is usually used to temporarily save standard input. Linux tee command function description: reads standard input data and outputs its contents to standard output and files.
Additional note: The tee command reads data from the standard input device, outputs its contents to the standard output device, and saves it as a file; if no file is specified after tee, It only outputs its contents to the standard output device. tee only supports single or double output, similar to the T-type pipe used by plumbers. parameter: -a or --append Append to an existing file instead of overwriting it. example: make 2>&1 | tee make.log command > filename redirects standard output to a new file Summarize The above is what I introduced to you about how to copy the contents of a file to the end of another file in Linux. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: Chrome plugin (extension) development guide (complete demo)
>>: Detailed steps to install MySQL on CentOS 7
The Truncate table statement is used to delete/tr...
Assume that a node in the three-node MGR is abnor...
This article shares the specific code of JavaScri...
Preface What is data type conversion? The default...
Table of contents Preface🌟 1. API Introduction 2....
Table of contents 1. What content usually needs t...
Table of contents Tomcat Introduction Tomcat depl...
I am using centos 7 64bit system here. I have tri...
Under the requirements of today's responsive ...
This article shares the specific code of vue echa...
Grouping and linking in MYSQL are the two most co...
Today, I logged into the server and prepared to m...
Three ways to configure Nginx The first method di...
UPD 2020.2.26 Currently Ubuntu 20.04 LTS has not ...
The outermost boxF rotates 120 degrees, the secon...