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