.. include:: ../header.txt .. seealso:: :ref:`io` .. _redirect: File Redirection =========================== .. index:: redirection, stdin, stdout, stderr, > , <, 2>&1 As was discussed in :ref:`io`, standard input, output and error (stdin, stdout, stderr) are open file descriptors in every process. stdin Redirection ------------------- Redirect standard input from a file (instead of the keyboard) using the ``<`` metacharacter. :: $ command < file stdout Redirection ------------------- Redirect standard output to a file (instead of the terminal) using the ``>`` metacharacter. The ``>>`` metacharacter redirects stdout appending the file. :: $ command > file $ command >> file stderr Redirection ------------------- Redirect standard error (error messages) to a file (instead of the terminal) using the ``2>`` metacharacter. The ``2>&1`` metacharacter redirects stderr to the same file that stdout was redirected to. :: # stdout to terminal and stderr to file: $ command 2> file # stdout and stderr to different files: $ command > out_file 2> error_file # stdout and stderr to the same file: $ command > file 2>&1