About the shell commond> out. File 2> & 1 command

Source: Internet
Author: User

Shell Command: ls-Al> out. log 2> & 1

Command Description: redirects the 1 (stdout) Output and 2 (stderr) output of the shell command to the out. log file.

Explanation: ls-al. After a commond statement is executed, there are two types of output: 1 (stdout) Output and 2 (stderr). By default, 1 is redirected to the standard output screen.

Ls-Al> out. log, which redirects the default output (which is actually output to the stdout on the screen) to the out. log file.

2> & 1 redirection means that & 1 means to get the standard output of 1 (stout), which is to redirect 2 to 1, because the current 1 has been redirected to the screen (the screen has been redirected to the out. so stdout and stderr are redirected to the out. log File.

Meanings of other writing methods:

Ls-Al> out. log 2> 1: The default 1 (stdout) is redirected to out. log, and 2 (stderr) is redirected to file 1.

ls 2> 1. If you test the file, no error is reported, but an empty file 1 is output.
ls XXX 2> 1 test, if the file XXX does not exist, the error is output to 1.
ls XXX 2> & 1 test. The file 1 is not generated, but the error is returned to the standard output;
ls XXX> out.txt 2> & 1, which can be replaced by ls xxx 1> out.txt 2> & 1; redirection symbol> errors are 1, errors, and outputs are all transmitted to out.txt.

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.