Input/output redirection
The shell can redirect standard input, standard output, and standard error to and from files. In other words, any command that reads from standard input can have its input come from a file instead with the shell’s < operator:
$ mycommand < infile
Likewise, any command that writes to standard output can write to a file instead:
$ mycommand > outfile Create/overwrite outfile $ mycommand >> outfile Append to outfile
A command that writes to standard error can have its output redirected to a file as well:
$ mycommand 2> errorfile
To redirect both standard output and standard error to files:
$ mycommand > outfile 2> errorfile Separate files $ mycommand > outfile 2>&1 Single file
Get Linux Pocket Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.