There are three special file descriptors: stdin, stdout and stderr (std stands for standard), which are defined as file descriptor 0, 1 and 2. You can do different types of redirections with them.

  • redirect stdout to a file
ls -la > la.log
  • redirect stderr to a file
ack 'pattern' 2> ack-error.log
  • redirect stdout to stderr
ack 'pattern' 1>&2
  • redirect stderr to stdout
ack 'pattern' 2>&1
  • redirect stderr and stdout to a file
ack 'pattern' &> /dev/null

References

  1. All about redirection from TLDP
  2. Linux file descriptor

Leave a comment