Controlling the Flow of Data
In Linux, data flow is highly standardized. Every process (command) has three default data streams:
- STDIN (Standard Input): File Descriptor 0. The input the command receives (usually the keyboard).
- STDOUT (Standard Output): File Descriptor 1. The normal output the command generates (usually the screen/terminal).
- STDERR (Standard Error): File Descriptor 2. Error messages the command generates (usually the screen/terminal).
Redirection is the process of changing where these streams originate or terminate.
Output Redirection (>) - Overwriting
The > symbol redirects STDOUT to a file, overwriting the file's contents if it exists.
bash $ ls -l /etc > file_listing.txt
The output of ls is written entirely to file_listing.txt
Output Redirection (>>) - Appending
The >> symbol redirects STDOUT to a file, appending the new output to the end of the existing file.
bash $ date >> file_listing.txt