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