We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.
very late, but fyi, it's only after the redirection operator ">" that "&" means that, otherwise the "&" would be taken by the preceding command where the output it being redirected, i.e.
"command &2>&1" would be parsed as
"command &" (run the command in the background) followed by
"2>&1" (run the command called "2" and redirect its output to the stdout)
very nice, thanks
Brian is this site personally built or a blog solution? Want to create one but don't want to start coding site from scratch. Will like to use a ready solution instead.
gg
nice
Clearly written, thanks!
thank you for this, it got the subject to be clear as day :D
Great article, very clear explanation. Thanks you very much
considering the part
You can use &[FILE_DESCRIPTOR] to reference a file descriptor value;
i have seen a new implementation about it
using
$ command >&file
how come >&file make "file" a file descriptor
Is there a difference between using 2>&1 to also forward 2 on and just using &> from the start?
example:
{CMD} > /dev/null 2>&1
vs
{CMD} &> /dev/null
best article ever finally i get to understand it
I like to remember &1 as "write into" 1.
Super helpful. Thx!
Excellent explanation.
Great job explaining everything except the "&". Why is it 2>&1, and not 2>1? Does the & make it the Address of 1, like in C?
He is actually already explaining it as well:
"You use &1 to reference the value of the file descriptor 1 (stdout). So when you use 2>&1 you are basically saying “Redirect the stderr to the same place we are redirecting the stdout”. And that’s why we can do something like this to redirect both stdout and stderr to the same place:"
If you just use 2>1, it will output the stderr to a file named 1. Instead you are using &1 as an address/reference as you state yourself.
Another way to write the same would be > /dev/null 2> /dev/null
thank you, very clear explanation!
Thanks, brain. It is really helpful!
very clear, thanks a lot~
Simple and clear.
I've read dozens of other articles, but finally feel like I understand. Thanks for creating this!
Cool & Thanks. After long time, I understood clearly.
useful
Thanks a lot. very useful information
Thank you, for the explanation
Well explained, simple and on point..
Perfect std explain!
Thanks Brian.
Well Explained.
Very well explained, thanks!
well explained
This is the best description of a Linux command I've ever seen! Cheers!
Helpful !
Thank you. good explanation
On target. Excellent
Wow. Great Explanation, Thank you :)
Wow. Great article. Keep it up!
good article, never gave a thought about this minute(but important) thing.
thank you.
Thanks Brian, The article helped me understand the command quickly.
Great article !
Really helpful.
Thank you so much for putting your time to write an excellent post..
Thanks for great explanation, I have a quick question .
In this command [ py="$(python --version 2>&1)" ] does that mean printing a python --version in command line goes to standard error file descriptor ?
you can easily test this just by executing "$ python --version 1> testfile.txt", in which case it will still print out the stderr and will not redirect anything to testfile.txt; then you can "$ python --version 2> testfile.txt" and you can see theres no output now, and the stderr will indeed be redirected to testfile.txt this time.
This is a peculiarity of python, since no other program print their version in stderr.
yes, you are correct
Great article! I have linked to it on the Ultimate Linux Newbie Guide! https://linuxnewbieguide.or...
easiest way on the internet
Nice article. Clear explanation.
Really simplified and easy to understand explanation. Thank you @Brian Storti !
So why on the left of ">" we use FILE_DESCRIPTOR without & char while on the right hand we use
FILE_DESCRIPTOR with & char?