Shell commands (2)--file descriptors and redirection characters

Source: Internet
Author: User

File descriptor

    1. STDIN: standard input, receive input from mouse, keyboard or other input device, file descriptor is 1
    2. Stduot: Output All normal output results, file descriptor is 2
    3. STDERR: Output All error messages, file descriptor is 3

Redirection character

    1. ">": Using the method, "command > File", after the process accepts the standard input, the redirect causes the standard output to change direction, not output to the screen, but output to a file. The standard error output remains unchanged, and the default output is to the screen or to the appropriate device. In addition, if the file already exists, the original content will be erased. For example:

    2. ">>": similar to the one above, except that when the file is written, the contents of the file are not purged but appended later. The file is created when the destination file does not exist.
    3. ">&": the redirect for all standard outputs. To output the error message to a file, use the >& redirect. This command will also erase the original content when writing to the file.
    4. ">>&": similar to the previous one, just write the file in Append mode
    5. "<": "Command < file", the process will get input information from the file, rather than input from the screen.
    6. "<<": one of the redirection characters followed by a delimiter. For example:
    7. "Command%n%c file": Command output redirected commands,%n file descriptor, default value is 1,%c redirect, file destination.
    8. Examples of several complex redirects:
      1. REDIRECT standard error to standard input command 2>&1
      2. The first file as standard input and as standard output command <> file
      3. Use the file descriptor x as the standard input command <&x
      4. redirect standard output to file descriptor x command >&m
      5. Turn off standard output command 1>&-
      6. Turn off standard error output command 2>&-
      7. Turn off standard input command 0<&-

Shell commands (2)--file descriptors and redirection characters

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.