I have been trying to figure out the relationship between file descriptors. One thing I don't understand is, how is:
ls -l /bin/usr > ls-output.txt 2>&1
different from:
ls -l /bin/usr 2>&1 >ls-output.txt
I have been trying to figure out the relationship between file descriptors. One thing I don't understand is, how is:
different from:
|
||||
|
The order of the redirection is important as they are executed sequentially: >filename 2>&1
That means that both 2>&1 >filenameHere This means that So in short the order of redirects is important as each filedescriptor is independent of each other. Additional InformationFor further information have a look at some other questions and answers such as: |
|||
|
They're not. a>&b redirects fd a to fd b. if a is not given, 1 is assumed. 1 is stdout and 2 is stderr. Some shells (e.g. Bash) also let you specify &> file to redirect both at the same time. However, > 2>&1 is more portable. |
|||||
|