Linux Input/output redirection

Source: Internet
Author: User
Linux Input and output redirection input and output redirection, 0-STDIN, 1-STDOUT, 2-STDERRls-altest1test2test32 & gt; error1 & gt; normal can simultaneously output ls-altest1test2test3 & amp; & gt; all3. temporary redirection gr. sh: echo & Linux input/output redirection, 0-STDIN, 1-STDOUT, 2-STDERRls-al test1 test2 test3 2> error 1> normal can output both ls-al test1 test2 test3 &> all 3. temporary Redirect gr. sh: echo 'hello'> & 2; echo 'world' run. /gr. sh 2> error.txt, the error result is output to error.txt, and world is output to the screen. 4. permanent redirection: exec 1> test.txtthe echo output below will all point to test.txt. once redirected, the original location cannot be easily redirected. The following describes the input redirection: exec 0 <test.txt, which will be taken from test. read While read lineDoEcho $ lineDone in file to create your own permanent redirection (greater than or equal to 3) Exec 3> grself.txt Echo 'hello world'> & 35. redirect file descriptor Exec 3> & 1 # redirect 3 to 1 Exec 1> test.txt redirect 1 to test.txt file Echo 'helloworld'> & 1 Exec 1> & 3 # redirect 1 to 3, 6. input file descriptor Exec 6 <& 0 # direct 0 to 6 Exec 0 TestfileRead line <& 3 Echo $ lineEcho 'Hello world'> & 38. close file descriptor Exec 3> &-List opened file descriptors/usr/bin/lsof-a-p $-d, 29. block command output echo 'hello'>/dev/null 10. create a temporary file Mktemp testing. XXXXX (at least three X files are randomly generated to ensure that the generated temporary files are unique). return the temporary file name Mktemp-t test after creation. XXXXXX (The-t option will force the creation of temporary files under the system/tmp and return the full path of the temporary files, not just the file name) create temporary directory tempdir = 'mktemp-d dir. XXXXXX 'CD $ tempdirtempfile1 = 'mktemp temp. XXXXXXX 'tempfile2 = 'mktemp temp. XXXXXXX '11. record Information: tee writes the file Ls-al to the screen at the same time. | tee test.txt Ls-al | tee-a test.txt (-a option, indicating appending to the file)
Related Article

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.