Title: Output Redirection (> and >>)
Course: CIS 121: Linux/UNIX I: Fundamentals ~ For IGNITE Review > Section: Learning Modules

Output Redirection

> stdout

The shell (and almost every other Linux command) takes input from stdin (stream 0) and sends output to stdout (stream 1) and error messages to stderr (stream 2) . The keyboard often serves as stdin, stdout and stderr both go to the display. The shell allows you to redirect these streams.

To repeat: While scanning the line, the shell will see the > sign and will clear the file! This means that even when the command fails, the file will be emptied!

Erasing a file while using > can be prevented by setting the noclobber option.

To remove the noclobber option and enable the file to allow overwriting, use the +o option.

[paul@RHELv4u3~]$ set +o noclobber

Use >> to append output to a file.

>> ignores the setting of noclobber.

(Cobbaut, p. 116)