Lesson 7: Input and Output
- File Descriptors
Every process is given three open file upon its execution. These open files are inherited
from the shell
- stdin - Standard Input (0) defaults to the user's keyboard
- stdout - Standard Output (1) defaults to the user's terminal
- stderr - Standard Error (2) defaults to the user's terminal
- File Redirection
The input and output of a program can be redirected from and to other files:
- < filename Input will now come from filename rather than the keyboard.
- > filename Output will now go to filename instead of the terminal.
- 2> filename Error messages will now go to filename instead of the terminal.
- >> filename Output will now be appended to filename.
- Pipelines
Commands may be chained together in susch a way that the stdout of one command is "piped" into
the stdin of a second process.
- Filters - A program that both reads from stdin and writes to stdout.
- Tees - A filter program that reads stdin and writes it to stdout and the file specified
as the argument. For example, the following command sends a sorted list of the current
users logged on to the system to the screen, and saves an unsorted list to the file users.
who | tee users | sort
- Miscellaneous Commands
- find
- grep
- sort
- spell
- wc
- Tasks to perform with pipelines:
- Count how many files are on the system
- Count how many users are logged onto the system
- Sort and count the misspelled words in a series of documents
- Search for a particular string in the output of a command