Input and Output Redirection

Input and Output Redirection

This document provides basic descriptions of redirection and pipe commands.


input

By convention, a UNIX command reads input from standard input (the keyboard). To get a command to read from a file instead, you need the command, the filename, and the character '<' : my_command < my_input. Think of the '<' as an arrow pointing in the direction the data is flowing, from the file to the command.


output

The output of a UNIX command is sent to standard output (the screen) by convention. To get a command to send the output into a file instead, you need the command, the filename, and the character '>' : my_command > my_output. The arrow analogy holds true in this direction as well, with the data flowing from the command to the file.

To append the output of a command to a file without erasing its previous contents, use the notation : my_command >> my_output.


pipes

If you have a series of commands in which the output of one command is the input of the next, you can pipe the output through without saving it in temporary files: first_command | next_command. For example, if you wanted to print out a sorted version of a file that contained a list of names and phone numbers, you could use a pipe (as well as input redirection): sort < my_phone_list | lpr.


[UNIX Survival home page]