Linux Shell script output redirection

Source: Internet
Author: User

In the Linux Shell environment, input and output redirection is supported, expressed by symbols <and>. 0, 1, and 2 indicate the standard input, standard output, and standard error information output, which can be used to specify the standard input or output to be redirected. For example, 2> a.txt outputs the error information to file a.txt.

At the same time, you can also implement redirection between the three standard input and output. For example, you can use 2> & 1 to redirect the error message to the standard output.

In Linux, there is also a special file/dev/null, which is like a bottomless pit, and all the information redirected to it will disappear without a trace. This is very useful. When we do not need to display all information about the program, we can redirect the output to/dev/null.

To disable normal output and error information, redirect both standard output and standard errors to/dev/null. For example:

# Ls 1>/dev/null 2>/dev/null

Another way is to redirect errors to standard output and then to/dev/null, for example:

# Ls>/dev/null 2> & 1

Note: The order here cannot be changed. Otherwise, the desired effect cannot be reached. In this case, the standard output is redirected to/dev/null and the standard error is redirected to the standard output, since the standard output has been redirected to/dev/null, the standard error will also be redirected to/dev/null, so everything will be quietly :-)

+:

$ Make> & filename. log &

This means to redirect both standard output and error output. make> out only redirects standard output.

> Log indicates to redirect the standard output to the file log.

> & Log indicates that both the standard output and error output are directed to the file log, which is equivalent to> log 2> & 1

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.