0% found this document useful (0 votes)
105 views3 pages

SLE201v15 Lab Exercise 3.3

This document describes an exercise in redirecting command output and piping commands together. It has the user redirect command output to files to create, overwrite, and append to files. It also has the user pipe command output to count lines, number lines, prepare files for printing, and view identical output on the console and save to a file simultaneously. The goal is to practice common Linux utilities like ls, cat, wc, nl, pr, tee, and less while manipulating file input and output.

Uploaded by

omar walid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views3 pages

SLE201v15 Lab Exercise 3.3

This document describes an exercise in redirecting command output and piping commands together. It has the user redirect command output to files to create, overwrite, and append to files. It also has the user pipe command output to count lines, number lines, prepare files for printing, and view identical output on the console and save to a file simultaneously. The goal is to practice common Linux utilities like ls, cat, wc, nl, pr, tee, and less while manipulating file input and output.

Uploaded by

omar walid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

SUSE Linux Enterprise Administration

3- 3 Use Piping and Redirection

Description:

y
In this exercise, you redirect the output of commands into files and pipe the output of

nl
commands to other commands.

O
e
Task 1: Open a terminal session

te Us
1. On server2, as the tux user, open a terminal by clicking on the Activities menu and
type:
terminal

bu r
tri ne
When the Terminal icon appears, click on it to start a terminal session
Task 2: Use Redirection to Create a File
is rt
D Pa
1. Redirect the output of a command to a file on disk with:
ls /etc > dir-listing.txt
ot d

2. Count the number of lines in the resulting file with:


N an

wc -l dir-listing.txt
Note the number of lines indicated for later reference.
D al

Task 3: Use Redirection to Overwrite a File


rn

1. Redirect the output of a command to a file on disk with:


te

ls ~ > dir-listing.txt
o

2. Count the number of lines in the resulting file with:


In

wc -l dir-listing.txt
SE

Compare this number of lines with the previous steps number, indicating the file was
overwritten by the contents of your home directory.
SU

Task 4: Use Redirection to Append to a File


1. Redirect the output of a command to a file on disk with:
ls ~ >> dir-listing.txt
2. Count the number of lines in the resulting file with:
wc -l dir-listing.txt
Compare this number of lines with the previous steps number, the file has doubled in
size, showing that the output was appended to the file.

31
SUSE Linux Enterprise Administration
Task 5: Copy and Count the Lines in a File
1. Copy a sample text file from the documentation directories with:
cp /usr/share/doc/packages/vim/README.txt vim-readme.txt
2. Count the number of lines in the resulting file with:
wc -l vim-readme.txt
The file should contain 133 lines of content.

y
nl
Task 6: Number the Lines in a File

O
1. Number just the lines of a file that have content with:
nl vim-readme.txt

e
You will see the output indicates that 88 lines were numbered, leaving blank lines

te Us
unnumbered.
2. Number all lines of a file with:

bu r
nl -ba vim-readme.txt

tri ne
You will see the output indicates that all 133 lines were numbered, including lines with
no content.
is rt
D Pa
Task 7: Prepare a File for Printing
1. Keeping in mind the original number of lines in the file, add page numbers, line widths
and double-spacing to the file with:
ot d
N an

pr -d vim-readme.txt | wc -l
You will observe that the file is considerably lengthened by the formatting added to it by
the command.
D al

Task 8: Using Pipes and Redirection Together


rn

1. Prepare a raw text file on disk for printing and display the identical output on the console
te

with:
o
In

cat vim-readme.txt | nl -ba | pr | tee vim-readme.2print | less


2. Navigate to the bottom of the output in less with:
SE

G
Note the number of lines in the output, for comparison in the next step.
SU

3. Quit the less command with:


q
4. Verify the number of lines of content in the vim-readme.2print file with:
wc -l vim-readme.2print
The number of lines indicated should match the number of lines in the less command’s
output, showing the exact output was shown on screen and committed to disk.
5. Close the terminal window

32
SUSE Linux Enterprise Administration

Summary:
In this exercise, you redirected the output of a command.

y
(End of Exercise)

nl
O
e
te Us
bu r
tri ne
is rt
D Pa
ot d
N an
D al
rn
te
o
In
SE
SU

33

You might also like