Chapter 15
Pipes And Redirection

15.1 Do This


Source 27: Linux/Mac OSX Exercise 15
  $ cat ex12.txt ex13.txt | less
  $ cat < ex13.txt
  I am a fun guy.
  Don't you know why?
  Because I make poems,
  that make babies cry.
  $ less < ex12.txt
  $ less < ex12.txt | cat | less
  $ cat ex13.txt > ex15.txt
  $ cat ex15.txt
  I am a fun guy.
  Don't you know why?
  Because I make poems,
  that make babies cry.
  $


Source 28: Windows Exercise 15
  > cd ..
  > cd temp
  > cat ex12.txt,ex13.txt | more
  > echo "I am a new file." > ex15.txt
  > cat ex15.txt
  I am a new file.
  > cat ex15.txt > another.txt
  > cat another.txt
  I am a new file.
  > cat ex15.txt | more
  >

15.2 You Learned This

Now we get to the cool part of the command line: redirection. The concept is that you can take a command and you can change where its input and output goes. You use the < (less-than), > (greater-than), and | (pipe) symbols to do this. Here's a breakdown:

|
The | takes the output from the command on the left, and "pipes" it to the command on the right. In line 1 you see me do that.
<
The < will take and send the input from the file on the right to the program on the left. You see me do that in line 2. This does not work in PowerShell.
>
The > takes the output of the command on the left, then writes it to the file on the right. You see me do that on line 9.
>>
The >> takes the output of the command on the left, then appends it to the file on the right.

There are a few more symbols, but we'll start with just these for now.

15.3 Do More

  1. Create some more index cards for memorizing these three symbols. Write the symbol on one side, then what it does on the other side. Drill these just like the other commands.


Online Video Course + PDF For $9

For the price of most other course's PDFs only, you can get the full PDF for this class and 2 videos demonstrating the whole book for both Unix/OSX Terminal and Windows PowerShell. The course is self-paced so you can go through it any time you want, as many times as you want.


Signup Now At Udemy.com For $9