Linux redirect command

  

A file identifier is an integer starting at 0 to ending at 9, indicating the source of a particular data stream associated with the process. By default, there are always 3 “file descriptors'; are open, 0, 1, 2 are stdin, stdout, stderr respectively.

The redirect descriptor has the following usage:

: >filename Truncates the file filename to 0; if the file does not exist, it creates a file of length 0.

command 1 > fielname redirects standard output to file fielname

command 2 > filename redirects standard error to file fielname

command > filename 2> &1 (equivalent to command & > filename) redirects standard output along with standard error to file filename

command >&m redirects standard output to file descriptor m

command <&- Close standard input

n<&m Copy the input of FD to m to FD as n

n>&- Close FD Output for n

n<&- Turn off FD for input of n

n <> filename To read and write filename, open file filename and assign file descriptor n to it If the file filename does not exist, create it.

Note: The function of guessing & character is to take the address, 0~9 marks an array of file descriptors, and &m means to take the file descriptor of the array in the table below, a single & ; characters represent stdout and stderr. Of course, these are just guesses, in order to make it easier to understand and remember the usage of redirects.



Copyright © Windows knowledge All Rights Reserved