Linux Shell redirection

Source: Internet
Author: User

Linux file descriptor: Three file descriptors are opened by default: standard input 0, standard output 1, error output 2

Output redirection

Command-line1 [1-N]> file or file operator or device

First, check whether the file on the right exists. If the file exists, delete it and create it again. No matter whether the command on the left is executed successfully or not, the file on the right will become empty. Use> to append the object.

[UNIX @17:18:57 ~] $ Ls>A.txt
[UNIX @17:19:11 ~] $ Cat a.txt
A.txt
CPP
Ctest
Makefile
Network
Shell
Socket
Test
Thread

Input redirection

Command-line [N] <file or file descriptor & Device

[Unix@17:20:59~]$ Cat>A <a.txt
[Unix@17:21:36~]$ CatA
A.txt
CPP
Ctest
Makefile
Network
Shell
Socket
Test
Thread

Exec binding redirection

Exec file descriptor [N] <or> file or file descriptor or device

As mentioned above, the output redirection will bind the input. After the output is bound to a file or device, it is only valid for the current command. If you need to bind all the subsequent commands to be supported, you need to use the EXEC command.

 [Unix  @  17  :  26  :  02  ~]  $ Exec     1  >  A.txt
[Unix @ 17 : 26 : 11 ~] $ Ls - Al
[Unix @ 17 : 26 : 16 ~] $ Exec 1 >/ Dev / Tty # Restore standard output
[Unix @ 17 : 26 : 25 ~] $ Ls
A.txt CPP ctest makefile network shell socket test thread

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.