On Debian how to overwrite stdout with stderr?
Jun 29, 11:28pm

On Debian (and most Unix-like systems), you can overwrite stdout with stderr by redirecting stderr to stdout. Here are the common ways to do it:


1. Redirect stderr to stdout

Use 2>&1 to redirect stderr (file descriptor 2) to stdout (file descriptor 1):

bash
command 2>&1
  • This sends both stdout and stderr to the terminal.

2. Overwrite stdout with stderr only

If you want to discard stdout and only show stderr, use:

bash
command 2>&1 >/dev/null
  • 2>&1 redirects stderr to stdout.
  • >/dev/null discards stdout (and thus stderr, since it was redirected to stdout).

3. Swap stdout and stderr

If you want to swap stdout and stderr (so stderr goes to stdout and stdout goes to stderr), use:

bash
command 3>&2 2>&1 1>&3 | command2
  • This is more advanced and rarely needed.

4. Save stderr to a file and overwrite stdout

If you want to save stderr to a file and overwrite stdout with it:

bash
command 2> error.log
cat error.log >&1

Jun 29, 11:28pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more