3.8.2 Redirecting input and output

Next: 3.8.3 Using pipes Up: 3.8 UNIX Plumbing Previous: 3.8.1 Standard input and

          Now, let’s say that we wanted to send the output of sort to a file, to save our shopping list elsewhere. The shell allows us to redirect standard output to a filename, using the « > » symbol. Here’s how it works.

/home/larry/papers# sort > shopping-list

/home/larry/papers# As you can see, the result of the sort command isn’t displayed, instead it’s saved to the file shopping-list. Let’s look at this file.

/home/larry/papers# cat shopping-list apples bananas carrots


Now we can sort our shopping list, and save it, too! But let’s suppose that we were storing our unsorted, original shopping list in the file items. One way of sorting the information and saving it to a file would be to give sort the name of the file to read, in lieu of standard input, and redirect standard output as we did above. As so:

/home/larry/papers# sort items > shopping-list
/home/larry/papers# cat shopping-list apples bananas carrots


      However, there’s another way of doing this. Not only can we redirect standard output, but we can redirect standard input as well, using the « 

READ  Graphics Muse