Pipes And - Red Hat ENTERPRISE LINUX 3 - STEP BY STEP GUIDE Manual

Table of Contents

Advertisement

36
Chapter 3. Shell Prompt Basics
3.9. Pipes and Pagers
In Linux, pipes connect the standard output of one command to the standard input of another com-
mand.
Consider the
command that was discussed earlier. There are plenty of options available with
,
ls
ls
but what if the contents of a directory scroll by too quickly for you to view them?
View the contents of the
directory with the command:
/etc/
ls -al /etc
How do you get a closer look at the output before it moves off the screen?
One way is to pipe the output to a utility called
, a pager utility that allows you to view informa-
less
tion one page (or screen) at a time.
Use the vertical bar (
) to pipe the commands.
|
ls -al /etc | less
Now you can view the contents of
one screen at a time. To move forward a screen, press
/etc/
[Space]; to move back a screen, press [B]; to quit, press [Q]. Alternatively, you can use the arrow keys
to navigate with
.
less
To search the output of a text file using
, press [/] and then type the keyword you want to search
less
for within the file. For example:
/Linux
Pipes can also be used to print only certain lines from a file. Type:
grep coffee sneakers.txt | lpr
This command prints every line in the
file that mentions the word "coffee" (read more
sneakers.txt
about
in Section 3.10.3 The
Command).
grep
grep
3.9.1. The
Command
more
The main difference between
and
is that
allows backward and forward movement
more
less
less
using the arrow keys, while
only uses the [Spacebar] and the [B] key for forward and backward
more
navigation.
List the contents of the
directory using
and
.
/etc/
ls
more
ls -al /etc | more

Advertisement

Table of Contents
loading

This manual is also suitable for:

Enterprise linux 3

Table of Contents