WARNING: This site is intended for online use only; mass-downloading of pages degrades the server and is prohibited.
If you attempt to use tools to mass-download the site, you may be blocked permanently by automated software.
If you want to read this CertiGuide offline, please use one of the links on the left to purchase a convenient PDF copy. Thank you.

Like this CertiGuide? Get it in PDF format!
Click Here!

Custom Search






Table Of Contents  CertiGuide to A+ (A+ 4 Real)
 9  Chapter 5: The Linux Operating System
      9  Basic Concepts and Procedures for Creating, Viewing and Editing Files and Directories

Previous Topic/Section
Examples of Using Meta Characters
Previous Page
Pages in Current Topic/Section
1
Next Page
Shell Information
Next Topic/Section

Pipes And Redirection

Most commands take data from the standard input (usually the keyboard), process or filter it, and send the results to the standard output (usually the display). Pipes and redirection provide the capability to take input from something other than the keyboard and send the output to something other than the display. Pipes are indicated by the symbol | (this is not a lowercase L but the vertical bar character). Using a pipe, the standard output of one command can be redirected to become the standard input for subsequent command. For example:

ls -al |grep file1

This will perform the long form of the ls command, showing hidden files, and send the output of that command to the grep command, which will then filter that output and only show lines that have the string or pattern file1 in them. This would perform approximately the same function as:

ls -al file1

Pipes perform a very useful function in Linux and other uses will be discussed in the section about administrative commands. Using pipes many commands can be strung together to perform very powerful functions. Linux has many text processing commands that can be used in an interesting manner by piping the output of one command into another.

The use of the > for redirecting output was shown with the cat command where two files were sent one after another to a third location. This was:

cat file1 file2 > file3

In this manner instead of sending file1 then file2 to the screen, the output was redirected and stored in file3. The > sign will redirect the standard output to the file named after the >. It is a important remember that if file3 exists and has contents, the first action will be to delete those contents before copying file1 to files3, then appending the contents of file2 to the new contents of file3.

The >> can be used prevent over writing the file. It will redirect the standard output to the file but append that output to the end of the indicated file. So in the above example if >> had been used instead of > the contents of file1 would have been appended to the end of the contents of file3 and then the contents of file2 would have been appended to the end of everything.

One final redirection operator is the < sign. This will redirect the standard input so that it will come from the file given after the < sign instead of the keyboard. This can be used when you want to input a file to a command that would not normally take a file as its input.


Previous Topic/Section
Examples of Using Meta Characters
Previous Page
Pages in Current Topic/Section
1
Next Page
Shell Information
Next Topic/Section

If you find CertiGuide.com useful, please consider making a small Paypal donation to help the site, using one of the buttons below. You can also donate a custom amount using the far right button (not less than $1 please, or PayPal gets most/all of your money!) In lieu of a larger donation, you may wish to consider buying an inexpensive PDF equivalent of the CertiGuide to A+ (A+ 4 Real) from StudyExam4Less.com. Thanks for your support!
Donate $2
Donate $5
Donate $10
Donate $20
Donate $30
Donate: $



Home - Table Of Contents - Contact Us

CertiGuide to A+ (A+ 4 Real) (http://www.CertiGuide.com/apfr/) on CertiGuide.com
Version 1.0 - Version Date: March 29, 2005

Adapted with permission from a work created by Tcat Houser et al.
CertiGuide.com Version Copyright 2005 Charles M. Kozierok. All Rights Reserved.
Not responsible for any loss resulting from the use of this site.