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
This article shares the installation and configur...
This article uses an example to describe how MySQ...
CSS Selectors Setting style on the html tag can s...
#docker ps check, all ports are mapped CONTAINER ...
Content 1. Give readers a reason to stay. Make the...
1. MS SQL SERVER 2005 --1. Clear the log exec(...
*Create a page: two input boxes and a button *Cod...
Today, I found out while working on PHP that if w...
When multiple images are introduced into a page, ...
The installation of compressed packages has chang...
Using fonts on the Web is both a fundamental skill...
1. Download the installation package from the off...
Table of contents 1. Variable Overview 1.1 Storag...
Table of contents 1. Custom instructions 1. Regis...
Table of contents Two ways to solve the problem o...