What does " 2>&1 " mean?
stackoverflow.com
What does " 2>&1 " mean?
1–10 of 260 posts
Re: What does " 2>&1 " mean?
#2It redirects STDERR (2) to where STDOUT is piped already (&1). Good for dealing with random CLI tools if you're not a human.
Re: What does " 2>&1 " mean?
#3Re: What does " 2>&1 " mean?
#4Though, understanding it this way makes the direction of the angled bracket a little odd; at least for me it's more natural to understand dup2(2, 1) as 2<1, as in make fd 2 a duplicate of fd 1, but in terms of abstract I/O semantics that would be misleading.
Re: What does " 2>&1 " mean?
#5Not sure why this link and/or question is here, except to say LLMs like this incantation. It redirects STDERR (2) to where STDOUT is piped already (&1). Good for dealing with random CLI tools if you're not a human.
Re: What does " 2>&1 " mean?
#6Not sure why this link and/or question is here, except to say LLMs like this incantation. It redirects STDERR (2) to where STDOUT is piped already (&1). Good for dealing with random CLI tools if you're not a human.
I found the explanation useful, about "why" it is that way. I didn't realize the & before the 1 means to tell it is the filedescriptor 1 and not a file named 1.
Re: What does " 2>&1 " mean?
#7[0] https://stackoverflow.com/questions/3618078/pipe-only-stderr...
Re: What does " 2>&1 " mean?
#8Re: What does " 2>&1 " mean?
#9I find it easier to understand in terms of the Unix syscall API. `2>&1` literally translates as `dup2(1, 2)`, and indeed that's exactly how it works. In the classic unix shells that's all that happens; in more modern shells there may be some additional internal bookkeeping to remember state. Understanding it as dup2 means it's easier to understand how successive redirections work, though you also have to know that re…
Which is lost when using more modern or languages foreign to Unix.