Topics Map > University of Chicago > IT Services > Applications, Operating Systems, & Devices

Basic Unix - Redirecting Input and Output

This article describes how to redirect input and output between sources in Unix.

Many options exit in Unix to allow you redirect input and output between various sources.

Output can be redirected from many sources. For instance, you can redirect the output of ls command to the less command, by typing ls | less at the harper prompt. You may be wondering what the | is. It's commonly referred to as a pipe, and you can find it right above the \ on your keyboard. You can use it to take output from any other command into another-much as a pipe moves liquids from one place to another.

You can also use the greater than > and less than < commands to manipulate data. Basically, > takes input from a command, and writes it into a file. As an example, typing ls > foo would take the output of the ls command and write it into the file named foo.

">" overwrites data in a file: if you use it on a file where something is already written, the old data will be replaced by the new data. You can, however, append to files. You do this by using ">>":two greater thans.

Let's say you had a file you wanted to maipulate with a command. You'd use less than ("<") to manipulate the data in that file. For example, you could take the data in foo and run it through the sort command by typing "sort < foo" at the command prompt.

There are, of course, many other ways to manipulate data using redirection. The four outlined here are the most important for most users: |, in particular, is very useful.

Keywords:redirect   Doc ID:16211
Owner:Larry T.Group:University of Chicago
Created:2010-12-08 18:00 CSTUpdated:2015-03-30 05:27 CST
Sites:University of Chicago, University of Chicago - Sandbox
Feedback:  0   0