redirect pipe stdout stderr file-descriptor

Source

  • Redirect stdoutcommand > file
  • Redirect stderrcommand 2> file
  • Redirect both stdout and stderr:
    • Standard: command > file 2>&1
    • Shorthand: command &> file
  • Append stdoutcommand >> file
  • Append both stdout and stderr:
    • Standard: command >> file 2>&1
    • Shorthand: command &>> file
  • Pipe stdoutcommand1 | command2
  • Pipe both stdout and stderr:
    • Standard: command1 2>&1 | command2
    • Shorthand: command1 |& command2
  • Custom file descriptors:
    • Create and redirect stdout: exec 3> file; command >&3
    • Redirect stderr: command 2>&3
    • Redirect both stdout and stderr: command > /dev/fd/3 2>&1 (no shorthand available)
  • Discard stdout and stderr:
    • Standard: command > /dev/null 2>&1
    • Shorthand: command &>/dev/null