Shell redirection in Linux

Source: Internet
Author: User

Example

Ls-L> out. File 2> & 1 &

Explanation:
Ls-L> out. File // redirects ls output to file out. File

2> & 1 // in shell, the file descriptor is usually stdin, stdout, stderr, I .e., 0, 1, 2. It can be seen that it uses LS-L> out. the error message generated by file in the output process is also stored in stdout, namely: 1. You can perform an experiment. If the command produces an error, the error message is in the out. file.

It may be a bit strange that & 1. Since> 2 on the Left can represent stderr, why cannot I use 1 directly on the right?

In fact, if you use 1 directly on the right side, you will find that the error message is not in out. file, but in file 1.

:~ $ Sudo./test1.sh P1 P2 P3 P4> out. File 2> 1 :~ $ LS1 out. File test1.sh :~ $ Cat 1 sudo:./test1.sh: Command not found :~ $ Cat out. File :~ $ Sudo./test1.sh P1 P2 P3 P4> out. File 2> & 1 :~ $ Cat 1 sudo:./test1.sh: Command not foundiie @ monitor :~ $ Cat out. File sudo:./test1.sh: Command not foundiie @ monitor :~ $


Because test1.sh does not have execution permission, the following error occurs: sudo:./test1.sh: Command not found.

The last &, needless to say, is to run in the background.

Reference: http://www.linuxsir.org/bbs/thread40501.html

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.