5.9.1. Standard Input and Standard Output

The standard input

The standard input is, by default, tied to the keyboard. A program can read information from it.

But the standard input can be redirected to a file, causing the program to read information from the file as if it is coming from the keyboard. To do that, add <file to the end of a Linux command. For example,

  jump up <data.txt
runs command
  jump up
but arranges for its standard input to come from file data.txt.


The standard output

The standard output is, by default, tied to the terminal window, and information written to it shows up in the terminal.

But the standard output can be redirected to a file, causing the program to write information into the file instead of into the terminal window. To redirect it, write >file after a Linux command. For example,

  jump up <data.txt >jump-out.txt
runs command
  jump up
with the standard input tied to file data.txt and the standard output going to file jump-out.txt. You can redirect either the standard input or the standard output or both.