We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Tomek • 1 year ago

So why on the left of ">" we use FILE_DESCRIPTOR without & char while on the right hand we use
FILE_DESCRIPTOR with & char?

Ada • 9 months ago

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)

victor • 2 years ago

very nice, thanks

victor • 2 years ago

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 • 2 years ago

gg

douyu • 3 years ago

nice

THor • 3 years ago

Clearly written, thanks!

Klaudia • 3 years ago

thank you for this, it got the subject to be clear as day :D

david luu • 5 years ago

Great article, very clear explanation. Thanks you very much

just • 5 years ago

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

joel reindel • 5 years ago

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

Peter lymo • 5 years ago

best article ever finally i get to understand it

random name • 5 years ago

I like to remember &1 as "write into" 1.

Stackguy • 5 years ago

Super helpful. Thx!

Brennan Sebastian • 5 years ago

Excellent explanation.

Ken Long • 5 years ago

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

Chris • 5 years ago

thank you, very clear explanation!

snowball_wang • 5 years ago

Thanks, brain. It is really helpful!

gary zhang • 5 years ago

very clear, thanks a lot~

KD • 5 years ago

Simple and clear.

peter • 5 years ago

I've read dozens of other articles, but finally feel like I understand. Thanks for creating this!

Smizan • 5 years ago

Cool & Thanks. After long time, I understood clearly.

useful

Thanks a lot. very useful information

fisenkodv • 6 years ago

Thank you, for the explanation

Baskar Balaji • 6 years ago

Well explained, simple and on point..

Changwoo Rhee • 6 years ago

Perfect std explain!

shash_rath • 6 years ago

Thanks Brian.

Well Explained.

Valente Flores • 6 years ago

Very well explained, thanks!

billobeng • 6 years ago

well explained

Jax • 6 years ago

This is the best description of a Linux command I've ever seen! Cheers!

goutham gonuguntla • 6 years ago

Helpful !

Manoj Prakash • 6 years ago

Thank you. good explanation

Nanda Kumar • 6 years ago

On target. Excellent

Pilath Raj • 6 years ago

Wow. Great Explanation, Thank you :)

nxn • 6 years ago

Wow. Great article. Keep it up!

superman • 6 years ago

good article, never gave a thought about this minute(but important) thing.

mark anthony • 6 years ago

thank you.

Karthik R • 6 years ago

Thanks Brian, The article helped me understand the command quickly.

Ravi Agrawal • 6 years ago

Great article !

Navin A • 6 years ago

Really helpful.
Thank you so much for putting your time to write an excellent post..

Thawfeek Yahya • 6 years ago

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 ?

anonymous • 6 years ago

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.

anonymous • 6 years ago

yes, you are correct

Linux Newbie Guide • 6 years ago

Great article! I have linked to it on the Ultimate Linux Newbie Guide! https://linuxnewbieguide.or...

Ashutosh Soni • 6 years ago

easiest way on the internet

yongle • 6 years ago

Nice article. Clear explanation.

Sagar • 6 years ago

Really simplified and easy to understand explanation. Thank you @Brian Storti !