Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

In Ksh for redirecting i/o from a command away from standard output/error I do , [ where command is any command that produces output/error ]

command 2>filename
command 2>/dev/null

or

command &>filename
command &>/dev/null

In bash , often I see code like

command >&/dev/null

what does that additional & signify, when the same can be get done by using

command> /dev/null

I know I am missing something fine, but glad to learn.

EDIT: I knew what 2>&1 is, which the so called duplicate question asks , I was told that 1 indicates a file descriptor and hence we need an & to refer that. I was puzzled to see & before the name of the file. Hence this question.

share|improve this question
add comment

marked as duplicate by slm, jasonwryan, rahmu, terdon, Anthon Sep 26 '13 at 4:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 2 down vote accepted
>&fname

is the same as

>fname 2>&1

i.e. it redirects both stdout and stderr into file fname. See bash(1) man page, section REDIRECTION (especially its part Redirecting Output) for detailed explanation.

share|improve this answer
    
awesome. wondering why the documentation says out of &>fname and >&fname , the former is preferred. Thanks a lot of pointing me to the right documentation. –  user917279 Sep 25 '13 at 15:05
    
That documented preference puzzles me too. When csh introduced the >& syntax it had to be in that order because the parser wasn't as complicated and ls &> junk.dat was semantically equivalent to ls & ; cat /dev/null > junk.dat. For the benefit of a reader of a script, I'd still use >& to lessen the ambiguity, but I'm pretty old skool. –  msw Sep 25 '13 at 16:29
    
unix.stackexchange.com/a/89388/20291 points to a nice article on redirection. –  user917279 Sep 26 '13 at 7:49
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.