whatis redirection
Redirection
Also known as: I/O redirection, >, >>, 2>&1
Shell syntax such as >, >>, <, and 2>&1 that connects a command's input or output to files instead of the terminal.
What Is I/O Redirection in Linux?
> writes stdout to a file, replacing it; >> appends; < reads stdin from a file. Prefixing a file descriptor number targets other streams, so 2> redirects stderr and 2>&1 sends stderr wherever stdout is currently going.
Order matters: cmd > out.log 2>&1 captures both streams in the file, while cmd 2>&1 > out.log sends errors to the terminal. Redirecting to /dev/null discards output entirely.
Example
backup.sh > /var/log/backup.log 2>&1 Learn more about Redirection
- I/O Redirection and Pipes Explained Every Linux command reads from standard input and writes to standard output and standard error. This guide explains those three streams and how to redirect and chain them with >, >>, <, 2>&1, pipes, and xargs.
- Heredocs and Process Substitution in Bash Feed multi-line text to a command without a temporary file, and present a command's output where a filename is expected. Two syntaxes that remove most of the need for temporary files in scripts.
- tee Command Explained: Writing to a File and the Screen at Once tee splits a stream so it goes to a file and onward down the pipeline. It is also the standard way to write to a root-owned file without running your editor as root.