In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Problem description:
For example, the file content of 11 is as follows:
Hello
22 the contents of the document are:
World
Copy the contents of the 22 file to the end of the 11 file, and the effect of the 11 file is:
Hello
World
Solution:
Cat 22 > > 11
> > means to add.
> means redirect, which will overwrite the original content
Little Tips:
Clear the contents of the a.txt file and make the file size 0 without deleting the file:
Cat / dev/null > a.txt
Knowledge point expansion:
Linux outputs the end of the file to another file
The redirect overwrites the original file; it is appended to the end of the file.
1. To redirect standard output, you can use the ">" symbol, for example:
Dir my_dir > filelisting.txt
The standard screen output of the dir command will be redirected to the text file filelisting.txt file
2. Redirect standard error, you can use structure "2 >", for example:
Dir my_dir 2 > errorlisting.txt
The above command will send the standard output to the screen, if there is no error message, no information will be written to the errorlisting.txt file. If something goes wrong, nothing will be output to the screen, and the file errorlisting.txt will contain the error message.
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 command more (automatically paused when the output is full): dir | more
5. Use the "tee" command to write standard output to both the file and the screen: dir | tee filelisting.txt
6. There is also a special file / dev/null under Linux, and all information redirected to it will disappear without a trace. When we don't need all the information about the echo program
You can redirect the output to / dev/null.
7. The following command directs both standard output and errors to the file
# ls / dev & > filename
"&" here represents standard output and standard error, where both normal output and error information are written to filename
8. To redefine the file identifier, you can use the I > & j command to redirect the file identifier I to j. You can understand "&" as "take an address".
Take a look at the following example
# exec 5 > & 1
Indicates that file identifier 5 is directed to standard output, which is usually used to save standard input temporarily.
Linux tee command function description: read standard input data and output its contents to standard output and files.
Grammar: tee [- ai] [--help] [--version] [file.]
Note: the tee instruction will read the data from the standard input device, output its contents to the standard output device, and save it as a file; if no file is specified after the tee
Its contents are output only to standard output devices, and tee supports only one or two outputs, similar to the T-tube used by plumbers.
Parameters:
-an or-- append appends to the existing file instead of overwriting it.
-iMuri or-- ignore-interrupts ignore the interrupt signal.
-- help online help.
-- version displays version information.
Example:
Make 2 > & 1 | tee make.log
Command > filename redirects standard output to a new file
Command > > filename redirects standard output to a file (append)
Command 1 > fielname redirects standard output to a file
Command > filename 2 > & 1 redirects standard output and standard error into a file together
Command 2 > filename redirects standard error to a file
Command 2 > > filename redirects standard output to a file (append)
Command > > filename 2 > & 1 redirect standard output and standard error to a file (append)
Summary
The above is the linux introduced by the editor to copy the contents of one file to the end of another file. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!
If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.