DevOps · Flashcard

Why does command 2>&1 >file still leave error output on the terminal?

  • Astderr copies stdout's terminal target before stdout is later moved to the file
  • Bstderr is inherently immune to redirection and can only ever reach the terminal
  • CA file cannot hold two streams, so stderr silently falls back to the terminal
  • DThe shell applies >file first, redirecting stderr before stdout is redirected

Why this is the answer

Redirections apply left to right: 2>&1 first aims stderr at stdout's CURRENT target (the terminal), then >file moves stdout to the file — stderr still points at the terminal. Use >file 2>&1 to send both to the file. Option two is a myth — stderr redirects fine with 2>. Option three invents a one-stream limit. Option four has the order backwards.

Official docs
Study in Gnoseed →