Lesson 7: Input and Output

  1. File Descriptors
    Every process is given three open file upon its execution. These open files are inherited from the shell
    1. stdin - Standard Input (0) defaults to the user's keyboard
    2. stdout - Standard Output (1) defaults to the user's terminal
    3. stderr - Standard Error (2) defaults to the user's terminal
  2. File Redirection
    The input and output of a program can be redirected from and to other files:
    1. < filename   Input will now come from filename rather than the keyboard.
    2. > filename   Output will now go to filename instead of the terminal.
    3. 2> filename   Error messages will now go to filename instead of the terminal.
    4. >> filename   Output will now be appended to filename.
  3. 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.
    1. Filters - A program that both reads from stdin and writes to stdout.
    2. 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
  4. Miscellaneous Commands
    1. find
    2. grep
    3. sort
    4. spell
    5. wc
  5. Tasks to perform with pipelines:
    1. Count how many files are on the system
    2. Count how many users are logged onto the system
    3. Sort and count the misspelled words in a series of documents
    4. Search for a particular string in the output of a command