Ten sentences to teach you how to redirect data streams in Linux

Source: Internet
Author: User

Ten sentences show you how to redirect data streams in Linux. 1. When you see the redirection, you suddenly think of redirect in the web. That's right, but the function of redirecting data streams in Linux is not to jump to another web page, it is used to store important screen information, output unnecessary screen information to a file or "black hole", store error information and correct information separately, or only display correct information ~ 2. Data Stream redirection is divided into standard input (code is 0, use <or <), standard output (code is 1, use> or>), standard error (code is 2, use 2> or 2>) to output the three types. 3. Standard input> example: ls-l/> dir.txt contains 4 bytes. If you want to continue output in dir.txt but do not overwrite the previous information, use >>, such as ls/home> dir.txtto check dir.txt, the ls/home results are added at the end. If you use>, the preceding content will be overwritten.> Output cannot be accumulated! 5. If you want to input the content in another file to dir.txt, You Can cat> dir.txt <report/build. xml (the original content in the file is not retained) or cat> dir.txt <report/build. xml (keep the original content in the file) 6. After running the shell, if you want to save the correct and wrong information in the screen information to the two files respectively. Find dir.txt qwert> right_lisit 2> wrong_list must use 2> Output Error Message 7. Some errors have been known beforehand and are irrelevant. It is not necessary to display them on the screen, there is no need to store it in the file. You can find dir.txt qwert 2>/dev/null so that the error message can be thrown into the "black hole ~, If you are interested, go to/dev/null. Let's take a look ~ Nothing in it... 8. If you want to record both the correct information and error information, find dir.txt qwert> list.txt 2> & 1 9. You can also create a file through> ~ Cat> newfile 10, there is another <not introduced, this is different from his "Other Half">, does not mean accumulation, but indicates the end of the input. For example: cat> newfile <"over", then you can enter the content of the file. 12345 go up the hill and fight the tiger over and execute the cat newfile command. You can see that there is no over word in the file ~, Over is just a identifier defined by us as the end of input ~

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.