0% found this document useful (0 votes)
174 views

Linux POWER USER PDF

Uploaded by

nilelinux
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)
174 views

Linux POWER USER PDF

Uploaded by

nilelinux
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/ 446

V2.0.0.

cover

 Front cover

Linux
Power User
(Course Code LX02)

Student Notebook
ERC 3.0

IBM Certified Course Material


Student Notebook

Trademarks
IBM® is a registered trademark of International Business Machines Corporation.
The following are trademarks of International Business Machines Corporation in the United
States, or other countries, or both:
AIX® AT® DB2®
Domino™ Lotus® OS/2®
PS/2®
Microsoft, Windows and Windows NT are trademarks of Microsoft Corporation in the
United States, other countries, or both.
Intel and Pentium are trademarks of Intel Corporation in the United States, other countries,
or both.
UNIX is a registered trademark of The Open Group in the United States and other
countries.
Linux is a registered trademark of Linus Torvalds in the United States and other countries.
Other company, product and service names may be trademarks or service marks of others.

June 2003 Edition

The information contained in this document has not been submitted to any formal IBM test and is distributed on an “as is” basis without
any warranty either express or implied. The use of this information or the implementation of any of these techniques is a customer
responsibility and depends on the customer’s ability to evaluate and integrate them into the customer’s operational environment. While
each item may have been reviewed by IBM for accuracy in a specific situation, there is no guarantee that the same or similar results will
result elsewhere. Customers attempting to adapt these techniques to their own environments do so at their own risk.

© Copyright International Business Machines Corporation 2001, 2003. All rights reserved.
This document may not be reproduced in whole or in part without the prior written permission of IBM.
Note to U.S. Government Users — Documentation related to restricted rights — Use, duplication or disclosure is subject to restrictions
set forth in GSA ADP Schedule Contract with IBM Corp.
V2.0
Student Notebook

TOC Contents
Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi

Course Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii

Agenda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv

Certification Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii

Unit 1. Introduction to Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
A Short History of Linux (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
A Short History of Linux (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
What’s So Special About Linux? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8
Effects of the License Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-10
Linux has become a Way of Life . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12
Linux Today . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13
Linux Hardware Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-17

Unit 2. Installing Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Preparing a System for Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3
Know your Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
Partitioning Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
Partitioning Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7
PartitionMagic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9
Installing Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10
Installation Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12
Select Language, Keyboard, Mouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13
Install Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14
Disk Partitioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15
Configure a Boot Loader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17
Configure Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19
Configure Root and User Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20
Select Package Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21
Configure X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
Other (Optional) Installation Screens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24
Installing Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-25
Create Boot Disk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26
Reboot System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-28
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-29

© Copyright IBM Corp. 2001, 2003 Contents iii


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Unit 3. Using the System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-2
Linux is Multi-user and Multi-tasking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-3
Virtual Terminals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-5
Logging In (Text Mode VT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-6
Logging In (Graphical Mode VT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-7
Linux Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-8
Starting a Terminal Emulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-9
Command Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-10
Linux Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-11
Command Format Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-12
Some Basic Linux Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-13
Changing your Password . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-14
The date Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-16
The cal Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-17
Who Is on the System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-18
Finding Information about Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-19
The clear, echo, write and wall Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-20
Talk with Another User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-21
The mesg Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-22
Keyboard Tips (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-23
Keyboard Tips (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-24
Command History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-25
Retrieving commands with “!” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-26
Console Mouse Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-27
Locking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-28
Logging Out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-29
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-30
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-31

Unit 4. Working with Files and Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-2
A File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-3
File Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-4
Linux Filenames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-5
Linux Pathnames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-6
Example Directory Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-7
Where Am I? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-8
Change Current Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-9
Create Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-10
Removing Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-11
Working with Multiple Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-12
List of Contents of Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-13
The touch Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-14
Copying Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-16
Copying Files (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-17
Moving and Renaming Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-18
Moving and Renaming Files (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-19

iv Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

TOC Listing File Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20


Displaying Files Page by Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21
Displaying Binary Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-22
Removing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-23
Splitting Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-24
File Managers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-26
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-27

Unit 5. File and Directory Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Users and Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
Viewing Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5
Permissions Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6
Required Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8
Changing Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9
Changing Permissions (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11
umask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15

Unit 6. Linux Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
The man Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3
man Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5
man Example (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6
man Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-7
The info Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8
info Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-10
The --help Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12
HOWTO Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-13
HOWTO Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-14
Other Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-15
Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-16
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-17
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-18

Unit 7. A Tour through Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2
Directory Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
/bin, /lib, and /sbin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4
/boot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-5
/dev . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7
/etc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9
/home . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-10
/mnt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-11
/proc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-12

© Copyright IBM Corp. 2001, 2003 Contents v


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

/root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-13
/tmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-14
/usr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-15
/var . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-17
/lost+found . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-18
Other Directories in / . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-19
The mount Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-20
The umount Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-22
The /etc/fstab File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-23
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-25
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-26

Unit 8. Editing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-2
Editing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-3
The "vi" text editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-5
vi Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-7
Starting vi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-8
Cursor Movement in Command Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-9
Editing Text in Command Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-10
Switching to Edit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-11
Adding Text in Edit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-12
Exiting the Edit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-13
Searching for Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-14
Replacing Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-15
Cut, Copy and Paste . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-16
Cut and Paste . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-17
Copy and Paste . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-18
vi Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-19
Exiting vi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-21
vi Cheat Sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-22
Other Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-23
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-24
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-25

Unit 9. Working with Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-2
What is a Process? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-3
Starting and Stopping a Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-4
Login Process Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-5
Parents and Children . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-6
Monitoring Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-7
Viewing Process Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-8
Controlling Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-9
Starting Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-10
Job Control in the Bash Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-12
Job Control Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-13
Kill Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-14

vi Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

TOC Running Long Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-16


Managing Process Priorities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-17
The nice command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-19
The renice Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-20
Integrated Process Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-21
Daemons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-22
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-23
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-24

Unit 10. Shell Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
The Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-3
Shell Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-4
Metacharacters and Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-5
Basic Wildcard Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-6
Advanced Wildcard Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-7
File Descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-8
Input Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-9
Output Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-10
Error Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-11
Combined Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-13
Pipes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-14
Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-15
Common Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-16
Split Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-18
Command Substitution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-19
Command Grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-20
Shell Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-21
Referencing Shell Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-22
Exporting Shell Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-23
Standard Shell Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-24
Return Codes from Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-26
Quoting Metacharacters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-27
Quoting Non-Metacharacters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-28
Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-29
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-30
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-31

Unit 11. Linux Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
The find Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-3
Sample Directory Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-4
Using find . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-5
Executing Commands with find . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-6
Interactive Command Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7
Additional find Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-8
find Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-10
locate Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-11

© Copyright IBM Corp. 2001, 2003 Contents vii


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

The cut Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-12


cut Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-13
cut Example (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-14
The grep Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-15
grep Sample Data Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-16
Basic grep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-17
grep with Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-18
Regular Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-19
grep Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-20
Other greps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-21
The sort Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-22
sort Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-23
The head and tail Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-24
The type, which and whereis Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-26
The file Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-28
The gzip, gunzip, and zcat Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-29
The join and paste Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-31
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-32
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-33

Unit 12. Shell Scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-2
What is a Shell Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-3
Invoking Shell Scripts (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-4
Invoking Shell Scripts (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-5
Invoking Shell Scripts (3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-6
Invoking Shell Scripts In Another Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-7
Typical Shell Script Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-8
Shell Script Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-9
Complex Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-11
Conditional Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-13
The test Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-14
The test Command (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-15
The && and || Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-17
The if Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-18
Command Repetition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-19
The while Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-20
The for Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-21
Shifting Shell Script Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-22
User Interaction: The read Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-24
Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-25
The expr Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-27
Command Search Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-28
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-29
Checkpoint (2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-30
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-31

viii Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

TOC Unit 13. The Linux GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-2
The Linux Graphical User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-3
Client/Server Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-4
X Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-5
X Servers in Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-7
XFree86 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-8
Desktop Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-10
The K Desktop Environment (KDE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-11
The GNOME Desktop Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-13
Starting X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-14
Choosing your Desktop Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-16
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-17
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-18

Unit 14. Customizing the User Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-2
Bash Initialization (Login Shell) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-3
Bash Initialization (non-Login Shell) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-4
Bash Initialization with Red Hat Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-5
Bash Initialization with SuSE Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-7
KDE Customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-9
GNOME Customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-10
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-11
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-12

Unit 15. Basic System Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-2
Why System Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-3
System Configuration Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-5
Adding/Removing Software using RPM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-7
Querying the RPM Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-9
Adding/Removing Software from a .tar.gz File . . . . . . . . . . . . . . . . . . . . . . . . . . 15-10
Printer Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-12
Sound Card Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-14
Network Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-15
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-17
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-18

Unit 16. Connecting to the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-2
Connecting to the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-3
Modem Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-5
Modem Connections in Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-6
ISDN Principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-8
ISDN in Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-9
Cable Modem Principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-11
xDSL Principles (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-13

© Copyright IBM Corp. 2001, 2003 Contents ix


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Cable Modems in Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16-14


Internet Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16-15
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16-21
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16-22

Unit 17. Integrating Linux in a Windows Environment . . . . . . . . . . . . . . . . . . 17-1


Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-2
Accessing Files on Windows Filesystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-3
Mounting Windows Filesystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-5
Accessing Windows Filesystems Directly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-6
Running Windows Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-8
PC Emulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-9
VMWare Screenshot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-11
Windows Emulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-12
win4lin Screenshot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-14
WINE Screenshot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-15
Accessing Windows Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-16
smbclient Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-18
smbmount Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-19
smbprint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-20
Reading Windows Document Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-21
Other Useful Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-22
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-23
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17-24

Appendix A. Checkpoint Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1

Appendix B. Certification Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-1

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . X-1

x Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

TMK Trademarks
The reader should recognize that the following terms, which appear in the content of this
training document, are official trademarks of IBM or other companies:
IBM® is a registered trademark of International Business Machines Corporation.
The following are trademarks of International Business Machines Corporation in the United
States, or other countries, or both:
AIX® AT® DB2®
Domino™ Lotus® OS/2®
PS/2®
Microsoft, Windows and Windows NT are trademarks of Microsoft Corporation in the
United States, other countries, or both.
Intel and Pentium are trademarks of Intel Corporation in the United States, other countries,
or both.
UNIX is a registered trademark of The Open Group in the United States and other
countries.
Linux is a registered trademark of Linus Torvalds in the United States and other countries.
Other company, product and service names may be trademarks or service marks of others.

© Copyright IBM Corp. 2001, 2003 Trademarks xi


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

xii Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

pref Course Description


Linux Power User

Duration: 5 days

Purpose
The purpose of this course is to teach the students how to install,
configure and use Linux on their personal workstation, so that they can
use this system for their daily work.

Audience
This course is designed for students with little or no Linux knowledge
or experience, who want to make a start with Linux.

Prerequisites
• Be able to use a Microsoft Windows-based workstation

Objectives
On completion of this course, students should be able to:
• Install and configure Linux on a workstation
• Use Linux for their daily work.

Contents
• History and culture of Linux
• Installing Linux
• Using the system
• Working with files and directories
• Linux documentation
• A tour through Linux
• Editing files
• Working with processes

© Copyright IBM Corp. 2001, 2003 Course Description xiii


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

• Shell basics
• Linux utilities
• Shell Scripting
• The Linux GUI
• Customizing the User Environment
• Basic system configuration
• Connecting to the internet
• Integrating Linux in a Windows environment.

xiv Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

pref Agenda
Day 1
Unit 1 - Introduction to Linux
Unit 2 - Installing Linux
Exercise 2 - Installing Linux
Unit 3 - Using the System
Exercise 3 - Using the System
Unit 4 - Working with Files and Directories
Exercise 4 - Working with Files and Directories

Day 2
Unit 5 - File and Directory Permissions
Exercise 5 - File and Directory Permissions
Unit 6 - Linux Documentation
Exercise 6 - Linux Documentation
Unit 7 - A Tour through Linux
Exercise 7 - A Tour through Linux
Unit 8 - Editing Files
Exercise 8 - Editing Files

Day 3
Unit 9 - Working with Processes
Exercise 9 - Working with Processes
Unit 10 - Shell Basics
Exercise 10 - Shell Basics
Unit 11 - Linux Utilities
Exercise 11 - Linux Utilities

Day 4
Unit 12 - Shell Scripting

© Copyright IBM Corp. 2001, 2003 Agenda xv


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Exercise 12 - Shell Scripting


Unit 13 - The Linux GUI
Exercise 13 - The Linux GUI
Unit 14 - Customizing the User Environment
Exercise 14 - Customizing the User Environment

Day 5
Unit 15 - Basic System Configuration
Exercise 15 - Basic System Configuration
Unit 16 - Connecting to the Internet
Exercise 16 - Securing a Linux Workstation
Unit 17 - Integrating Linux in a Windows Environment
Exercise 17 - Integrating Linux in a Windows Environment
Exercise 18 - End-of-Course Challenge Exercise (optional)

xvi Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

pref Certification Information


Several professional certifications currently exist for Linux. This
course, combined with other Linux courses, will prepare you for all of
them. For more information, see appendix B.
This course, in combination with other courses, has been certified by
ProCert (http://www.procert.com) as appropriate course material for
preparing for LPI certification tests. The statement below reflects this.

Linux Professional Institute Statement


“This course is specifically designed to provide you with the skills,
knowledge and understanding required to become professionally
certified by LPI. To learn more about LPI certifications, or to register to
take an official LPI certification exam, visit www.lpi.org.”

© Copyright IBM Corp. 2001, 2003 Certification Information xvii


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

xviii Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 1. Introduction to Linux

What This Unit Is About


This unit is a short introduction to the history and current status of
Linux.

What You Should Be Able to Do


After completing this unit, you should be able to:
• Discuss the history of Linux
• Name some important people in the history of Linux
• Discuss the GNU General Public License

How You Will Check Your Progress


Accountability:
• Checkpoint questions

© Copyright IBM Corp. 2001, 2003 Unit 1. Introduction to Linux 1-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
'LVFXVVWKHKLVWRU\RI/LQX[
1DPHVRPHLPSRUWDQWSHRSOHLQWKHKLVWRU\RI/LQX[
'LVFXVVWKH*18*HQHUDO3XEOLF/LFHQVH

Figure 1-1. Objectives LX023.0

Notes:

1-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
$6KRUW+LVWRU\RI/LQX[ 

5LFKDUG6WDOOPDQVWDUWV*18
SURMHFW
*18
V1RW8QL[
KWWSZZZJQXRUJ
3XUSRVH)UHH81,;
)UHHDVLQ)UHH6SHHFKQRW
)UHH%HHU
)LUVWVWHSUHLPSOHPHQWDWLRQRI
81,;8WLOLWLHV
&FRPSLOHU&OLEUDU\
HPDFV
EDVK
7RIXQGWKH*18SURMHFWWKH)UHH
6RIWZDUH)RXQGDWLRQLVIRXQGHG
KWWSZZZIVIRUJ
Figure 1-2. A Short History of Linux (1) LX023.0

Notes:
The history of Linux starts properly in 1984. In that year, a system administrator working at
Massachusetts Institute of Technology (MIT), Richard Stallman, received a new version of
the UNIX flavor they were using. But in contrast to previous versions, this time they did not
receive the source of the operating system with it, and could not obtain the source
separately without signing a Non-Disclosure Agreement (NDA). Richard Stallman was
therefore not able to implement a certain additional feature into the operating system which
his users had come to like.
Richard Stallman became so upset with these developments in general that he vowed to
write a new UNIX-like operating system from scratch. That new operating system was
supposed to be free (as in free speech): Everybody would have the right to use and adapt
the software for its own use, and to distribute the software to others. (More about this later.)
This project was called GNU, which stands for GNU's Not Unix.
To fund the GNU project and to advocate the use of free software in general, the Free
Software Foundation (FSF) was founded.

© Copyright IBM Corp. 2001, 2003 Unit 1. Introduction to Linux 1-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

The first steps taken by the GNU project was to re-implement various essential utilities in a
UNIX operating system. Although hundreds of little tools were written, four tools stand out:
• The GNU C compiler (gcc), which was essential for compiling all software, including the
kernel and the C compiler itself.
• The GNU C library (glibc), which implements a large set of standardized system calls.
• emacs, which is a full-featured, world class editor which can be extended into a sort of
application development environment.
• bash (Bourne Again Shell), a command interpreter and programming environment.
Having a shell is essential on a UNIX system, since the shell interprets and executes the
commands you type.
Later on, the GNU project also started development on a UNIX-like kernel1, called Hurd.
This kernel has never been important for Linux however, since it was released for the first
time at the end of the 1990s, when Linux was already thriving.

1
The kernel of an operating system is the program that runs 24 hours a day, and takes care of scheduling, device handling, memory
management and so forth.

1-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
$6KRUW+LVWRU\RI/LQX[ 

/LQXV7RUYDOGVZULWHVVW
YHUVLRQRI/LQX[NHUQHO
,QLWLDOO\DUHVHDUFKSURMHFW
DERXWWKHSURWHFWHGPRGH
/LQXV
81,;!/LQX[
&RPELQHGZLWKWKH*18DQG
RWKHUWRROVIRUPVDFRPSOHWH
81,;V\VWHP
)LUVWGLVWULEXWLRQVHPHUJH
/LQX[NHUQHO
*18DQGRWKHUWRROV
,QVWDOODWLRQSURFHGXUH
7KHUHVWLVKLVWRU\

Figure 1-3. A Short History of Linux (2) LX023.0

Notes:
In 1991, a student at the University at Helsinki, Linus Torvalds, started a small research
project into the workings of the Intel 80386 processor, which by then was state-of-the-art.
He was interested in exploring a new feature which up to then was not present in any Intel
processor, namely a Memory Management Unit. This MMU offered hardware support for
running multiple processes simultaneously, each in its own memory segment. With such an
MMU, processes cannot access memory areas owned by other processes, and this
effectively means that if one process crashes, it cannot take the whole system down with it.
The operating systems that were available for the 386 (Windows for Workgroups and
Minix) all did not use this feature and were therefore very prone to crashing. ("Who is
General Failure and why is he reading my hard disk?")
Linus started out writing three small programs:
• A small program which continuously printed the letter A on the screen.
• A small program which continuously printed the letter B on the screen.

© Copyright IBM Corp. 2001, 2003 Unit 1. Introduction to Linux 1-5


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

• A slightly larger program which switched the processor to "protected mode" and
scheduled the other two programs to take turns.
When Linus finally managed to see the output of both programs on his screen, in turn
(ABABABAB...), he knew he had the beginnings of a kernel of a multitasking operating
system.
Linus continued to improve and refine the kernel, and at the end of 1991, he was able to
run the GNU C compiler and the Bash shell under his kernel, which by then was dubbed
Linux, for Linus' UNIX.
Linus then decided to upload this to the internet (which by then was still largely a university
network) for others to use:
From: [email protected] (Linus Benedict Torvalds)
Newsgroups: comp.os.minix
Subject: What would you like to see most in minix?
Summary: small poll for my new operating system
Message-ID: <[email protected]>
Date: 25 Aug 91 20:57:08 GMT
Organization: University of Helsinki

Hello everybody out there using minix -


I'm doing a (free) operating system (just a hobby, won't be big and
professional like gnu) for 386(486) AT clones. This has been brewing
since April, and is starting to get ready. I'd like any feedback on
things people like/dislike in minix, as my OS resembles it somewhat
(same physical layout of the file-system (due to practical reasons)
among other things). I've currently ported bash(1.08) and gcc(1.40),and
things seem to work.This implies that I'll get something practical within a
few months, and I'd like to know what features most people would want. Any
suggestions are welcome, but I won't promise I'll implement them :-)
Linus ([email protected])
PS. Yes - it's free of any minix code, and it has a multi-threaded fs.
It is NOT protable (uses 386 task switching etc), and it probably never
will support anything other than AT-harddisks, as that's
all I have :-(.
Other people on the internet started picking up this software, started using it, and refined it.
The patches were sent to Linus, who incorporated this into the main kernel stream.
Starting to use Linux was a major undertaking, however. The Linux kernel, the C compiler,
the shell and all the other tools you need to make a complete operating system were all
distributed in source code form. Before you can make use of them, you need to compile
them, which requires a C compiler, which itself also needs to be compiled first... To break
through this vicious circle, people started creating "distributions", which contain a
precompiled kernel, a precompiled C compiler, various precompiled tools and some sort of

1-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty installation program. All this is stored in a convenient format for installation (originally floppy
disk images, but today CD-ROM images are prevalent).
The rest, as they say, is history...

© Copyright IBM Corp. 2001, 2003 Unit 1. Introduction to Linux 1-7


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

:KDW
V6R6SHFLDO$ERXW/LQX["

0RVWVRIWZDUH LQFOXGLQJWKH/LQX[NHUQHO LV*3/


HG
*18*HQHUDO3XEOLF/LFHQVH
KWWSZZZJQXRUJFRS\OHIWJSOKWPO
,VFDOOHGFRS\OHIW LQVWHDGRIFRS\ULJKW
<RXPD\FRS\WKHVRIWZDUH
<RXJHWWKHVRXUFHFRGH
<RXPD\DOWHUWKHVRXUFHFRGHDQGUHFRPSLOHLW
<RXPD\GLVWULEXWHWKHDOWHUHGVRXUFHDQGELQDULHV
<RXPD\FKDUJHPRQH\IRUDOOWKLV
<RXRQO\PD\QRWFKDQJHWKHOLFHQVH
6RDOO\RXUFXVWRPHUVKDYHWKHVDPHULJKWVDV\RX
6R\RXUHDOO\FDQQRWPDNHPRQH\IURPVHOOLQJWKH
VRIWZDUHDORQH
2WKHU2SHQ6RXUFHOLFHQVHV HJ%6' DUHDOVRXVHG

Figure 1-4. What’s So Special About Linux? LX023.0

Notes:
To understand what's so special about Linux, it is necessary to quickly look at international
copyright laws. The principle of copyright is very simple: When an author creates a unique
piece of work, such as a computer program, then he is the owner of all rights to that piece
of work. He may decide what others can and cannot do with it.
What others may do with that piece of work is usually written down in a License Statement,
a contract between the creator and the user which describes the rights that the user has.
These rights may be granted for free, but in most cases the user has to pay for them.
A typical license in the world of computer software entitles the user to run the binary
program on the number of machines that the license was purchased for. It is not allowed to
make more copies of the software than needed for running it, and one extra backup copy.
Furthermore, the user cannot claim any rights to the source code and is not allowed to
dissemble the binary code to learn and/or alter its inner workings. In short, a typical
copyright statement does not give you the right to copy.
In contrast, the GNU General Public License or GPL for short, turns this around. The aim of
the GPL is to keep all software "free", so that everybody can adapt the software to its own

1-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty needs, without being dependent on the goodwill of the author. This means that any piece of
software that has been placed under the GPL by the original author gives the user the
following rights:
• The user may copy the (binary) software as often as he or she wishes.
• The user has the right to obtain the source code.
• The user has the right to alter the source code and recompile the source code into
binary form.
• The user may distribute the sources and the binaries.
• The user may charge money for all of this.
Basically the only restriction that the GPL imposes on all users is that the license statement
may not be changed. This means that all your customers have the same rights to the
software as you do. And as a practical aside, that means that in general it is impossible to
make any money from selling the software (apart from a nominal fee for media and
distribution).
The GPL is the most-often used license statement in the Linux world, but other open
source licenses, such as the BSD license, are also being used.

© Copyright IBM Corp. 2001, 2003 Unit 1. Introduction to Linux 1-9


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

(IIHFWVRIWKH/LFHQVH0RGHO

(YHU\ERG\KDVDFFHVVWRWKHVRXUFH
9ROXQWHHUVRIWZDUHGHYHORSPHQWRQWKH,QWHUQHWZLWK
FHQWUDOFRRUGLQDWLRQ
/LQXV7RUYDOGVFRRUGLQDWHVNHUQHOGHYHORSPHQW
2WKHUVFRRUGLQDWHRWKHUSLHFHVRIWKH26
3HHUUHYLHZVSRVVLEOH
6HFXULW\
3HUIRUPDQFH
/LFHQVHFDQQRWFKDQJH
6R\RXUFKDQJHV DQGQDPH ZLOOVWD\LQIRUHYHU

Figure 1-5. Effects of the License Model LX023.0

Notes:
The effects of this license model are far reaching:
The first effect is that, since everybody has access to the source code, everybody
interested can improve the code, or add new features. This means that software
development is very rapid, with potentially hundreds of developers working on the same
piece of code. People in the Linux community understand the inherent risk of a code fork
with a development model like this, and a lot of effort is spent in coordinating the work of
various developers. This usually comes down to two things:
• A volunteer or group of volunteers who take up the coordination of the development.
Linus Torvalds for instance hardly writes any code anymore, but spends most of his time
coordinating others who write code for the kernel. And other people coordinate the
development on other programs.
• Some sort of automated support for distinguishing and integrating contributions of
developers. Most often, the CVS (Concurrent Versioning System) is used.

1-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty As an example, the sourceforge.net website hosts thousands of projects who all are
managed using CVS.
Another effect of having the source available is that peer reviews are possible. It is easy for
people to look through the code and identify any performance or security problems. In fact,
there is currently a "Linux Janitor" project underway which aims at auditing the Linux code
automatically, searching for typical, well known programming errors. This is most likely the
first time where large-scale white-box testing2 is being automated.
A third effect of the license model is that if you make any changes, or add a feature, then
that feature is owned by you, and not by the original author of the software. This means
that your name (as part of the copyright statement for that feature) stays in forever. This is
usually a great motivation factor for people.

2
White-box testing means testing a device of which the components are known to you, so you can examine each and every component
individually. In software testing, this usually means that the source code is available for testing. In contrast to white-box testing stands
black-box testing, where the individual components are not known. You can only test the whole system. In general, white-box testing is
more complicated than black-box testing but tends to find far more bugs.

© Copyright IBM Corp. 2001, 2003 Unit 1. Introduction to Linux 1-11


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

/LQX[KDVEHFRPHD:D\RI/LIH

&XOWXUH +XPRU
8VHUIULHQGO\
&HOHEULWLHV
6HJIDXOW
/LQXV7RUYDOGV
5LFKDUG6WDOOPDQ 0DVFRW
(ULF5D\PRQG 7X[

Figure 1-6. Linux has become a Way of Life LX023.0

Notes:
For a large number of people, Linux is not just another operating system, but it has become
a way of life for them. It is something they believe in, and they want to express that belief.

1-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
/LQX[7RGD\

/LQX[FRYHUVWKHZKROHVSHFWUXPRIFRPSXWLQJ
(PEHGGHGGHYLFHV
/DSWRSV 6XSHUFRPSXWHUV
'HVNWRSV\VWHPV 0DLQIUDPHV

'HYHORSPHQWV\VWHPV
6PDOODQGODUJHVHUYHUV
0HJDFOXVWHUVVXSHUFRPSXWHUV
/DSWRSV'HVNWRSV
'HSDUWPHQWVHUYHUV
/LQX[LVXVHGWKURXJKRXWWKHZRUOG 3HUYDVLYH
DQGLQVSDFH &RPSXWLQJ

/LQX[LVXVHGE\KRPHXVHUV
DQGE\VRPHRIWKHODUJHVWFRPSDQLHVLQWKHZRUOG
,%0
%RHLQJ
1$6$

Figure 1-7. Linux Today LX023.0

Notes:
Linux was originally developed for the Intel 80386 processor, and could therefore run on
any Intel processor (486, Pentium,...) after that. But somewhere around 1994, Richard
Stallman gave Linus Torvalds an old Dec Alpha machine. A few months later, Linux was
ported to the Dec Alpha. Since then, Linux has been ported to a variety of architectures,
which allows it to run on a variety of small and large systems.
The smallest implementations of Linux can be found in embedded devices: the microchips
that control your VCR, microwave and so forth. IBM even has created a wristwatch running
Linux. (Well, wristwatch... You can wear it on your wrist and watch xclock running.)
Linux also runs on laptops, with Advanced Power Management features and LCD displays,
it runs on regular desktop systems, development workstations, and small and large
servers. And it is even used to power some of the largest supercomputers in the world3.

3
See http://www.top500.org.

© Copyright IBM Corp. 2001, 2003 Unit 1. Introduction to Linux 1-13


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Linux is used throughout the world, and in space: Various experiments on board of NASAs
spacelab and in the International Space Station are controlled by systems running Linux.
And Linux is used by home users and by some of the largest companies in the world.

1-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
/LQX[+DUGZDUH6XSSRUW

[6HULHV L6HULHVS6HULHV]6HULHV
,QWHO  3RZHU3&  3RZHU3&  0DLQIUDPH

DOVRVXSSRUWHG&RPSDT$OSKD$50
+LWDFKL6XSHU++HZOHWW3DFNDUG'(&9$;
0,36

Figure 1-8. Linux Hardware Support LX023.0

Notes:
The visual shows the various hardware architectures and components that are supported
by Linux. Pretty spectacular eh?

© Copyright IBM Corp. 2001, 2003 Unit 1. Introduction to Linux 1-15


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&KHFNSRLQW

7)/LQXV7RUYDOGVZURWHWKH/LQX[2SHUDWLQJ6\VWHP
DOOE\KLPVHOI

:KLFKRIWKHIROORZLQJVWDWHPHQWVLV127WUXHDERXW
VRIWZDUHOLFHQVHGXQGHUWKH*18*3/"
D<RXKDYHWKHULJKWWRREWDLQDQGUHYLHZWKHVRXUFHFRGH
E<RXPD\QRWFKDUJHDQ\PRQH\IRUWKHVRIWZDUH
F<RXPD\QRWFKDQJHWKHOLFHQVHVWDWHPHQW
G<RXPD\PRGLI\WKHVRXUFHFRGHDQGVXEVHTXHQWO\
UHFRPSLOHLW

:KRLVWKHPDVFRWRI/LQX["

Figure 1-9. Checkpoint LX023.0

Notes:

1-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
8QLW6XPPDU\

7KH/LQX[NHUQHOFRPELQHGZLWKWKH*18DQGRWKHU
WRROVIRUPDFRPSOHWH81,;OLNHRSHUDWLQJV\VWHP
$GLVWULEXWLRQDGGVDQLQVWDOODWLRQSURFHGXUHDQGD
FRQYHQLHQWIRUPDWIRUGLVWULEXWLRQ
0RVWVRIWZDUHLQD/LQX[GLVWULEXWLRQLVOLFHQVHGXQGHU
2SHQ6RXUFHOLFHQVHVVXFKDVWKH*18*3/
/LQX[KDVEHHQSRUWHGWRPRUHWKDQWHQKDUGZDUH
DUFKLWHFWXUHVDQGVXSSRUWVYLUWXDOO\DOO3&KDUGZDUH
/LQX[LVXVHGLQDYDULHW\RIVPDOODQGODUJHDSSOLFDWLRQV

Figure 1-10. Unit Summary LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 1. Introduction to Linux 1-17


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

1-18 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 2. Installing Linux

What This Unit Is About


This unit will show the student how to perform an installation of Linux
on a workstation.

What You Should Be Able to Do


After completing this unit, you should be able to:
• Prepare a system for installation
• Install Linux from CD-ROM

How You Will Check Your Progress


Accountability:
• Checkpoint questions
• Machine exercises

© Copyright IBM Corp. 2001, 2003 Unit 2. Installing Linux 2-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
3UHSDUHDV\VWHPIRULQVWDOODWLRQ
,QVWDOO/LQX[IURP&'520

Figure 2-1. Objectives LX023.0

Notes:

2-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
3UHSDULQJD6\VWHPIRU,QVWDOODWLRQ

.QRZ\RXUKDUGZDUH
&38PHPRU\NH\ERDUGPRXVH
+DUGGLVNV&'520SOD\HUV
*UDSKLFDODGDSWHUVPRQLWRUFDSDELOLWLHV
1HWZRUNDGDSWHUV,3DGGUHVVHV
3ULQWHUV
,VDOO\RXUKDUGZDUHVXSSRUWHG"
/LQX[+DUGZDUH+2:72
'LVWULEXWRUV+DUGZDUH&RPSDWLELOLW\/LVW
+DUGZDUHPDQXIDFWXUHU
,IXQVXUHMXVWWU\LW
0DNHVSDFHIRU/LQX[SDUWLWLRQV

Figure 2-2. Preparing a System for Installation LX023.0

Notes:
Before you install a Linux system, there are some things you should do. One of the most
important steps is knowing what hardware you have, and all the characteristics and
configuration options of that hardware.
Furthermore, you need to verify that all your hardware is supported by Linux. Since not all
hardware manufacturers make the specifications of their hardware public, some hardware
is not supported, or not supported in full. For a detailed list of hardware supported by Linux,
refer to the Hardware-HOWTO at http://www.tldp.org. Also, your distributor may have
several restrictions on the hardware that their distribution supports. You may also be able
to obtain information from the hardware manufacturer itself.
If you are unsure whether your hardware is supported, then just go ahead and try it.
Another important step is making space for Linux partitions. Linux cannot be installed in a
Windows partition, and thus needs free, unpartitioned space for its own partitions. Since
most PCs today ship with the whole hard disk partitioned for Windows, you need to resize
and/or delete Windows partitions to make room for Linux.

© Copyright IBM Corp. 2001, 2003 Unit 2. Installing Linux 2-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

.QRZ\RXU+DUGZDUH

2EWDLQLQIRUPDWLRQIURP
0DQXDOV
:LQGRZV&RQWURO3DQHO

Figure 2-3. Know your Hardware LX023.0

Notes:
Most hardware characteristics can easily be obtained from the Windows Control Panel
menus. Some things, for instance the monitor capabilities, can not however. You will need
to consult your monitor manual for that.

2-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
3DUWLWLRQLQJ7KHRU\

3DUWLWLRQLQJLVQHFHVVDU\RQ,QWHOEDVHGFRPSXWHUV
0D[LPXPRIIRXUSULPDU\SDUWLWLRQV
2QHSULPDU\SDUWLWLRQPD\EHDQH[WHQGHGSDUWLWLRQ
$QH[WHQGHGSDUWLWLRQFDQKROGDQXQOLPLWHGDPRXQWRI
ORJLFDOSDUWLWLRQV /LQX[PD[

PDVWHUERRWUHFRUG KGD7KHILUVWVHFWRURIWKHGLVNFRQWDLQVWKH0%5DQG
3DUWLWLRQ7DEOH
SDUWLWLRQWDEOH

:LQGRZV KGD)LUVWSULPDU\SDUWLWLRQKROGVD:LQGRZVILOHV\VWHP
KGD6HFRQGSULPDU\SDUWLWLRQLVDQH[WHQGHGSDUWLWLRQDQG
KROGVWKUHHORJLFDOSDUWLWLRQV
KGD)LUVWORJLFDOSDUWLWLRQKROGVD/LQX[ILOHV\VWHPWKDWZLOO
/LQX[
EHPRXQWHGDV
KGD6HFRQGORJLFDOSDUWLWLRQKROGVD/LQX[ILOHV\VWHPWKDW
/LQX[KRPH ZLOOEHPRXQWHGDVKRPH
KGD7KLUGORJLFDOSDUWLWLRQKROGVD/LQX[VZDSVSDFH
/LQX[VZDS

Figure 2-4. Partitioning Theory LX023.0

Notes:
On an Intel-based computer (x86 compatible) a hard disk is split up using a partitioning
scheme. The scheme dates back to the 8086 processor.
Every hard disk in your computer consists of a large number of sectors of 512 bytes each.
The first sector of the disk always contains two things:
• The Master Boot Record (MBR). This master boot record contains the bootstrap code
of the system.
• The Partition Table. This table contains the way the rest of the disk is divided into
partitions.
The rest of the disk can be split up into a maximum of four primary partitions. Every
partition can hold a separate filesystem, each with its own operating system on it. In
addition to that, one of the primary partitions can be used as an extended partition, which
can contain an unlimited number of logical partitions. (Linux limits the number of logical
partitions to 59 on IDE disks and 11 on SCSI disks.) Every logical partition can hold a

© Copyright IBM Corp. 2001, 2003 Unit 2. Installing Linux 2-5


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

separate filesystem too. Most operating systems are not able to boot off a logical partition,
just off a primary partition. Linux is an exception to this.
The first IDE hard disk is called /dev/hda, the second /dev/hdb, and so on. The first primary
partition on the first IDE drive is called /dev/hda1, the first logical partition is called
/dev/hda5. Most Linux distributions define devices up to /dev/hda16, so if you want to
create more than 12 logical partitions, you need to create some extra /dev entries yourself
using the mknod command.
SCSI disks are a little different in this respect. The first difference is that SCSI disks use
/dev/sda instead of /dev/hda. The second difference is that SCSI disks can only hold
eleven logical partitions. This has to do with the SCSI ID numbering, which reserves 16 IDs
for all block devices on the disk, where /dev/sda is also considered a block device.
Together with four primary partitions, this leaves a maximum number of eleven logical
partitions.

2-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
3DUWLWLRQLQJ7RROV

3DUWLWLRQ0DJLF
&RPPHUFLDOSURJUDPIURP3RZHU4XHVW
5XQVXQGHU06'26DQG:LQGRZV
&DQFUHDWHUHVL]HPRYHGHOHWHSDUWLWLRQV
*18SDUWHG
&DQFUHDWHUHVL]HPRYHGHOHWHSDUWLWLRQV
IGLVN
9LUWXDOO\HYHU\3&26 :LQGRZV26/LQX[ FRPHV
ZLWKDWRROIGLVNWRFUHDWHSDUWLWLRQVIRUWKDW26
'LVN'UXLG<D67DQGRWKHUV
3DUWLWLRQLQJSURJUDPVLQWHJUDWHGLQLQVWDOOSURJUDP

Figure 2-5. Partitioning Tools LX023.0

Notes:
Various tools are available for partitioning your hard disk.
The most luxurious tool for partitioning is PartitionMagic, a commercial program from
PowerQuest. It runs under MS-DOS and Windows, and allows you to create, resize, move
and delete partitions for virtually all PC operating system. Especially the resize feature is
something which cannot be found in any other tool (except parted), since it requires
knowledge of the internal structure of the filesystem that is stored in that partition.
parted is the GNU answer to PartitionMagic. It runs under Linux and provides nearly all
functions that PartitionMagic offers. It doesn’t have the same attractive user interface
though.
Virtually every PC operating system comes with a program called fdisk. Although the
implementations differ, the basic functionality is always the same: it allows you to create
and delete partitions for that particular operating system, but you cannot resize partitions.
Some distributions integrate partitioning programs into their installation process. An
example of this is Disk Druid, which is part of a Red Hat installation, and YaST, which is

© Copyright IBM Corp. 2001, 2003 Unit 2. Installing Linux 2-7


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

part of a SuSE installation. These programs typically can create partitions for Linux, but not
for other operating systems.

2-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
3DUWLWLRQ0DJLF

Figure 2-6. PartitionMagic LX023.0

Notes:
The visual shows a screenshot of PartitionMagic in action. From the data on the visual you
can see that we had a 2 GB hard disk which was filled with one big primary partition for
Windows. We are resizing that partition to about 230 MB so that disk space comes
available for Linux.

© Copyright IBM Corp. 2001, 2003 Unit 2. Installing Linux 2-9


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

,QVWDOOLQJ/LQX[

%RRWV\VWHPIURPERRWDEOHPHGLD
$OOPRGHUQ3&VFDQERRWIURP&'520GLUHFWO\
0XVWEHHQDEOHGLQ%,26
2WKHUZLVHERRWIURPIORSS\
6RPHGLVWULEXWLRQVUHTXLUHDGGLWLRQDOGLVNV
$OOGLVNLPDJHVDUHXVXDOO\VWRUHGRQWKH&'520
$IWHUERRWLQJLQVWDOOIURP
/RFDO&'520'9'
/RFDO+DUG'LVN
1HWZRUN

Figure 2-7. Installing Linux LX023.0

Notes:
Installing Linux starts with booting a very tiny Linux system from some sort of bootable
media. The newest PCs can boot from the installation CD-ROM directly (depending on the
BIOS version and settings), but older systems still need to boot from a boot diskette.
In addition to this, certain distributions require additional diskettes to be available. These
additional diskettes will then contain support for less commonly used devices, for instance
for PCMCIA (PC Card) support.
Not all of these additional diskettes are contained in the box, if you bought a certain
distribution. And certainly, if you downloaded the distribution from the Internet, you will
need to make them yourself. The raw diskette images are therefore always stored
somewhere on the distribution CD-ROM or are downloadable from the Internet as well.
They are easily recognizable: they will always have a size of 1474560 bytes (1440
Kilobytes).
Writing the image to a floppy disk is generally done with the rawrite program:

2-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty C:\> d:
D:\> cd images
D:\IMAGES> dir
.
BOOT IMG 1,474,560 19-04-99 17:24 BOOT.IMG
BOOTNET IMG 1,474,560 19-04-99 17:25 BOOTNET.IMG
PCMCIA IMG 1,474,560 18-04-99 23:29 PCMCIA.IMG
.
D:\IMAGES> \dosutils\rawrite
Enter disk image source file name: pcmcia.img
Enter target diskette drive: a:
Please insert a formatted disk into drive A: and press -Enter-:
D:\IMAGES> _
After the system is booted, installation can continue. For that, you will need the installation
packages, which may be on any of these locations:
• Local CD-ROM or local hard disk
• On a network server, accessible through NFS, FTP, HTTP or SMB
(Note that certain distributions have different boot diskettes for local and network installs.)

© Copyright IBM Corp. 2001, 2003 Unit 2. Installing Linux 2-11


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

,QVWDOODWLRQ6WHSV

$OOLQVWDOODWLRQSURJUDPVQHHGWRSHUIRUPHVVHQWLDOO\WKH
VDPHVWHSV
 &KRRVHODQJXDJHNH\ERDUGW\SHPRXVHW\SH
 &UHDWHSDUWLWLRQV
 6HWXSDERRWORDGHU
 &RQILJXUHQHWZRUN
 &RQILJXUHXVHUVDQGDXWKHQWLFDWLRQ
 6HOHFWSDFNDJHJURXSV
 &RQILJXUH;
 ,QVWDOO3DFNDJHV
 &UHDWH%RRW'LVN
2UGHURIVWHSVPD\YDU\IURPGLVWULEXWLRQWRGLVWULEXWLRQ
2WKHUVWHSVPD\DOVREHLQFOXGHG
HJILUHZDOOSULQWHUVVRXQG

Figure 2-8. Installation Steps LX023.0

Notes:
After the system is booted, the installation program will take over, and ask you a number of
questions regarding the Linux configuration. It will then install Linux and configure it
according to the options you specified.
Obviously, every distribution will have its own installation program, so the exact order in
which questions are being asked is different from distribution to distribution. However,
every distribution basically needs to do the same things in its installation process, so if you
look beyond the order of the various menu screens, the installation programs do not differ
that much from each other.

2-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
6HOHFW/DQJXDJH.H\ERDUG0RXVH

6HOHFWWKHODQJXDJHWREHXVHGGXULQJLQVWDOODWLRQ
SURFHVV
'LIIHUHQWGLVWULEXWLRQVVXSSRUWGLIIHUHQWODQJXDJHV
6HOHFWWKHNH\ERDUGOD\RXW
'LIIHUHQWFRXQWULHVXVHGLIIHUHQWNH\ERDUGOD\RXWV
'HDG FRPSRVH NH\VDOORZ\RXWRLQSXWDFFHQWHGRU
VSHFLDOFKDUDFWHUVVXFKDVpo‰DQGVRIRUWK
6HOHFW\RXUPRXVH
$PRXVHFDQEHFRQQHFWHGXVLQJD3686%RU
VHULDOFRQQHFWRU
,I\RXUPRXVHKDVRQO\EXWWRQV\RXFDQHPXODWH
WKHWKLUG PLGGOH EXWWRQE\FOLFNLQJERWKEXWWRQV
VLPXOWDQHRXVO\

Figure 2-9. Select Language, Keyboard, Mouse LX023.0

Notes:
One of the first things the installation program needs to do is to determine the language to
be used during installation, and to determine the keyboard layout and mouse type.

© Copyright IBM Corp. 2001, 2003 Unit 2. Installing Linux 2-13


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

,QVWDOO&ODVV

0RVWGLVWULEXWLRQVKDYHGHIDXOWLQVWDOODWLRQFODVVHVIRU
W\SLFDOXVHUV

:RUNVWDWLRQ

/DSWRS

6HUYHU

$FXVWRPFODVVDOORZV\RXWRPDNHDOOGHFLVLRQV
\RXUVHOI
3DFNDJHVWREHLQVWDOOHG
9DULRXVFRQILJXUDWLRQRSWLRQV

Figure 2-10. Install Class LX023.0

Notes:
Most distributions allow you to select an installation class. These classes allow you to
quickly install a typical system. Among other things, a class determines the packages that
will be installed and various configuration options. If a distribution uses these classes, then
it will always support a "custom" class too, which allows you to make all decisions yourself.
Note that some distributions also make assumptions regarding partitioning, depending on
the class chosen. As an example, a Red Hat "Workstation" install will remove all existing
Linux partitions, and a Red Hat "Server" install will remove ALL existing partitions, including
any non-Linux partitions. If you choose to use an installation class, make sure to read the
documentation.
Most distributions also support an "upgrade" class, which does not make any configuration
changes but upgrades all installed software to the latest level.

2-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
'LVN3DUWLWLRQLQJ

/LQX[LQVWDOODWLRQUHTXLUHV\RXWRFUHDWH/LQX[SDUWLWLRQV
$WDPLQLPXPFUHDWH

0%

5HFRPPHQGHG
ERRW
0%

0D\QHHGZDQWWRFUHDWHRWKHUSDUWLWLRQV

XVU XVUORFDO YDU WPS RSW KRPH

'HIDXOWSDUWLWLRQLQJSURJUDPXQGHU/LQX[LVIGLVN
'LVWULEXWLRQVPD\DGGWKHLURZQSDUWLWLRQLQJSURJUDPV

Figure 2-11. Disk Partitioning LX023.0

Notes:
Almost every Linux distribution allows you to partition your disks during the installation
process. Most distributions use fdisk for this, but some distributions wrote their own
partitioning tool. Red Hat for instance has created Disk Druid to do partitioning.
No matter what tool you use, you need to create two partitions minimum to ensure a
problem-free system:
• The first partition to create is your root partition. This partition will hold the filesystem
which in turn will hold all your data. The absolute minimum depends on your distribution
(a really minimalist Linux install will usually be around 750 Megabytes), but you will find
1.5 Gigabyte or so more comfortable to work in.
Note that it is possible to create more partitions (/usr, /tmp and so forth). In that case,
your root partition doesn’t have to be this large.
• The second partition will not hold a filesystem but will be used as swap space. This is
virtual memory which is used when your system exhausts its real memory. The opinions

© Copyright IBM Corp. 2001, 2003 Unit 2. Installing Linux 2-15


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

on the size of this swap space vary, but it's usually best to take the amount of real
memory on your system as swap space, with a maximum of 256 MB1.
Note that the swap space needs to have another partition type (type 82), and does not
get a mountpoint.
Even though it is not strictly needed on most systems, it is a good idea always to create a
/boot partition (that is short for saying "a partition which will hold a filesystem that will be
mounted at the /boot mountpoint") of about 16 to 32 Megabytes2. This partition will hold
everything that is needed by the Linux boot process. The most important program here is
the Linux kernel itself, but you will also need to have some components of LILO or GRUB
itself stored here.
The reason to store these components on a separate partition is complex and outside the
scope of this course.
Depending on what you are going to do with your system, you might also need to create
other partitions for /usr, /usr/local, /var, /tmp, /opt, /home and so forth. When this is needed
and how these are created is outside the scope of this course; they're not needed for a
Linux workstation anyway.
When partitioning, make sure you don't delete any existing Windows partitions, and make
sure that you format only all newly created Linux partitions.

1
When your system starts using the swap space, it generally means that you do not have enough real memory to run all your processes
in. This leads to a huge performance loss, since hard disk accesses are far slower than memory accesses. Memory today is so cheap
that you should size your system so that you do not need swap space, except in a rare situation.
2
Red Hat requires your /boot partition to be at least 100 Megabytes, so that you can install several kernel images.

2-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&RQILJXUHD%RRW/RDGHU

$%RRW/RDGHUORDGVDQGVWDUWVWKH/LQX[NHUQHO

&DQERRWRWKHURSHUDWLQJV\VWHPVDVZHOO
26:LQGRZV%H26
*LYHHDFK26DXQLTXHODEHO
&DQEHSDVVZRUGSURWHFWHG
3UHYHQWVXVHUVIURPSDVVLQJERRWSDUDPHWHUVWR
/LQX[RUERRWLQJDQ\26
6KRXOGJHQHUDOO\EHFRQILJXUHGLQWKH0%5XQOHVV
DQRWKHUERRWORDGHULVXVHG
&RPPRQ%RRW/RDGHUV
/,/2/LQX[/RDGHU
*58%*5DQG8QLILHG%RRW/RDGHU

Figure 2-12. Configure a Boot Loader LX023.0

Notes:
One of the next screens will allow you to configure a “Boot Loader”. This is a program
which loads and starts the Linux kernel. It can also pass various boot parameters to the
Linux kernel, such as device information, and is also able to load an “Initial RAM Disk3”
(initrd), which contains kernel modules that are required to access the root filesystem.
A boot loader can also be used to boot non-Linux operating systems, such as Windows
and OS/2. For this to work, your boot loader, your boot loader typically needs to be stored
in the master boot record (/dev/hda). If you use another boot loader, such as BootMagic or
OS/2’s boot manager, then the boot loader that loads Linux is usually stored in the Linux
root partition (the partition that holds the root filesystem).
Every OS that needs to be bootable is identified with a label, which you can choose
yourself. This label is used to select the operating system that will be booted when your
system is switched on. If you don't make a selection, then after a number of seconds
(usually 5), the default OS is booted.
Currently, two boot loaders are in use:
3
Also known as Initial Root Disk.

© Copyright IBM Corp. 2001, 2003 Unit 2. Installing Linux 2-17


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

LILO, the Linux Loader, is the oldest of the two. It was specifically written to load Linux, but
can boot other operating systems, such as Windows, as well.
GRUB, the GRand Unified Bootloader, is a successor to LILO. LILO suffers from a number
of drawbacks, especially in multi-boot environments where three or more operating
systems are used.
All boot loaders support passwords. These passwords, if configured, are required if the
user wants to pass parameters to the kernel when the system is booting. These parameters
could for instance be used to boot the system into “single user” mode, where the user
automatically becomes root without having to log in.

2-18 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&RQILJXUH1HWZRUN

0RVWGLVWULEXWLRQVFRQILJXUH\RXUQHWZRUNDGDSWHUDVSDUW
RIWKHLQVWDOODWLRQSURFHVV
(WKHUQHW
7RNHQ5LQJ
1HHGWKHIROORZLQJLQIRUPDWLRQ
,3DGGUHVV
6XEQHWPDVN
1HWZRUNDGGUHVV
%URDGFDVWDGGUHVV
+RVWQDPH
'HIDXOWURXWHUJDWHZD\
'16VHUYHUDGGUHVVHV
0D\DOVREHFRQILJXUHGWRXVH'+&3

Figure 2-13. Configure Network LX023.0

Notes:
Most distributions can configure your (Ethernet or Token Ring) network adapter during the
installation. For this to work, you need to obtain the following information from your network
manager:
• IP address
• Subnetmask
• Network Address
• Broadcast Address
• Hostname
• Default router/gateway
• DNS server addresses
If your workstation will reside on a network where a DHCP server is present, you can also
configure your system to use this DHCP server to obtain this information.

© Copyright IBM Corp. 2001, 2003 Unit 2. Installing Linux 2-19


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&RQILJXUH5RRWDQG8VHU$FFRXQWV

URRWLVWKHVXSHUXVHURIWKHV\VWHP
&DQGRDQ\WKLQJ
1HHGVDVWURQJSDVVZRUG
'RQRWXVH\RXUV\VWHPDVURRWXQOHVV\RXQHHGWR
0RVWGLVWULEXWLRQVDOORZ\RXWRDGGXVHUDFFRXQWVGXULQJ
LQVWDOODWLRQWRR
&UHDWHDXVHUDFFRXQWIRUHYHU\LQGLYLGXDOXVHUWKDWLV
JRLQJWRXVHWKHV\VWHP
+LQW<RXVKRXOGHQDEOHVKDGRZSDVVZRUGVDQG0'
HQFU\SWLRQLIDYDLODEOHIRUDGGLWLRQDOVHFXULW\

Figure 2-14. Configure Root and User Accounts LX023.0

Notes:
On a Linux system, the superuser is called root. If you (or anybody else) is logged into the
system as this user, you can do anything to the system. This is considered very dangerous,
and that's why you need to configure a strong password for this account. A good policy to
live by is never to use the root account unless you really need to. Unfortunately, most Linux
workstation users ignore this...
Most distributions also allow you to add regular user accounts during the installation. If your
distribution does this, then create user accounts for every user that is going to use your
system.
If your distribution allows you to configure shadow passwords and MD5 encryption of
passwords, enable this. This greatly increases the security of your system.
Some distributions also allow you to configure your workstation as a NIS, LDAP or
Kerberos client, or as a client of some other network authentication method. Only do this if
your network supports this (ask your network administrator).

2-20 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
6HOHFW3DFNDJH*URXSV

0RVWGLVWULEXWLRQVKDYHJURXSHGLQGLYLGXDOSDFNDJHVLQ
SDFNDJHJURXSV
2QO\VHOHFWWKHSDFNDJHJURXSV\RXQHHGRQ\RXU
ZRUNVWDWLRQ
6HOHFWLQJLQGLYLGXDOVRIWZDUHSDFNDJHVLVXVXDOO\VWLOO
SRVVLEOHEXWWHGLRXV
$W\SLFDOGLVWULEXWLRQKDVRYHUSDFNDJHV

Figure 2-15. Select Package Groups LX023.0

Notes:
A typical distribution consists of over 1000 individual packages (software components) that
should or can be installed. To save the user from having to make 1000 or more informed
decisions, these packages are often grouped into package groups. Instead of having to
decide on each and every individual package, you decide to install a package group or not.
This greatly reduces the complexity of selecting the packages you want to install. Most
distributions still offer the "select individual packages" option though, in case you've got
nothing better to do or need to run a really tight system (security-wise or
harddiskspace-wise).

© Copyright IBM Corp. 2001, 2003 Unit 2. Installing Linux 2-21


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&RQILJXUH;

; ;:LQGRZ6\VWHP LVWKHJUDSKLFDOXVHULQWHUIDFHRI
/LQX[
1HHGVWREHFRQILJXUHGIRU\RXUV\VWHP
*UDSKLFDODGDSWHU
0RQLWRU
0RVWDGDSWHUVDQGPRQLWRUVFDQEHDXWRGHWHFWHG
,IQRWDXWRGHWHFWHGVHOHFWPDQXDOO\RUXVHD
*HQHULFDGDSWHURUPRQLWRU
8VXDOO\FXVWRPL]DWLRQDOORZHG
5HVROXWLRQ5HIUHVKUDWH
&RORU'HSWK
7HVWVHWWLQJVLISRVVLEOH
,IQRWKLQJZRUNVVNLS;FRQILJXUDWLRQ

Figure 2-16. Configure X LX023.0

Notes:
The X Window System (X for short) is the Graphical User Interface (GUI) of Linux. It
needs to be configured for your graphical adapter and monitor in order to provide optimal
performance.
Most distributions incorporate auto detection mechanisms which detect your adapter and
monitor automatically. If this fails, select your adapter and monitor manually or use a
"Generic" adapter or monitor.
Within the limits of your adapter and monitor, you can customize your resolution (the
amount of pixels on your screen), your refresh rate (the number of times your screen will be
refreshed, per second) and the color depth (the amount of colors that can be displayed
simultaneously). There usually is a trade-off to be made here: a higher resolution usually
means less color depth, and a higher resolution also means a lower refresh rate. It is
therefore important that, if possible, you test the configuration before you continue the
installation process.
It occasionally happens that X cannot be configured from the installation process at all.
Trying to configure X might in some rare case even hang the system altogether. Especially

2-22 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty laptops suffer from this occasionally. In that case, there's always a possibility to skip X
configuration altogether.

© Copyright IBM Corp. 2001, 2003 Unit 2. Installing Linux 2-23


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2WKHU 2SWLRQDO ,QVWDOODWLRQ6FUHHQV

6RPHGLVWULEXWLRQVRIIHUDGGLWLRQDOLQVWDOODWLRQVFUHHQV

3ULQWHUFRQILJXUDWLRQ

)LUHZDOOFRQILJXUDWLRQ

6RXQGFDUGFRQILJXUDWLRQ

0RGHPFRQILJXUDWLRQ

7LPH=RQHFRQILJXUDWLRQ
8VXDOO\VWUDLJKWIRUZDUG

Figure 2-17. Other (Optional) Installation Screens LX023.0

Notes:
Some distributions offer other configuration screens in addition to the ones we've covered.
This might include configuration of printers, firewalls, sound cards, modems, time zones
and so forth. These screens are usually straightforward. And if they're not, there's usually
help available.

2-24 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
,QVWDOOLQJ3DFNDJHV

,QVWDOOLQJSDFNDJHVPD\WDNHPLQVWRVHYHUDOKRXUV
0RVWGLVWULEXWLRQVSURYLGHDSURJUHVVEDUDQGRUWRWDO
WLPHLQGLFDWLRQ
6RPHGLVWULEXWLRQVSURYLGHVRPHHQWHUWDLQPHQWZKLOH
LQVWDOOLQJ
:KLOHLQVWDOODWLRQLVJRLQJRQYDULRXVYLUWXDOWHUPLQDOV
SURYLGHLQIRUPDWLRQRQWKHSURJUHVV
6ZLWFKEHWZHHQ97VXVLQJ&WUO$OW)&WUO$OW)
)HHGDGGLWLRQDO&'
VZKHQDVNHGIRU

Figure 2-18. Installing Packages LX023.0

Notes:
After all configuration choices have been made, the system will start installing packages.
This installation may take 5 minutes or several hours, depending on your hardware and
amount of packages to install. Most distributions however display some sort of progress bar
or time indication so you can estimate how long your coffee or lunch break is going to be.
While the installation is going on, you can get additional information about it from various
virtual terminals. Virtual terminals are pseudo-monitors, which can be accessed using
Ctrl-Alt-F1, Ctrl-Alt-F2 and so forth.
Do not forget to feed additional CDs when the install program asks for it.

© Copyright IBM Corp. 2001, 2003 Unit 2. Installing Linux 2-25


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&UHDWH%RRW'LVN

$IWHULQVWDOODWLRQPRVWGLVWULEXWLRQVDOORZ\RXWRFUHDWHD
FXVWRPERRWGLVN
8VHGWRERRWWKHV\VWHPLQFDVHRI/,/2*58%NHUQHO
SUREOHPV
6\VWHPVSHFLILFWRVRPHGHJUHH

Figure 2-19. Create Boot Disk LX023.0

Notes:
At the end of the installation process, most distributions offer you the chance of creating a
custom boot disk. This disk allows you to boot your newly installed Linux system even if
there is a LILO or GRUB problem. It is a useful thing to have.
Note that the boot disk is system specific to some degree: you cannot use it on other
systems without some modification.

2-26 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
5HERRWV\VWHP

$IWHULQVWDOODWLRQKDVILQLVKHG\RXVKRXOGUHERRW\RXU
V\VWHP
0RVWGLVWULEXWLRQVDUHFRPSOHWHO\FRQILJXUHGDIWHUUHERRW
8VHWKHVKXWGRZQFRPPDQGIRUUHERRW

VKXWGRZQUQRZ!UHERRWVWKHV\VWHPQRZ
VKXWGRZQKQRZ!KDOWVWKHV\VWHPQRZ

Figure 2-20. Reboot System LX023.0

Notes:
For most distributions, after the packages have been installed and post-install configuration
has been done, the install is over. The only thing left to do is to reboot the system.
Some distributions, for instance SuSE, either need to perform some post-install
configuration after the system has rebooted for the first time, or perform the reboot during
the installation. If this is the case, you will see that automatically.
The reason for this reboot is to activate the newly-installed kernel: The installation program
will typically run on top of a generic, i386 compatible kernel. This installation program then
determines your CPU type and will install a kernel which is optimized for your CPU.

© Copyright IBM Corp. 2001, 2003 Unit 2. Installing Linux 2-27


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&KHFNSRLQW

7)/LQX[FDQFRH[LVWZLWK:LQGRZVRQWKHVDPH
KDUGGLVN

:KLFKRIWKHIROORZLQJVWHSVLV127HVVHQWLDOLQWKH
LQVWDOODWLRQSURFHVV
D&UHDWHSDUWLWLRQVIRU/LQX[
E&RQILJXUH\RXUSULQWHU
F6HOHFW\RXUNH\ERDUGW\SH
G,GHQWLI\WKHSDFNDJHVWRLQVWDOO

:KDWLVWKHEHVWVRXUFHRILQIRUPDWLRQDERXW\RXU
KDUGZDUH"

Figure 2-21. Checkpoint LX023.0

Notes:

2-28 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
8QLW6XPPDU\

3UHSDULQJDV\VWHPIRULQVWDOODWLRQ
%RRWLQJWKHLQVWDOODWLRQSURJUDP
,QVWDOOLQJ/LQX[DQGEDVLFFRQILJXUDWLRQ

Figure 2-22. Unit Summary LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 2. Installing Linux 2-29


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2-30 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 3. Using the System

What This Unit Is About


This unit gives a general overview on how a Linux system should be
used properly, keeping in mind that Linux is a multi-tasking, multi-user
system. It also introduces some Linux commands that illustrate the
workings and concepts of a multi-user system.

What You Should Be Able to Do


After completing this unit, you should be able to:
• Log in and out of the system
• State the structure of Linux commands
• Execute basic Linux commands
• Use Linux commands to communicate with other users
• Use the keyboard and mouse effectively
• Use the command history

How You Will Check Your Progress


Accountability:
• Checkpoint questions
• Machine exercises

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
/RJLQDQGRXWRIWKHV\VWHP
6WDWHWKHVWUXFWXUHRI/LQX[FRPPDQGV
([HFXWHEDVLF/LQX[FRPPDQGV
8VH/LQX[FRPPDQGVWRFRPPXQLFDWHZLWKRWKHUXVHUV
8VHWKHNH\ERDUGDQGPRXVHHIIHFWLYHO\
8VHWKHFRPPDQGKLVWRU\

Figure 3-1. Objectives LX023.0

Notes:

3-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
/LQX[LV0XOWLXVHUDQG0XOWLWDVNLQJ

/LQX[LVDPXOWLXVHUPXOWLWDVNLQJRSHUDWLQJV\VWHP
0XOWLSOHXVHUVFDQUXQPXOWLSOHWDVNVVLPXOWDQHRXVO\
LQGHSHQGHQWRIHDFKRWKHU
$OZD\VQHHGWRORJLQEHIRUHXVLQJWKHV\VWHP
,GHQWLI\\RXUVHOIZLWKXVHUQDPHSDVVZRUG
0XOWLSOHZD\VWRORJLQWRWKHV\VWHP
&RQVROH'LUHFWO\DWWDFKHGNH\ERDUGPRXVHPRQLWRU
6HULDOWHUPLQDO
1HWZRUNFRQQHFWLRQ

Figure 3-2. Linux is Multi-user and Multi-tasking LX023.0

Notes:
Linux, just like any UNIX system, is designed from the ground up as a multi-user,
multi-tasking operating system. This means that multiple users can run multiple tasks
simultaneously on the same system, independent of each other. Security is of course
paramount on such systems, since it would be unacceptable if one regular user could stop
or otherwise influence processes of other users. In order for this separation to work
properly, user authentication is needed.
User authentication on a Linux system is done when you first start using the system. Before
you can do anything, you need to identify yourself using your username and password. On
a real multi-user system, the system administrator will assign you a username and initial
password, but if you are using Linux on your personal workstation, you need to create a
user account for yourself (for instance during installation), or log in as root, which is the
account for the superuser.
There are multiple ways of logging into a Linux system, since it would be rather
inconvenient if hundreds of users tried to use one keyboard all at once:

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

• The first method is by using the console. This is an ancient name which is currently
used to identify the keyboard, mouse and monitor that are directly attached to the
system.
• The second method is by using a serial terminal. This is a fairly cheap combination of
keyboard and monitor (no mouse) which is connected to the system through a serial
line. Serial terminals were very popular in the days before the PC, since they were
cheap and required virtually no maintenance, both hardware- and software-wise. Also,
serial terminals could be tens to hundreds of meters away from the actual system
without requiring additional hardware (just a loooong cable).
• The third method is by using the network, using programs such as telnet and ssh.

3-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
9LUWXDO7HUPLQDOV

,QPRVW/LQX[GLVWULEXWLRQVWKHFRQVROHHPXODWHVD
QXPEHURIYLUWXDOWHUPLQDOV
(DFKYLUWXDOWHUPLQDOFDQEHVHHQDVDVHSDUDWHGLUHFWO\
DWWDFKHGFRQVROH
'LIIHUHQWXVHUVFDQXVHGLIIHUHQWYLUWXDOWHUPLQDOV
7\SLFDOVHWXS
97WKURXJKWH[WPRGHORJLQV
97JUDSKLFDOPRGHORJLQSURPSW LIHQDEOHG
6ZLWFKEHWZHHQ97VZLWK$OW)Q RU&WUO$OW)QLILQ;

Figure 3-3. Virtual Terminals LX023.0

Notes:
In most Linux distributions, the console emulates a number of virtual terminals. These
virtual terminals can be seen as separate, directly attached consoles and can be used by
different users, although, in practice, this is rather inconvenient.
Since the system in reality only has one console, there are hotkey combinations to switch
from one VT to another. This hotkey combination is Alt-Fn, where the n is the virtual
terminal number you want to access. When you are in an X environment, you need to use
Ctrl-Alt-Fn instead.
The default virtual terminal setup differs from distribution to distribution, but the most
common setup offers six text mode logins on VTs 1 through 6, and (if enabled by the user)
a graphical mode login on VT 71.

1
How this is enabled is covered later.

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

/RJJLQJ,Q 7H[W0RGH97

Figure 3-4. Logging In (Text Mode VT) LX023.0

Notes:
The visual shows a text mode login session.

3-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
/RJJLQJ,Q *UDSKLFDO0RGH97

1RWH'LIIHUHQWGLVWULEXWLRQVDQGGHVNWRSHQYLURQPHQWV
ZLOOGLVSOD\GLIIHUHQWORJLQSURPSWV
Figure 3-5. Logging In (Graphical Mode VT) LX023.0

Notes:
The visual shows a graphical mode login session. The exact layout of the graphical login
session varies from distribution to distribution and from desktop environment to desktop
environment.

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

/LQX[&RPPDQGV

(YHU\WKLQJRQD/LQX[V\VWHPFDQEHGRQHE\W\SLQJ
FRPPDQGV
(YHQEURZVLQJWKH:RUOG:LGH:HE
7KH*UDSKLFDO8VHU,QWHUIDFH ;:LQGRZ6\VWHPRU; LV
QRWQHHGHGIRUUXQQLQJD/LQX[V\VWHP
%XWLVVRPHWLPHVPRUHFRQYHQLHQW
,QRUGHUWREHDEOHWRW\SHFRPPDQGVLQ;\RXQHHGWR
VWDUWDWHUPLQDOHPXODWRU

Figure 3-6. Linux Commands LX023.0

Notes:
Every process that is running on a Linux system is started by a command, although for
most processes, you will never see that command since they are started automatically. And
since every command can be executed from any login session, be it local or remote, a
whole Linux system can be managed just as easily over the network as locally. You don't
need to sit down at the console, in a possibly noisy and cold server room to manage a
Linux system.
Similarly, most commands do not need a Graphical User Interface (X) to run. And if there
are commands that do need X (such as the web browsers Netscape and Konqueror), then
there are usually text-based alternatives available that can do without X (such as Lynx, a
text-based web browser). Using the GUI is sometimes more convenient though, especially
for things like graphics design, games and browsing the web.
Commands can obviously be run from a text based terminal. But to run commands from
within X, you need to start a terminal emulator.

3-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
6WDUWLQJD7HUPLQDO(PXODWRU

7RUXQD/LQX[FRPPDQGLQVLGHWKH;HQYLURQPHQWRSHQ
DWHUPLQDOZLQGRZRUWHUPLQDOHPXODWRU
(PXODWHVDWH[WFRQVROH

.'(
5HG+DW %OXH&XUYH 

*120(

6X6(

Figure 3-7. Starting a Terminal Emulator LX023.0

Notes:
A terminal emulator is a program that emulates a text terminal in an X environment. The
window that is consequently opened is also called a "terminal window".
Various desktop environments have different terminal emulators, and have different buttons
to start them. The visual shows the buttons for the GNOME and KDE desktop
environments.

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&RPPDQG3URPSW

7KHFRPPDQGSURPSWLQGLFDWHVWKDWWKHV\VWHPLVUHDG\
WRDFFHSWFRPPDQGV
&DQEHFRQILJXUHG\RXUVHOI ZLOOEHFRYHUHGODWHU
'HIDXOWGHSHQGVRQGLVWULEXWLRQ
([DPSOHV
>XVHU#KRVWGLU@
GLU


7KHGROODU  XVXDOO\PHDQVORJJHGLQDVUHJXODUXVHU
7KHKDVK  XVXDOO\PHDQVORJJHGLQDVURRW

Figure 3-8. Command Prompt LX023.0

Notes:
The command prompt is the indication that the system is ready to accept commands. Only
when the command prompt shows (in a text terminal or terminal emulator) can you type
commands2.
What the command prompt looks like is something you can configure yourself; we will do
that later. Different distributions have different default settings, of which the visual shows
some examples. What is important to note is that, for historic reasons, a dollar sign ($)
usually means that you are logged in as a regular user, and a hash sign (#) usually means
that you are logged in as root.

2 If the command prompt does not show, you can already type the beginnings of a command. The keys typed will then appear as soon

as the command prompt displays.

3-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
/LQX[&RPPDQG6\QWD[

/LQX[FRPPDQGVKDYHWKHIROORZLQJIRUPDW
FRPPDQGRSWLRQ V DUJXPHQW V

OV
OVO
OVGHY
OVOGHY

Figure 3-9. Linux Command Syntax LX023.0

Notes:
The order and separation of the elements of a command is very important.
The command or process name must come first.
Spaces are used by the shell as separators on the command line and should not be placed
within the command name.
The options should follow the command name, separated by a space, and preceded by a
"-" (minus sign), or a "+" (plus sign). Multiple options may be grouped immediately after a
single "-", or separated by spaces and each preceded by a "-".
Options are typically used to modify the operation of the process.
The arguments follow the options, again separated by a space. The order of the arguments
will depend on the command.

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&RPPDQG)RUPDW([DPSOHV

5,*+7 :521*

6HSDUDWLRQ
PDLOISHUVRQDO PDLOISHUVRQDO
ZKRX ZKRX

2UGHU
PDLOVWHVWURRW PDLOWHVWURRWV
ZKRX XZKR

0XOWLSOHRSWLRQV
ZKRPX ZKRPX
ZKRPX ZKRPX

Figure 3-10. Command Format Examples LX023.0

Notes:

3-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
6RPH%DVLF/LQX[&RPPDQGV

SDVVZG&KDQJH\RXUSDVVZRUG
PNSDVVZG*HQHUDWHDUDQGRPSDVVZRUG
GDWHFDO)LQGRXWWRGD\
VGDWHDQGGLVSOD\VDFDOHQGDU
ZKRILQJHU)LQGRXWZKRHOVHLVDFWLYHRQWKHV\VWHP
FOHDU&OHDUWKHVFUHHQ
HFKR:ULWHDPHVVDJHWR\RXURZQVFUHHQ
ZULWH:ULWHDPHVVDJHWRRWKHUVFUHHQV
ZDOO:ULWHDPHVVDJHWRDOOVFUHHQV
WDON7DONWRRWKHUXVHUVRQWKHV\VWHP
PHVJ6ZLWFKRQRIIUHFHSWLRQRIZULWHZDOODQGWDON
PHVVDJHV

Figure 3-11. Some Basic Linux Commands LX023.0

Notes:
In the next few visuals, we are going to look at the commands listed in the visual.

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&KDQJLQJ\RXU3DVVZRUG

7KHSDVVZGFRPPDQGDOORZV\RXWRFKDQJH\RXU
SDVVZRUG

SDVVZG
&KDQJLQJSDVVZRUGIRUWX[
2OGSDVVZRUG
1HZSDVVZRUG
5HW\SHQHZSDVVZRUG

3DVVZRUGVDUHLPSRUWDQWIRUVHFXULW\FKRRVHDJRRG
SDVVZRUG
0LQLPXPVL[FKDUDFWHUV
1RWDGLFWLRQDU\ZRUGELUWKGDWHOLFHQVHSODWH
7KHPNSDVVZGFRPPDQGJHQHUDWHVDUDQGRP
SDVVZRUG
Figure 3-12. Changing your Password LX023.0

Notes:
The user password is the primary mechanism for ensuring security on a Linux system. All
passwords are encrypted and cannot be decoded.
The passwd command is used to change the user password and is an example of a simple
command that may be entered at the shell prompt.
The system will start the passwd process that will prompt the user for a new password. To
prevent users being "locked-out" of the system through simple typing errors, the new
password is entered twice. Only if the two entries match is the new password accepted.
The old password is invalid thereafter.
It is really important to come up with a good password, since too many systems have been
broken into because of bad (easily guessed) passwords. To help you set a good password,
the mkpasswd command can be helpful. It generates a random string of letters, which can
be used as your password. It is often used by system administrators to set an initial
password for new user accounts.

3-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty The mkpasswd command may not be installed by default. On a Red Hat system, it is part
of the expect package, and on a SuSE system, it is part of the whois package. You will
learn how to install additional packages later in this course.

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-15
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHGDWH&RPPDQG

GDWHVKRZVWKHFXUUHQWGDWHDQGWLPH

GDWH
)UL-XQ&(7

Figure 3-13. The date Command LX023.0

Notes:
The date command shows you the current system date and time. Note that the timezone is
displayed too. Linux has a full implementation of date functions, which includes
compensation for time zones and daylight savings time. This might seem overkill until you
realize that people from all over the world might be using the same system at the same
time, but all want their times to be displayed as local time.

3-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KHFDO&RPPDQG

FDOVKRZVDFDOHQGDU
6\QRSVLVFDO>0RQWK@><HDU@

FDO
-XQH
6X0R7X:H7K)U6D







Figure 3-14. The cal Command LX023.0

Notes:
With the cal command you can look at the calendar of a given year or a given month in a
year.

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-17
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

:KR,VRQWKH6\VWHP

ZKRVKRZVZKRLVORJJHGRQWRWKHV\VWHP

ZKR
URRW WW\ 0DU
WX[ WW\ 0DU

ZKRDPL
KRVWWX[ WW\ 0DU

%XW
ZKRDPL
WX[

Figure 3-15. Who Is on the System LX023.0

Notes:
To find out who is logged in the system, you could enter one of these two commands.
The who command shows you: user ID, display where the user logged in, date and time
the user logged in, and (if a network is used) the hostname the user logged in from.
The who am i and whoami commands show you what user you logged in to the system
as.

3-18 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
)LQGLQJ,QIRUPDWLRQDERXW8VHUV

7KHILQJHUFRPPDQGVKRZVLQIRDERXWRWKHUXVHUV
6\QRSVLVILQJHU>XVHU@>#KRVW@

ILQJHU
/RJLQ1DPH7W\,GOH/RJLQ7LPH
WX[7X[  0DU
URRWURRW 0DU

ILQJHUWX[
/RJLQWX[ 1DPH7X[ 
'LUHFWRU\KRPHWX[6KHOOELQEDVK
2QVLQFH)UL0DU &(7 RQWW\
1RPDLO
1RSODQ

Figure 3-16. Finding Information about Users LX023.0

Notes:
The finger command will show you additional information about a user, for instance
yourself. (Note: the finger service is by default disabled in most distributions, because it can
also be accessed over the network and is considered a security risk.)
The finger command shows you: user ID, full name, display, idle time, date and time the
user logged in and some office information.
The asterisk in the output of the finger command indicates that the issuer of the finger
command cannot write to this (tty1) device.

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-19
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHFOHDUHFKRZULWHDQGZDOO&RPPDQGV

7KHFOHDUFRPPDQGFOHDUV\RXUVFUHHQ
FOHDU
7KHHFKRFRPPDQGZULWHVPHVVDJHVWR\RXURZQVFUHHQ
HFKR:KRZDQWVWRJRWROXQFK"
:KRZDQWVWRJRWROXQFK"
8VHZULWHWRGLVSOD\DWH[WPHVVDJHRQDXVHU
VWHUPLQDO
ZULWHWX[
0HVVDJH
FWUOG!
8VHZDOOWRSODFHDPHVVDJHRQDOOORJJHGLQXVHU
V
GLVSOD\V
ZDOO
,
PEDFN
FWUOG!

Figure 3-17. The clear, echo, write and wall Commands LX023.0

Notes:
The clear command clears your screen.
The echo command writes a message to your own screen, while the write command
writes messages to screens of other users.
The wall command finally writes a message to all screens.

3-20 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7DONZLWK$QRWKHU8VHU

,I-RKQZDQWVWRWDONZLWK)UHG-RKQHQWHUV
WDONIUHG

,I)UHGDOVRZDQWVWRWDONZLWK-RKQ)UHGHQWHUV
WDONMRKQ

-2+1 )5('
Figure 3-18. Talk with Another User LX023.0

Notes:
The talk command can be used locally on one system or across the network.
talk allows two users to hold a conversation. One user invites the other to hold a
conversation by issuing the talk command.
When the local user initiates a conversation, a message is sent to the remote user inviting
him to a conversation, to which the remote user must respond in order to form a
connection.
If the invitation is accepted, each user's screen is split horizontally into two windows. In the
top window everything the other user types is displayed.
To close the conversation, press the INTERRUPT key (Ctrl-c).
talk can also be used in a network. To talk to Fred on sys2, the command would be
talk fred@sys2.

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-21
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHPHVJ&RPPDQG

7KHPHVJFRPPDQGFRQWUROVZKHWKHURWKHUXVHUVFDQ
VHQGPHVVDJHVWR\RXZLWKWKHZULWHZDOORUWDON
FRPPDQGRUWKURXJKRXWSXWUHGLUHFWLRQ

8VHUWX[DWWW\

PHVJQ

8VHUWX[DWWW\

ZULWHWX[WW\
ZULWHWX[KDVGLVDEOHGPHVVDJHVRQWW\

Figure 3-19. The mesg Command LX023.0

Notes:
If you don’t want to be disturbed by write and talk messages, you can issue the mesg n
command. Only the root user can then write something on your screen.

3-22 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
.H\ERDUG7LSV 
EDFNVSDFH!FWUOK! &RUUHFWVPLVWDNHV
FWUOF! 7HUPLQDWHVWKHFXUUHQW
FRPPDQGDQGUHWXUQVWR
WKHVKHOO
FWUOG! (QGRIWUDQVPLVVLRQ
FWUOV! 7HPSRUDULO\VWRSVRXWSXWWR
WKHVFUHHQ
FWUOT! 5HVXPHVRXWSXW
FWUOZ! (UDVHODVWZRUG
FWUOX! (UDVHWKHHQWLUHOLQH
WDE! &RPPDQGRUILOHQDPH
FRPSOHWLRQ

Figure 3-20. Keyboard Tips (1) LX023.0

Notes:
Several keyboard shortcuts help you correct mistakes that you typed, and can stop and
resume scrolling output.

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-23
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

.H\ERDUG7LSV 
DUURZXS! 3UHYLRXVFRPPDQG
DUURZGRZQ! 1H[WFRPPDQG
DUURZOHIW! 2QHFKDUDFWHUWRWKHOHIW
DUURZULJKW! 2QHFKDUDFWHUWRWKHULJKW
VKLIWSDJHXS! /RRNDWWKHRXWSXWRI
SUHYLRXVFRPPDQGV
VKLIWSDJHGRZQ! /RRNDWWKHRXWSXWRIODWHU
FRPPDQGVHYHQWXDOO\JHWV
\RXEDFNWRWKHFRPPDQG
SURPSW
&WUO5! 6HDUFKIRUDFRPPDQGLQ
WKHFRPPDQGKLVWRU\

Figure 3-21. Keyboard Tips (2) LX023.0

Notes:
The <arrow up> and <arrow down> can be used to retrieve commands from history.
The <arrow left> and <arrow right> are used to move the cursor along the command line
to correct mistakes or make changes.
With the <shift page-up> sequence you can look at the output of previous executed
commands. The <shift page-down> will bring you back to your prompt. Note that this
“scroll buffer” is cleared when you switch from one virtual terminal to another.

3-24 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&RPPDQG+LVWRU\

&RPPDQGKLVWRU\DOVRFDQEHYLHZHGZLWKKLVWRU\
FRPPDQG

KLVWRU\
FOHDU
ZFEDVKBSURILOH
ZFEDVKBSURILOH
ZFEDVKBSURILOH
KLVWRU\

Figure 3-22. Command History LX023.0

Notes:
You can also view all commands that are stored in the history with the history command.

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-25
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

5HWULHYLQJFRPPDQGVZLWK

7RUHWULHYHFRPPDQGVXVH

ZFEDVKBSURILOH
   EDVKBSURILOH
5HGRSUHYLRXV


ZFEDVKBSURILOH
   EDVKBSURILOH
RU


5HGRFRPPDQG1R


Figure 3-23. Retrieving commands with “!” LX023.0

Notes:
Retrieving commands from the history is done with the exclamation point (!) command.
This way of recalling your history is very powerful. Among other things, it allows you to
change your commands on the fly. See the last line in the visual for an example. For more
information see the manual page of bash.

3-26 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&RQVROH0RXVH7LSV

2QPRVWGLVWULEXWLRQVWKHPRXVHDOVRZRUNVLQWH[WPRGH
/HIWPRXVHEXWWRQ
&OLFN0DUNVWDUWRIVHOHFWLRQ
'UDJ0DUNVHOHFWLRQ
0LGGOHPRXVHEXWWRQ
&OLFN3DVWHVHOHFWLRQ
5LJKWPRXVHEXWWRQ
&OLFN0DUNHQGRIVHOHFWLRQ

Figure 3-24. Console Mouse Tips LX023.0

Notes:
Most distributions automatically run the gpm program. This program allows you to use the
mouse for copy and paste actions in a text console.
When gpm is running and you start moving the mouse, you will see the mouse cursor as a
square block moving across the screen. When you click the left mouse button, you will
mark the start of the selection, and when you click the right mouse button, you will mark the
end of the selection. You can also make a selection by "dragging" with the left mouse
button: Hold the left mouse button depressed when making your selection. Your selection
will show up in reverse video.
To paste your selection, click the middle mouse button3.
Copy and paste using gpm will work across different virtual terminals.

3 Remember, if your mouse only has two buttons, you need to enable "emulate third button" while installing your system. This will allow

you to emulate your middle mouse button by clicking on the left and right button simultaneously.

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-27
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

/RFNLQJ

:KHQWHPSRUDU\OHDYLQJDV\VWHPDORQHDOZD\VORFN
\RXUWHUPLQDO
2WKHUSHRSOHPLJKWPLVXVH\RXUDFFRXQW
,QDWH[WPRGHWHUPLQDOXVHYORFN ORFN\RXUWHUPLQDO RU
YORFND ORFNWKHZKROHFRQVROH
,QDJUDSKLFDOPRGHWHUPLQDOXVHWKHPHQXWKH
SDGORFNLFRQRU[ORFN
0RVWVFUHHQVDYHUVVXSSRUWDXWRPDWLFORFNLQJWRR
$ORFNHGWHUPLQDOFDQRQO\EHXQORFNHGZLWKWKHXVHUV
SDVVZRUG

Figure 3-25. Locking LX023.0

Notes:
When you are away from your system for a short period of time, lock your terminal. The
easiest way of breaking in is after all finding a door which is already open...
Locking a text mode terminal can be accomplished with the vlock command. The vlock -a
command not only locks your virtual terminal, but the whole console.
In a graphical environment, use the menu options, the padlock icon or the xlock command.
Most screensavers support locking too.
A locked terminal can only be unlocked with the users password4.

4
Occasionally you will find a configuration where you can also unlock a terminal with the root password. This requires the xlock
command to run with root privileges though, and is generally considered a security risk.

3-28 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
/RJJLQJ2XW

:KHQILQLVKHGZRUNLQJRQDV\VWHPDOZD\VORJRXW
2WKHUSHRSOHPLJKWPLVXVH\RXUDFFRXQW
,QDWH[WPRGHWHUPLQDOXVHORJRXWH[LWRU&WUO'
,QDJUDSKLFDOPRGHWHUPLQDOXVHDSSURSULDWHPHQXV

*120( .'(

Figure 3-26. Logging Out LX023.0

Notes:
After you have finished using a system, always log out.
To log out of a text mode session, you can use the logout or exit commands, or use the
hotkey sequence Ctrl-d5.
To log out of a graphic mode session, use the appropriate menus or buttons.

5 In some distributions, the shell variable "$IGNOREEOF" is set automatically. This indicates that Ctrl-d should not log you out, or that it

should log you out only if you typed a number of Ctrl-ds (10 by default) consecutively.

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-29
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&KHFNSRLQW

7)$/LQX[V\VWHPDOZD\VQHHGVD*UDSKLFDO
8VHU,QWHUIDFH

:KLFKRIWKHIROORZLQJFRPPDQGVLVQRWDOHJDO
 FRPPDQGLQ/LQX["
DOVGHYELQ
EOVDOGHYELQ
FOVDO
GOVDOGHY

+RZGR\RXVZLWFKEHWZHHQYLUWXDOWHUPLQDOV" 

Figure 3-27. Checkpoint LX023.0

Notes:

3-30 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
8QLW6XPPDU\

$/LQX[V\VWHPLVFRQWUROOHGE\HQWHULQJFRPPDQGV
$*8,LVQRWQHFHVVDU\IRUFRQWUROOLQJD/LQX[V\VWHP
/LQX[FRPPDQGVFDQXVHPXOWLSOHRSWLRQVDQG
DUJXPHQWVDQGPXVWIROORZSURSHUV\QWD[UXOHV
7KHUHDUHPDQ\VLPSOH\HWSRZHUIXOFRPPDQGVVXFKDV
GDWH
FDO
ZKRZKRDPLZKRDPL
ILQJHU
HFKR
FOHDU
&RPPXQLFDWHZLWKRWKHU/LQX[XVHUVXVLQJFRPPDQGV
VXFKDVPDLOZULWHZDOODQGWDON

Figure 3-28. Unit Summary LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 3. Using the System 3-31
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

3-32 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 4. Working with Files and Directories

What This Unit Is About


This unit covers the most important commands that allow the user to
manipulate files and directories.

What You Should Be Able to Do


After completing this unit, you should be able to:
• Describe the different file types
• Describe file and pathnames
• Create, delete, copy, move and list directories
• Create, delete, copy and move files
• View the content of both text and binary files
• Split large files into smaller ones

How You Will Check Your Progress


Accountability:
• Checkpoint questions
• Machine exercises

© Copyright IBM Corp. 2001, 2003 Unit 4. Working with Files and Directories 4-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
'HVFULEHWKHGLIIHUHQWILOHW\SHV
'HVFULEHILOHDQGSDWKQDPHV
&UHDWHGHOHWHFRS\PRYHDQGOLVWGLUHFWRULHV
&UHDWHGHOHWHFRS\DQGPRYHILOHV
9LHZWKHFRQWHQWRIERWKWH[WDQGELQDU\ILOHV
6SOLWODUJHILOHVLQWRVPDOOHURQHV

Figure 4-1. Objectives LX023.0

Notes:

4-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
$)LOH

$ILOHLV

$BFROOHFWLRQBRIBGDWD?Q
$BVWUHDPBRIBFKDUDFWHUVBRUBDBE\WHBVWUHDP?Q
1RBVWUXFWXUHBLVBLPSRVHGBRQBDBILOHBE\BWKHBRSHUDWLQJBV\VWHP?Q

?Q QHZOLQHFKDUDFWHU
B VSDFHFKDUDFWHU

Figure 4-2. A File LX023.0

Notes:
Linux imposes no internal structure on a file's content. The user is free to structure and
interpret the contents of a file in whatever way is appropriate.

© Copyright IBM Corp. 2001, 2003 Unit 4. Working with Files and Directories 4-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

)LOH7\SHV

RUGLQDU\ GLUHFWRU\ VSHFLDOILOH

DVFLLWH[W KDUGZDUHGHYLFHV
 ZDOUXV
IRUH[DPSOH
H[HFXWDEOH  SURILOH
GHYOS SULQWHUGHYLFH
 P\ILOH
MSHJSLFWXUH  EDVKUF

KWPOILOH ORJLFDOGHYLFHV
IRUH[DPSOH
GHYQXOO QXOOGHYLFH

Figure 4-3. File Types LX023.0

Notes:
An ordinary file can contain either text or code data. Text files are readable by a user and
can be displayed or printed. Code data, also known as binary file, is readable by the
computer. Binary files may be executed.
Directories contain information the system needs to access all types of files, but they do not
contain the actual data. Each directory entry represents either a file or subdirectory.
Special files usually represent devices used by the system. A very useful special file is
/dev/null, which can be used as a sort of trashbin for unwanted output.

4-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
/LQX[)LOHQDPHV

6KRXOGEHGHVFULSWLYHRIWKHFRQWHQW
6KRXOGXVHRQO\DOSKDQXPHULFFKDUDFWHUV
833(5&$6(ORZHUFDVHQXPEHU#B
6KRXOGQRWLQFOXGHHPEHGGHGEODQNV
6KRXOGQRWFRQWDLQVKHOOPHWDFKDUDFWHUV
"! >@_?
  ^`
6KRXOGQRWEHJLQZLWKRUVLJQ
$UHFDVHVHQVLWLYH
)LOHQDPHVVWDUWLQJZLWKDDUHKLGGHQ
7KHPD[LPXPQXPEHURIFKDUDFWHUVIRUDILOHQDPHLV

Figure 4-4. Linux Filenames LX023.0

Notes:
In general, the naming of files is free in Linux. Linux for instance does not force filenames
into an 8.3 format like MS-DOS did. Extensions in general have no value to the shell. They
may be relevant for applications, though.
Theoretically, every character on your keyboard can be used in a filename. But since the
shell interprets various characters as metacharacters, it is best to stick to lowercase and
uppercase letters, digits, the underscore and the at sign. Other characters like embedded
blanks and metacharacters should preferably not be used. If you encounter them, you need
to quote them properly. (Discussed later)
The dot is a special case: Anywhere in the filename it is simply used as part of the file
name, except when the dot is the first character in the file name. If a file name begins with
a dot (for example, .bash_profile), the file is considered to be a hidden file and will not
show up when you enter the ls command, for example.

© Copyright IBM Corp. 2001, 2003 Unit 4. Working with Files and Directories 4-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

/LQX[3DWKQDPHV

)XOOSDWKQDPHV
6WDUWIURP WKHURRWGLUHFWRU\

5HODWLYHSDWKQDPHV
6WDUWIURPWKHSUHVHQWZRUNLQJGLUHFWRU\

([DPSOHV ZRUNLQJGLUHFWRU\LVKRPHWX[
KRPHWX[GRFPRQBUHSRUW IXOO
GRFPRQBUHSRUW UHODWLYH
WX[SJPVVXED UHODWLYH
WHVW DILOHLQWKHFXUUHQWGLU
aWHVW VDPHDVDERYH

Figure 4-5. Linux Pathnames LX023.0

Notes:
The path name is written as a string of names separated by slashes (not back slashes like
in DOS, OS/2 or Windows). The rightmost name can be any type of file (ordinary, directory
or special). The other names must be directories.
A path name is always considered to be relative UNLESS it begins with a slash (/). An
absolute path name or full path name always starts with a slash.

4-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
([DPSOH'LUHFWRU\6WUXFWXUH

KRPH

WX[ WX[ WX[

EDVKBSURILOH
WHVW GRF F PDQXDOV US F SJPV
WHVW VXED
PRQBUHSRUW D
WULRBOWU E
ZDOUXV

Figure 4-6. Example Directory Structure LX023.0

Notes:
This example directory structure will be used in the rest of the unit.

© Copyright IBM Corp. 2001, 2003 Unit 4. Working with Files and Directories 4-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

:KHUH$P,"

7KHSZGFRPPDQG SULQWZRUNLQJGLUHFWRU\ FDQEHXVHG


WRILQGRXWZKDW\RXUFXUUHQWZRUNLQJGLUHFWRU\LV

SZG
KRPHWX[


Figure 4-7. Where Am I? LX023.0

Notes:
The pwd command will always return the full path name of your (current) present working
directory. It is not a bad idea to use this command often, especially when you are removing
files (to be sure you are removing them from the correct directory).
Note that most distributions, by default, configure a shell prompt which lists the last part of
the current directory as well.

4-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&KDQJH&XUUHQW'LUHFWRU\

:LWKWKHFG FKDQJHGLUHFWRU\ FRPPDQG


FGGLUBQDPH

FGGRF UHODWLYH
FGKRPHWX[GRF IXOO
FGaWX[GRF KRPH

FG *RWR\RXUKRPHGLUHFWRU\
FG *RRQHGLUHFWRU\XS
FG *RWRSUHYLRXVGLUHFWRU\

Figure 4-8. Change Current Directory LX023.0

Notes:
Using the cd command with nothing after it will automatically return you to your home
directory. This is the directory into which you are usually placed when you log in.

© Copyright IBM Corp. 2001, 2003 Unit 4. Working with Files and Directories 4-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&UHDWH'LUHFWRULHV

:LWKWKHPNGLU PDNHGLUHFWRU\ FRPPDQG


PNGLUGLUBQDPH

PNGLUKRPHWX[GRF IXOOSDWKQDPH

FGKRPHWX[
PNGLUGRF  UHODWLYHSDWKQDPH

Figure 4-9. Create Directories LX023.0

Notes:
The mkdir command creates one or more new directories specified by the dir_name
parameter. Each new directory contains the standard entries . (dot) and .. (dot dot).
The -m option can be used with the mkdir command to specify the directory being created
with a particular set of permissions.

4-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
5HPRYLQJ'LUHFWRULHV

:LWKWKHUPGLU UHPRYHGLUHFWRU\ FRPPDQG


UPGLUGLUBQDPH

SZG
KRPHWX[
UPGLUGRFWHVW
UPGLUGRF'LUHFWRU\QRWHPSW\


GLUHFWRU\PXVWEHHPSW\

Figure 4-10. Removing Directories LX023.0

Notes:
The rmdir command lets you delete directories.
You get no message if the command is successful. It never hurts to follow a command such
as this with an ls, which is discussed on the next page, to make sure that you have
accomplished what you set out to do.
It is also practical to check if you are in the correct directory with pwd, before you try to
remove something.

© Copyright IBM Corp. 2001, 2003 Unit 4. Working with Files and Directories 4-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

:RUNLQJZLWK0XOWLSOH'LUHFWRULHV

&UHDWHDQGUHPRYHPXOWLSOHGLUHFWRULHVVLPXOWDQHRXVO\
ZLWKWKHSIODJ

PNGLUSGLUGLUGLU
UPGLUSGLUGLUGLU

Figure 4-11. Working with Multiple Directories LX023.0

Notes:
The mkdir dir1/dir2/dir3 command will generate an error message if neither dir1 nor dir2
exists. To overcome this problem, you could use the -p option with mkdir. If dir1 and dir2
already exist, only dir3 is created.
The -p option with rmdir first removes dir3, then dir2 and finally the dir1 directory. If a
directory is not empty, you are in it, or you do not have the right permissions to it when it is
removed, the command terminates.

4-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
/LVWWKH&RQWHQWVRI'LUHFWRULHV

:LWKWKHOVFRPPDQG
OV>GLUILOH@

OVKRPH
WX[WX[WX[

,PSRUWDQWRSWLRQV
O ORQJOLVWLQJ PRUHLQIRUPDWLRQ
D OLVWVDOOILOHV LQFOXGLQJKLGGHQ
W OLVWVILOHVVRUWHGE\FKDQJHGDWH
5 OLVWVFRQWHQWVUHFXUVLYHO\

Figure 4-12. List of Contents of Directories LX023.0

Notes:
The ls command is used to list the contents of a directory, and has many useful options. If
no file or directory name is given as an argument, the current directory will be used.
By default, the ls command displays the information in alphabetic order. When the ls
command is executed it does not display any file names that begin with a dot (.), unless the
-a option is used. These files are generally referred to as hidden files, for this reason.

© Copyright IBM Corp. 2001, 2003 Unit 4. Working with Files and Directories 4-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHWRXFK&RPPDQG

7KHWRXFKFRPPDQGXSGDWHVWKHDFFHVVDQGRU
PRGLILFDWLRQWLPHVRIDILOH

OVO
UZUZUWX[SHQJXLQV)HEGRFV

WRXFKGRFV
OVO
UZUZUWX[SHQJXLQV0DUGRFV

WRXFKQHZ
OVO
UZUZUWX[SHQJXLQV0DUGRFV
UZUZUWX[SHQJXLQV0DUQHZ

Figure 4-13. The touch Command LX023.0

Notes:
The touch command serves two purposes:
• If the file specified by the file name does not exist, a zero length (empty) file is created.
This is useful since some programs in Linux only use the fact that a file exists to perform
a certain action or not. The contents are then not important.
An example of this is a lockfile. Suppose you have a special program which can only run
once on a system. It is not allowed to run two instances. To ensure that this program is
only started once, the program first checks if a certain file exists. If it does exist, it
terminates itself. If it does not yet exist, it creates the file and starts working. When the
program is terminated by the user, it also deletes the file. This effectively ensures that
the program can only be started once.
• If the file does exist, the last modification time (displayed with ls -l) is updated to reflect
the current date and time.
This can be useful to force a backup of a file for instance, when only incremental
backups are made.

4-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty The -t parameter allows you to specify a time and date. This makes it possible to give a file
any date and time you like.

© Copyright IBM Corp. 2001, 2003 Unit 4. Working with Files and Directories 4-15
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&RS\LQJ)LOHV

7KHFSFRPPDQGFRSLHVILOHV
FSVRXUFH>V@>WDUJHW@

&RS\LQJRQHILOHWRDQRWKHU
FSEDVKUFEDVKUFROG

&RS\LQJPXOWLSOHILOHVLQWRDWDUJHW
GLUHFWRU\
FSGRFPRQBUHSRUWGRFZDOUXVWPS

Figure 4-14. Copying Files LX023.0

Notes:
Pay attention to the two ways you can use the cp command. The first syntax copies a file
from one directory to another directory.
The second syntax is if you enter more than two parameters to cp. This means that the first
n parameters (which represent files) are copied to the last parameter, which represents a
directory.

4-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&RS\LQJ)LOHV 

FSFDQUHFXUVLYHO\FRS\GLUHFWRULHVZLWKWKH5IODJ

FS5KRPHWX[GRFWPS

7RSUHYHQWFSIURPRYHUZULWLQJH[LVWLQJ
ILOHVXVH
FS5LKRPHWX[GRFWPS
FSRYHUZULWHCWPSGRFZDOUXV"

Figure 4-15. Copying Files (2) LX023.0

Notes:
When using the cp command, if the file specified as the target file already exists, then the
copy operation will write over the original contents of the file without warning. To avoid this,
use cp -i (interactive copy).
If you are copying more than one file in one operation, the specified target must be a
directory.
If the target is a directory, the copy will have the same name as the original file.
cp -R can be used to recursively copy all files, subdirectories, and the files in those
directories to a new directory.

© Copyright IBM Corp. 2001, 2003 Unit 4. Working with Files and Directories 4-17
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

0RYLQJDQG5HQDPLQJ)LOHV

:LWKWKHPYFRPPDQG
PYVRXUFH>V@>WDUJHW@

7RPRYHDILOHGRDQRWKHUGLUHFWRU\
PYGRFZDOUXVWPS

7RUHQDPHDILOH
PYGRFGRFXPHQWV

8VHWKHLRSWLRQWRSUHYHQWPYIURP
RYHUZULWLQJH[LVWLQJILOHV

Figure 4-16. Moving and Renaming Files LX023.0

Notes:
The mv command is used to move files from one directory to another. The syntax is
mv source target.
The mv command can also be used to rename files.

4-18 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
0RYLQJDQG5HQDPLQJ)LOHV 

0RYLQJDQGUHQDPLQJILOHVFDQEHFRPELQHGE\PY

FG
SZG
KRPHWX[
PYWPSZDOUXV WHVWURE

7RPRYHDGLUHFWRU\
PYWHVWWPS

PYLVUHFXUVLYHE\GHIDXOW

Figure 4-17. Moving and Renaming Files (2) LX023.0

Notes:
The source can be a file or a list of files. If the source is a list of files, then the target must
be a directory.
The target can be a file or a directory. BEWARE, if the target is the name of a file that
already exists and if you have the correct permissions set for that file and directory, you will
overwrite the file and never get an error message. To avoid this, use mv -i, an interactive
move which prompts you if there are duplicate names.
As a result of the mv you will still have the same number of files as you did before.
Furthermore, all the attributes remain the same. The only things that change are the file
name and/or location.
If the source is a directory instead of a file, then mv will attempt to move this whole
directory to the new location, with all the files in it. Earlier versions of mv would only do this
if the source and target directory were on the same filesystem. Current versions of mv now
perform a cp and rm automatically if you try to move directories between filesystems.

© Copyright IBM Corp. 2001, 2003 Unit 4. Working with Files and Directories 4-19
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

/LVWLQJ)LOH&RQWHQWV

:LWKWKHFDW FRQFDWHQDWH FRPPDQG

FDWILOHILOH

FDWZDOUXV
7KHWLPHKDVFRPHWKHZDOUXVVDLG
7RWDONRIPDQ\WKLQJV
2IVKRHVDQGVKLSVDQGVHDOLQJZD[
2IFDEEDJHDQGNLQJV
$QGZK\WKHVHDLVERLOLQJKRW
$QGZKHWKHUSLJVKDYHZLQJV


Figure 4-18. Listing File Contents LX023.0

Notes:
If the output of the cat command is longer than a screen, the file will scroll until the bottom
of the file is reached. Thus, you may only be able to read the last full screen of information.
The cat command can be used to copy two files into one file. The syntax is:
cat file1 file2 > new_file

4-20 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
'LVSOD\LQJ)LOHV3DJHE\3DJH

:LWKWKHPRUHRUOHVVRPPDQGV

OHVVZDOUXV
7KHWLPHKDVFRPHWKHZDOUXVVDLG
7RWDONRIPDQ\WKLQJV
2IVKRHVDQGVKLSVDQGVHDOLQJZD[
2IFDEEDJHDQGNLQJV
$QGZK\WKHVHDLVERLOLQJKRW
$QGZKHWKHUSLJVKDYHZLQJV
WPSWHVWZDOUXV (1'

Figure 4-19. Displaying Files Page by Page LX023.0

Notes:
The more and less commands reads the file names specified and displays the contents of
the files one page at a time. Use the space bar to view the next page and the b key to view
previous one.
To search for patterns in the file which is displayed, use the / (forward slash) key. To repeat
a search, use n.
The advantage of less over more is that less can also scroll backwards if its input is
received from a pipe. Another difference is that less will clear the screen when done, while
more keeps the content of the last page on screen.
Use the q to end the more and less commands. (less does not terminate itself when the
end of the file is reached.)

© Copyright IBM Corp. 2001, 2003 Unit 4. Working with Files and Directories 4-21
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

'LVSOD\LQJ%LQDU\)LOHV

:LWKWKHRGFRPPDQG
RGXVUELQSDVVZG





:LWKWKHVWULQJVFRPPDQG
VWULQJVXVUELQSDVVZG
OLEOGVR
BBJPRQBVWDUWBB
BBGHUHJLVWHUBIUDPHBLQIR
BBUHJLVWHUBIUDPHBLQIR



Figure 4-20. Displaying Binary Files LX023.0

Notes:
od (octal dump) allows you to view the contents of a binary file byte by byte. Without any
option, od shows the contents of the file in octal format, but you can also specify the -c
option for decimal display, or the -h option for hexadecimal display. Other output options
also exist.
strings is also a very handy tool to take a peek at binary files. It only displays all the strings
that occur in a binary file. (A string is a combination of at least 4 consecutive, contiguous,
printable ASCII characters.)
An alternative for od is hexdump. It basically does the same thing, but in a slightly more
readable format. It is not available on all distributions by default, however.

4-22 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
5HPRYLQJ)LOHV

:LWKWKHUPFRPPDQG

UPWHVWURE
OVWHVWURE
OVURE1RVXFKILOHRUGLUHFWRU\

,IXQVXUHXVHLRSWLRQ
UPLWHVWURE
UPUHPRYHCWHVWURE"

7RUHPRYHILOHVDQGGLUHFWRULHV
UHFXUVLYHO\
UPLUWHVW

Figure 4-21. Removing Files LX023.0

Notes:
The rm command removes the entries for the specified file or files from a directory. Note
that the rm command by default does not require confirmation from the user1. For the
interactive version of the command use the -i option.
The -r option permits recursive removal of directories and their contents if directory is
specified. Be careful when using this option, as it does not require the directory to be empty
in order for this option to work.
The -f ("force") option prevents error messages and does not ask the user for confirmation.

1
Some distributions therefore alias rm to rm -i. You will learn how to use aliases later in this course.

© Copyright IBM Corp. 2001, 2003 Unit 4. Working with Files and Directories 4-23
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

6SOLWWLQJ)LOHV

<RXFDQVSOLWDILOHLQWRDVPDOOHUILOHVZLWKWKHVSOLW
FRPPDQG
VSOLWE%\WHV!ILOH>SUHIL[@

OVO
UZUUURRWURRW)HEODUJH

VSOLWENODUJHODUJH
OVO
UZUUURRWURRW)HEODUJH
UZUUURRWURRW)HEODUJHDD
UZUUURRWURRW)HEODUJHDE
UZUUURRWURRW)HEODUJHDF
UZUUURRWURRW)HEODUJHDG

Figure 4-22. Splitting Files LX023.0

Notes:
If files are too large, for instance to fit on a floppy, they can be split into multiple, smaller
files. This can be done based on bytes or lines.

4-24 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
)LOH0DQDJHUV

/LQX[DOVRRIIHUVGLIIHUHQWJUDSKLFDOILOHPDQDJHUV
1DXWLOXV *120(
.RQTXHURU .'(


Figure 4-23. File Managers LX023.0

Notes:
When you are in a graphical environment, you do not need to use these commands
(although they're not that hard if you're used to them), but you can use one of the several
graphical file managers that are available for your desktop environment.
Both the GNOME and KDE file managers have the capability to recognize the type of file
that you are working with and, if appropriate, allow you to do something with the content as
well. If you click on a .tar.gz file (a compressed file archive) for instance, it will automatically
uncompress the file and open the archive. You can then copy the files out of the archive.
And if you click on .rpm files (Red Hat Package Manager, the default format for software
distribution in most distributions), you can read the information about that .rpm file or install
it right away.

© Copyright IBM Corp. 2001, 2003 Unit 4. Working with Files and Directories 4-25
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&KHFNSRLQW

7)/LQX[LPSRVHVDQLQWHUQDOVWUXFWXUHRQDUHJXODU
ILOH QRWDGLUHFWRU\RUVSHFLDOILOH 

:KLFKRIWKHIROORZLQJLVQRWDOHJDOILOHQDPH"
DaWX[P\GRFVWDUJ]
EKRPHWX[P\GRF 
FYDUWPSVHFUHWGRF
GKRPHKRPHWX[RQHRQH

:KDWFRPPDQGZRXOG\RXXVHWRFRS\WKHILOH
 KRPHWX[P\GRFWRWPSDQGUHQDPHLWDWWKHVDPH
 WLPHWRWHPSGRF"


Figure 4-24. Checkpoint LX023.0

Notes:

4-26 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
8QLW6XPPDU\

7KHUHDUHWKUHHW\SHVRIILOHV
2UGLQDU\
'LUHFWRU\
6SHFLDO
7KH/LQX[ILOHV\VWHPVWUXFWXUHLVDKLHUDUFKLFDOWUHH
)LOHVDUHDFFHVVHGXVLQJHLWKHUIXOORUUHODWLYHSDWK
QDPHV$IXOOSDWKQDPHDOZD\VEHJLQVZLWKD
7KHIROORZLQJFRPPDQGVFDQEHXVHGZLWKGLUHFWRULHV
SZGFGPNGLUUPGLUWRXFKDQGOV
7KHIROORZLQJFRPPDQGVFDQEHXVHGZLWKILOHVFDW
PRUHOHVVFSPYUPWRXFKRGVSOLWDQGVWULQJV

Figure 4-25. Unit Summary LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 4. Working with Files and Directories 4-27
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

4-28 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 5. File and Directory Permissions

What This Unit Is About


This unit covers the most important commands that allow the user to
manipulate files and directories.

What You Should Be Able to Do


After completing this unit, you should be able to:
• Describe how permissions are used
• List the permissions required to perform several common
commands
• Change permissions using symbolic and octal notation
• Describe how default permissions are calculated

How You Will Check Your Progress


Accountability:
• Checkpoint questions
• Machine exercises

© Copyright IBM Corp. 2001, 2003 Unit 5. File and Directory Permissions 5-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
'HVFULEHKRZSHUPLVVLRQVDUHXVHG
/LVWWKHSHUPLVVLRQVUHTXLUHGWRSHUIRUPVHYHUDOFRPPRQ
FRPPDQGV
&KDQJHSHUPLVVLRQVXVLQJV\PEROLFDQGRFWDOQRWDWLRQ
'HVFULEHKRZGHIDXOWSHUPLVVLRQVDUHFDOFXODWHG

Figure 5-1. Objectives LX023.0

Notes:

5-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
8VHUVDQG*URXSV

*URXSSHQJXLQV *URXSSHRSOH

ULFKDUG
WX[
DODQ
WX[ OLQXV

;
(DFKILOHKDVDQRZQHU
JURXSVSHQJXLQVKHUULQJW[W (DFKILOHLVDVVLJQHGWRDJURXS

Figure 5-2. Users and Groups LX023.0

Notes:
In order to protect your files from other users, Linux allows you to set permissions on files
and directories. As an example, you might want to create files that are only accessible to
users that are members of a particular group, while members of other groups don’t have
access to these files. But you might also want to protect your own files from all other users
on the system, or make sure that certain system files can only be read by users, and not
written to.

© Copyright IBM Corp. 2001, 2003 Unit 5. File and Directory Permissions 5-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

3HUPLVVLRQV

)LOHSHUPLVVLRQVDUHDVVLJQHGWR

WKHRZQHURIDILOH
WKHPHPEHUVRIWKHJURXSWKHILOHLVDVVLJQHGWR
DOORWKHUXVHUV

3HUPLVVLRQVFDQRQO\EHFKDQJHGE\WKHRZQHUDQG
URRW

Figure 5-3. Permissions LX023.0

Notes:
Permissions under Linux are configured for each file and directory. There are three levels
of permissions:
1. The permissions that apply to the owner of the file. The owner of a file is by default the
user that created the file1.
2. The permissions that apply to all members of the group that is associated with the file.
3. The permissions that apply to all other users on the system.
Permissions can only be changed by the owner, and root of course.

1
The rootuser can change the owner of a file afterwards. This is outside the scope of this course, but will be covered in the LX03.

5-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
9LHZLQJ3HUPLVVLRQV

7RVKRZWKHSHUPLVVLRQVRIDILOHXVHWKHOV
FRPPDQGZLWKWKHORSWLRQ
OVO
UZUUWX[SHQJXLQV-XQILOH
UZUUWX[SHQJXLQV-XQILOH
GUZ[U[U[WX[SHQJXLQV-XQP\GLU

)LOHW\SH RZQHU VL]H QDPH

SHUPLVVLRQV JURXS PWLPH


PRGLILFDWLRQWLPH
OLQNFRXQWHU

Figure 5-4. Viewing Permissions LX023.0

Notes:
To view the permissions that are currently applied to a file, use the ls -l command.
Note that, when viewing the permissions on a directory, you cannot use the command
ls -l <directoryname>, since that command will list the contents of the directory, and not
the directory itself. Instead, use the command ls -ld <directoryname>.

© Copyright IBM Corp. 2001, 2003 Unit 5. File and Directory Permissions 5-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

3HUPLVVLRQV1RWDWLRQ

UZ[UZ[UZ[ U
Z
UHDG
ZULWH
[ H[HFXWH
RZQHUJURXSRWKHU
UHJXODUILOHV
U ILOHLVUHDGDEOH
ZILOHLVZULWHDEOH
[ ILOHLVH[HFXWDEOH LILQDQH[HFXWDEOHIRUPDW

GLUHFWRULHV
U FRQWHQWVRIGLUHFWRU\FDQEHOLVWHG OV
Z FRQWHQWVFDQEHPRGLILHG DGGGHOHWHILOHV
[ FKDQJHLQWRGLUHFWRU\LVSRVVLEOH FG

Figure 5-5. Permissions Notation LX023.0

Notes:
For each of the three groups (user, group and others), three permissions can be set: read,
write and execute.
For a file, these permissions mean the following:
• read: allow the user to read the contents of the file, for instance with cat or less.
• write: allow the user to modify the contents of the file, for instance with vi.
• execute: allow the user to execute the file as a program, provided that the file is indeed
an executable program (such as a shell script).
For a directory, these permissions have a slightly different meaning:
• read: allow the user to view the contents of the directory, for instance with ls.
• write: allow the user to modify the contents of the directory. In other words: allow the
user to create and delete files, and to modify the names of the files.
Note: Having write permissions on a directory thus allows you to delete files, even if you
have no write permissions on that file!

5-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty • execute: allow the user to use this directory as its current working directory. In other
words: allow the user to cd into it.

© Copyright IBM Corp. 2001, 2003 Unit 5. File and Directory Permissions 5-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

5HTXLUHG3HUPLVVLRQV

&RPPDQG 6RXUFHGLUHFWRU\ 6RXUFHILOH 7DUJHWGLUHFWRU\

FG [ 1$ 1$

OV [U 1$ 1$

PNGLUUPGLU [Z 1$ 1$

FDWOHVV [ U 1$

FS [ U [Z

FSU [U U [Z

PY [Z QRQH [Z

YL [U UZ 1$

UP [Z QRQH 1$

Figure 5-6. Required Permissions LX023.0

Notes:
The visual shows the permissions that are required for certain common Linux commands.

5-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&KDQJLQJ3HUPLVVLRQV

7RFKDQJHWKHSHUPLVVLRQRIDILOHXVHWKHFKPRG
FRPPDQG
6\QWD[ FKPRG02'(! ),/(>6@!
0RGHFDQEHV\PEROLF
FKPRGJRU[KRPHWX[
OVOGKRPHWX[
GUZ[ WX[ XVHUV  -DQ KRPHWX[

RURFWDO
FKPRGKRPHWX[
OVOGKRPHWX[
GUZ[ WX[ XVHUV  -DQ KRPHWX[

Figure 5-7. Changing Permissions LX023.0

Notes:
Changing permissions is done with the chmod command. This command supports two
different ways of writing down the required permissions: symbolic and octal.
Symbolic notation describes the permissions using the following syntax:
chmod <who operator what> <filename(s)>
<who> can be:
• u for the owner (user) of the file
• g for the group assigned to the file
• o for all other users
• a for all (owner+group+others)
<operator> can be:
• + to add permissions
• - to delete permissions

© Copyright IBM Corp. 2001, 2003 Unit 5. File and Directory Permissions 5-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

• = to clear all permissions and set to the permissions specified


<what> can be any combination of r, w and x.
Legal commands are for instance:
• chmod u=rw,go=r <file> - Gives the user read-write permissions, and gives read
permissions to the group and others. All previous permissions are discarded.
• chmod a+x - Give everybody execute permissions in additions to the permissions they
already had.
With octal notation, permissions are identified with an octal number.

5-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&KDQJLQJ3HUPLVVLRQV 

&DOFXODWLQJQXPHULF RFWDO PRGH

UZ[ U[ 


U 
Z 
 
[ 
  LIXQVHWLVXVHG
 

PRGHLV

Figure 5-8. Changing Permissions (2) LX023.0

Notes:
The visual shows how octal numbers are calculated.
Octal permissions may seem incredibly complex, when compared to symbolic notation.
However, in actual practice there are only a few permission combinations that make sense.
When applying these permissions, experienced Linux users don’t have to think about them
anymore, but apply them blindly. These combinations are:
600 (rw-------) For private files
700 (rwx------) For private programs and directories
644 (rw-r--r--) For files that you want to be readable by others
755 (rwxr-xr-x) For programs and directories you want to be
readable/executable by others
666 (rw-rw-rw-) For public writable files (does not happen often)
777 (rwxrwxrwx) For public writable directories such as /tmp.

© Copyright IBM Corp. 2001, 2003 Unit 5. File and Directory Permissions 5-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Note: /tmp actually has an additional permission bit set called


the “sticky bit”. Because of this bit, the permissions in reality are
4777, or rwxrwxrwt. This will be covered in the LX03.

5-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
XPDVN

1HZILOHVVKRXOGQRWEHFUHDWHGZLWK7RDYRLGWKLV
SUREOHPDSHUPLVVLRQPDVNH[LVWV

UHJXODUILOHV
GHIDXOWSHUPLVVLRQV UZUZUZ 

XPDVN  ZZ 

UHVXOWLQJSHUPLVVLRQV UZUU 

GLUHFWRULHV
GHIDXOWSHUPLVVLRQV UZ[UZ[UZ[ 

XPDVN  ZZ 

UHVXOWLQJSHUPLVVLRQV UZ[U[U[ 

6\QWD[XPDVN
Figure 5-9. umask LX023.0

Notes:
It is obviously important to know with what permissions new files and directories are
created. Under Linux, it’s not really easy to tell, since the default permissions can be
modified by setting a umask (with the umask command).
If no umask were set (which never happens, by the way), a file would always be created
with permissions 666 (rw-rw-rw-) and a directory would get 777 (rwxrwxrwx). In actual
practice however, a umask is set, and this number is subtracted from these permissions.
So, with a umask of 022, the default permissions for a file will become 644 (rw-r--r--,
666-022) and the default permissions for a directory will become 755 (rwx-r-xr-x, 777-022).
The default umask depends on your distribution, and whether your distribution uses
something called “User Private Groups”.
• Red Hat assigns a umask of 002 to regular users, and 022 to root.
• SuSE assigns a umask of 022 to all users, including root.
User Private Groups and the reasons for the different umasks are beyond the scope of this
course. They’re covered in the LX03.

© Copyright IBM Corp. 2001, 2003 Unit 5. File and Directory Permissions 5-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&KHFNSRLQW

SZG
JURXSV
OVO
GUZ[UZ[U[URRWSHQJXLQV)HESHQJXLQV
OVOSHQJXLQV
UZUUWX[SHQJXLQV)HEKHOORF
UZUUWX[SHQJXLQV)HEWDVNF
UZUUWX[SHQJXLQV)HE]LSF

&DQWX[ ZKRLVDOVRDPHPEHURIWKHSHQJXLQVJURXS VXFFHVVIXOO\H[HFXWH


WKHIROORZLQJFRPPDQGV"
FGJURXSVSHQJXLQV
PNGLUJURXSVSHQJXLQVP\GLU
FSJURXSVSHQJXLQVWDVNFaWDVNF
YLJURXSVSHQJXLQV]LSF
YLJURXSVSHQJXLQVQHZILOHF
UPJURXSVSHQJXLQVKHOORF

Figure 5-10. Checkpoint LX023.0

Notes:

5-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
8QLW6XPPDU\

3HUPLVVLRQVGHWHUPLQHZKHWKHUDXVHULVDEOHWRGR
VRPHWKLQJZLWKDILOHRUGLUHFWRU\
3HUPLVVLRQVFDQEHVHWIRUWKHXVHUWKHJURXSDQGDOO
RWKHUV
7KUHHEDVHSHUPLVVLRQVH[LVWUHDGZULWHDQGH[HFXWH
7RYLHZWKHSHUPLVVLRQVXVHOVO
3HUPLVVLRQVFDQRQO\EHFKDQJHGE\WKHRZQHURIWKHILOH
RUGLUHFWRU\DQGE\URRW
7KHXPDVNGHWHUPLQHVWKHGHIDXOWSHUPLVVLRQVRQDILOH

Figure 5-11. Unit Summary LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 5. File and Directory Permissions 5-15
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

5-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 6. Linux Documentation

What This Unit Is About


This unit covers the main documentation sources with regards to
Linux.

What You Should Be Able to Do


After completing this unit, you should be able to:
• Use the man command to view information about Linux commands
• Describe the use of info
• Describe the HOWTO documentation
• Explain the importance of Internet for gathering information about
Linux

How You Will Check Your Progress


Accountability:
• Checkpoint questions
• Machine exercises

© Copyright IBM Corp. 2001, 2003 Unit 6. Linux Documentation 6-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
8VHWKHPDQFRPPDQGWRYLHZLQIRUPDWLRQDERXW/LQX[
FRPPDQGV
'HVFULEHWKHXVHRILQIR
'HVFULEHWKH+2:72GRFXPHQWDWLRQ
([SODLQWKHLPSRUWDQFHRI,QWHUQHWIRUJDWKHULQJ
LQIRUPDWLRQDERXW/LQX[

Figure 6-1. Objectives LX023.0

Notes:

6-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KHPDQ&RPPDQG

:LWKWKHPDQFRPPDQG\RXFDQUHDGWKHPDQXDOSDJH
RIFRPPDQGV
0DQXDOSDJHVDUHVWRUHGLQXVUVKDUHPDQ
7KHPDQXDOSDJHFRQVLVWVRI

1DPH 7KHQDPHRIWKHFRPPDQGDQGDRQHOLQH
GHVFULSWLRQ
6\QRSVLV 7KHV\QWD[RIWKHFRPPDQG

'HVFULSWLRQ ([SODQDWLRQRIKRZWKHFRPPDQGZRUNVDQG
ZKDWLWGRHV
)LOHV 7KHILOHVXVHGE\WKHFRPPDQG

%XJV .QRZQEXJVDQGHUURUV

6HHDOVR 2WKHUFRPPDQGVUHODWHGWRWKLVRQH

Figure 6-2. The man Command LX023.0

Notes:
The man command will show the manual page of the commands and/or subroutines given
as an argument to the man command.
Most manual pages will consist of:
Name The title and a one-line description of the command
Synopsis The syntax of the command
Description Many pages of information about the function and usage of the
command
Options An explanation of the options
Files Any system files associated with the command
Bugs Any information about the behavior/performance of the
command in unusual circumstances

© Copyright IBM Corp. 2001, 2003 Unit 6. Linux Documentation 6-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

See also Other commands that are related to the same topic. Viewing
them can tell you more about the working of this particular
command
The output from the man command is presented one page at a time, using the less pager.
As we’ve already seen earlier, use the space bar to move forward one page at a time.
Pressing h while viewing the output will show you other commands and key sequences to
view the output. The b key will show you the previous page of information.
You can search for a pattern in a manual page with the / key.

6-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
PDQ([DPSOH

PDQILQJHU
)RUPDWWLQJSDJHSOHDVHZDLW
1$0(
ILQJHUXVHULQIRUPDWLRQORRNXSSURJUDP

6<1236,6
ILQJHU>OPVS@>XVHU@>XVHU#KRVW@

'(6&5,37,21
7KHILQJHUFRPPDQGGLVSOD\VLQIRUPDWLRQ
DERXWWKHV\VWHPXVHUV

2SWLRQVDUH
V)LQJHUGLVSOD\VWKHXVHU
VORJLQQDPH


Figure 6-3. man Example LX023.0

Notes:
This is only the first screen of the manual page of the finger command.
Note the first line of the manual page, which reads "Formatting page, please wait...". You
will see this line only once; the next time you view this manual page it will not appear. The
reason for this is that manual pages are written in a special format (troff), which basically
allows the man command to adapt the way your page will look to the output medium. This
formatting is done on the fly the first time a manual page is called up. After that, it is stored
on disk in a formatted format as well.

© Copyright IBM Corp. 2001, 2003 Unit 6. Linux Documentation 6-5


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

PDQ([DPSOH 

7KHNRSWLRQRIWKHPDQFRPPDQGRUWKHDSURSRV
FRPPDQGSULQWVRXWDGHVFULSWLRQRIDOOHQWULHVZKLFK
PDWFKWKHJLYHQNH\ZRUG

PDQNSULQW
DUFK  SULQWPDFKLQHDUFKLWHFWXUH
GDWH  SULQWRUVHWWKHV\VWHPGDWHDQGWLPH
ORJQDPH  SULQWXVHU
VORJLQQDPH
OSF   OLQHSULQWHUFRQWUROSURJUDP
OSG   OLQHSULQWHUVSRROHUGDHPRQ
OSU   RIIOLQHSULQW
OSUP    UHPRYHMREVIURPWKHOLQHSULQWHUTXHXH

Figure 6-4. man Example (2) LX023.0

Notes:
The man -k command shows the commands that have manual pages that contain any of
the given keywords in their title.
To allow the use of man -k, the superuser (root) must have run the /usr/sbin/makewhatis
command to create the /var/cache/man/whatis file.
The apropos command can also be used and is equivalent to using the man -k command.

6-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
PDQ6HFWLRQV

0DQXDOSDJHVDUHGLYLGHGLQVHFWLRQV
 8VHUFRPPDQGV
 6\VWHPFDOOV
 /LEFFDOOV
 'HYLFHV
 )LOHIRUPDWVDQGSURWRFROV
 *DPHV
 &RQYHQWLRQVPDFURSDFNDJHVDQGVR
IRUWK
 6\VWHPDGPLQLVWUDWLRQ
 .HUQHO
&HUWDLQVXEMHFWVDSSHDULQPXOWLSOHVHFWLRQV
7RVHOHFWFRUUHFWVHFWLRQDGGVHFWLRQQXPEHU
PDQSDVVZG DERXWWKHSDVVZGFRPPDQG
PDQSDVVZG DERXWWKHSDVVZGILOH
Figure 6-5. man Sections LX023.0

Notes:
Manual pages are stored in nine different sections. The first eight of them are standard
across UNIX, and section 9 is used for Linux kernel documentation.
In some cases, a single subject may appear in multiple sections. As an example, “passwd”
is both a command and a file, so a man page appears in two different sections. To retrieve
a manual page from a specific section, specify the section number as the first argument to
man.

© Copyright IBM Corp. 2001, 2003 Unit 6. Linux Documentation 6-7


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHLQIR&RPPDQG

6RPHWLPHVDUHSODFHPHQWIRUPDQXDOSDJHV
:LGHO\XVHGE\WKH*18SURMHFW
,QIRUPDWLRQIRULQIRLVVWRUHGLQXVUVKDUHLQIR
6RPHLQIRFRPPDQGV

VSDFH QH[WVFUHHQRIWH[W
GHORUEV SUHYLRXVVFUHHQRIWH[W

Q QH[WQRGH
S SUHYLRXVQRGH

T TXLWLQIR

Figure 6-6. The info Command LX023.0

Notes:
Another tool for viewing documentation is the info command.
The syntax of the info command is: info cmd_name.
To view the documentation of the info command, enter info info. This will display the info
documentation about the info command.
The info command works with entities named “nodes”. A node is one piece of information
about a command or function. In info, you navigate through nodes to find and read
information. The main difference between info and man is that these nodes can contain
“hyperlinks” to other info pages, just like the World Wide Web.
info has a lot of commands that help you navigate through the documentation. Some of
these commands are:
<space> Next screen of text
<del> or <bs> Previous page of text
n Next node

6-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty p Previous node


u Go to up node
b To top of node
e To end of node

s Search for a string in the current node


? Go to the help
l Leave the help and go back to the node
q Quit info
<tab> Jump to the next cross reference
f Follow this cross reference (this will bring you to another node)
m Pick menu item specified by name.
<Ctrl-l> Refresh screen
Cross references are indicated by a * on a line. With the tab key, you can jump to this cross
reference. Pressing the f key will make info follow the cross reference and show you
another node.
Another way of moving through info is by specifying menu items. A node only contains a
menu when you see * Menu: in the text. Menu items are also indicated by a *. Again use
the tab key to jump to a menu item. Then press the m key and info will ask you what menu
item you want to go to. Just entering an enter will make you jump to the currently selected
menu item. You could also enter another menu item, to jump to the specified menu item.
The info command can be used to obtain the up-to-date information when a manual page
starts with a sentence like: “This documentation is no longer being maintained and may be
inaccurate or incomplete. The Texinfo documentation is now the authoritative source.”

© Copyright IBM Corp. 2001, 2003 Unit 6. Linux Documentation 6-9


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

LQIR([DPSOH

LQIRSZG

)LOHFRUHXWLOVLQIR1RGHSZGLQYRFDWLRQ1H[WVWW\LQYRFDWLRQ8S?
:RUNLQJFRQWH[W

CSZG
3ULQWZRUNLQJGLUHFWRU\

CSZG
SULQWVWKHIXOO\UHVROYHGQDPHRIWKHFXUUHQWGLUHFWRU\7KDW
LVDOOFRPSRQHQWVRIWKHSULQWHGQDPHZLOOEHWKHDFWXDOGLUHFWRU\
QDPHVQRQHZLOOEHV\PEROLFOLQNV

%HFDXVHPRVWVKHOOVKDYHDEXLOWLQFRPPDQGE\WKHVDPHQDPHXVLQJ
WKHXQDGRUQHGFRPPDQGQDPHLQDVFULSWRULQWHUDFWLYHO\PD\JHW\RX
GLIIHUHQWIXQFWLRQDOLW\WKDQWKDWGHVFULEHGKHUH

7KHRQO\RSWLRQVDUHDORQHCKHOS
RUCYHUVLRQ
 1RWH&RPPRQ
RSWLRQV

]],QIR FRUHXWLOVLQIRJ] SZGLQYRFDWLRQOLQHV$OO


:HOFRPHWR,QIRYHUVLRQ7\SH&KIRUKHOSPIRUPHQXLWHP

Figure 6-7. info Example LX023.0

Notes:
The info command is invoked with an argument that is the command of which you want to
view the documentation.
On the screen you will see the following:
File The file that contains the node you are looking at
Node The current node
Next The next node. You can use the n command to jump to this
node
Up Besides a next node, a node can also have an up node. Use
the u command to jump to the up node
The node you are viewing.
Lines The total number of lines for this node.
Position ALL You see all the lines of the node

6-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty TOP You are at the top of the node


BOT You are at the bottom of the node
75% You are at 75% of the node.
See the notes of the previous foil for an overview of info commands.

© Copyright IBM Corp. 2001, 2003 Unit 6. Linux Documentation 6-11


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHKHOS2SWLRQ

$QRWKHUZD\RIJHWWLQJKHOSDERXWDFRPPDQG
+HOSLVEXLOWLQWKHFRPPDQGLWVHOI LIVXSSRUWHG

ZKRKHOS
8VDJHZKR>237,21@>),/(_$5*$5*@

KKHDGLQJSULQWOLQHRIFROXPQKHDGLQJV
PRQO\KRVWQDPHDQGXVHU
DVVRFLDWHGZLWKVWGLQ
TFRXQWDOOORJLQQDPHVDQGQXPEHURI
XVHUVORJJHGLQ
KHOSGLVSOD\WKLVKHOSDQGH[LW
YHUVLRQRXWSXWYHUVLRQLQIRUPDWLRQDQGH[LW

Figure 6-8. The --help Option LX023.0

Notes:
As we already saw, the man and info commands can be used to obtain information about
the working of a command. This information is stored in a separate file in /usr/share/man or
/usr/share/info. Obviously this manual page has to be installed.
Another way of getting help about a command is using the --help option of the command
itself. This option will show you a brief explanation of the synopsis of the command and the
options that can be used with the command. The information shown is part of the command
itself, and does not require the presence of a separate file.
The visual shows some lines of the help the who --help command would give you. The
actual output will probably not fit on your screen. To read the complete help, issue
who --help | less, which will show the output by page.
Note that not all commands support the --help option.

6-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
+2:72'RFXPHQWV

'RFXPHQWVZKLFKGHVFULEHLQGHWDLODFHUWDLQDVSHFWRI
FRQILJXULQJRUXVLQJ/LQX[
'HWDLOHGLQIRUPDWLRQDERXWKRZWRSHUIRUPDJLYHQWDVN
,QVWDOO3&0&,$VXSSRUW
.HUQHOFRPSLODWLRQ
'XDOERRWZLWKRWKHURSHUDWLQJV\VWHPV
+2:72GRFXPHQWVDUHWH[WILOHVLQ
XVUVKDUHGRF+2:72
1HHGWREHLQVWDOOHGPDQXDOO\
2QWKH,QWHUQHW
KWWSZZZWOGSRUJLQGH[KWPO

Figure 6-9. HOWTO Documents LX023.0

Notes:
Linux HOWTOs are documents which describe in detail a certain aspect of configuring or
using Linux. For example, there is the Installation HOWTO, which gives instructions on
installing Linux, and the Mail HOWTO, which describes how to set up and configure mail
under Linux. Other examples include the NET-3 HOWTO and the Printing HOWTO.
HOWTOs are comprehensive docs - much like an FAQ but generally not in
question-and-answer format. However, many HOWTOs contain an FAQ section at the end.
There are several HOWTO formats available: plain text, PostScript, DVI, and HTML.
In addition to the HOWTOs, there are a multitude of mini-HOWTOs on short, specific
subjects. They are only available in plain text and HTML format.

© Copyright IBM Corp. 2001, 2003 Unit 6. Linux Documentation 6-13


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

+2:72([DPSOH

OHVVXVUVKDUHGRF+2:72;)UHH+2:72
7KH/LQX[;)UHH+2:72
E\(ULF65D\PRQG
Y$XJXVW

7KLVGRFXPHQWGHVFULEHVKRZWRREWDLQLQVWDOODQG
FRQILJXUH
YHUVLRQRIWKH;)UHHYHUVLRQRIWKH;:LQGRZ6\VWHP
;5 IRU/LQX[V\VWHPV,WLVDVWHSE\VWHSJXLGHWR
FRQILJXULQJ;)UHHRQ\RXUV\VWHP

7DEOHRI&RQWHQWV
XVUVKDUHGRF+2:72;)UHH+2:72OLQHV

Figure 6-10. HOWTO Example LX023.0

Notes:
The example on the foil shows you the HOWTO on how to install and configure XFree86 on
your system.
XFree86 is the graphical environment of a Linux system.
The example on the foil doesn't show the complete HOWTO. You see only the first 12 of
792 lines.

6-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
2WKHU'RFXPHQWDWLRQ

&HUWDLQSURJUDPVDOVRRIIHURWKHUNLQGVRIGRFXPHQWDWLRQ
+70/
3RVW6FULSW
3ODLQ7H[W
8VXDOO\VWRUHGLQXVUVKDUHGRFSURJUDPQDPH!

Figure 6-11. Other Documentation LX023.0

Notes:
When a programmer creates a program, he or she will usually include the standard
documentation such as manual and/or info pages, and will implement the --help option. But
most programmers also write some non-standardized pieces of documentation. These are
typically README files, with up to date release information, or CHANGELOGS, which list
the changes since the previous versions. Other programmers might write large amounts of
HTML based documentation, or Postscript based installation instructions, and so forth.
A typical distribution leaves this documentation intact and stores it in
/usr/share/doc/<programname>.
In practice, the value of this documentation varies greatly. There are programmers who
only use the standardized tools (man, info) and as a consequence,
/usr/share/doc/<programname> is virtually empty. Other programmers have created a
whole website about their program, consisting of more than twenty HTML pages with
supporting graphics, example configuration files and so forth. So your mileage may vary
here.

© Copyright IBM Corp. 2001, 2003 Unit 6. Linux Documentation 6-15


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

,QWHUQHW

$OO/LQX[GRFXPHQWDWLRQLVDYDLODEOHRQWKH,QWHUQHW
)RULQIRUPDWLRQORRNDW
KWWSZZZWOGSRUJ
KWWSZZZOLQX[RUJ
KWWSZZZUHGKDWFRP
KWWSZZZVXVHFRP
KWWSZZZ[IUHHRUJ
KWWSZZZNHUQHORUJ
KWWSOZQQHW
KWWSZZZXJXFRP
DQGPDQ\PRUH ZZZ
8VHQHWQHZV
FRPSRVOLQX[
&RXQWU\VSHFLILFJURXSV

Figure 6-12. Internet LX023.0

Notes:
All information about Linux can also be found on the internet. There are scores of web
pages on Linux. For more personal and up-to-date help, you can also go to Usenet news
and other forums.

6-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&KHFNSRLQW

7)$+2:72GRFXPHQWLVWKHEHVWVRXUFHRI
GRFXPHQWDWLRQLI\RXZDQWXSWRGDWH
LQIRUPDWLRQDERXWDVSHFLILFFRPPDQG

7KHPDLQ/LQX[GRFXPHQWDWLRQZHEVLWHLV
DKWWSZZZWOGSRUJ
EKWWSZZZOLQX[RUJ
FKWWSZZZOZQQHW
GKWWSZZZNHUQHORUJ

,QZKLFKVHFWLRQVDUHPDQXDOSDJHVGLYLGHG"

Figure 6-13. Checkpoint LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 6. Linux Documentation 6-17


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

8QLW6XPPDU\

7KHPDQFRPPDQGFDQEHXVHGIURPWKHFRPPDQGOLQH
WRYLHZWKHSURSHUV\QWD[RI/LQX[FRPPDQGV
)RUPDQXDOSDJHVWKDWDUHRXWRIGDWH\RXFDQXVHWKH
LQIRFRPPDQGWRYLHZWKHV\QWD[
6SHFLILFV\VWHPDGPLQLVWUDWLRQWDVNVDUHGHVFULEHGLQWKH
+2:72GRFXPHQWV
7KH,QWHUQHWLVWKHSODFHIRUWKHODWHVWLQIRUPDWLRQDERXW
/LQX[

Figure 6-14. Unit Summary LX023.0

Notes:

6-18 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 7. A Tour through Linux

What This Unit Is About


This unit gives an overview of the filesystem structure on a typical
Linux system after installation, and explains some of the concepts
behind this. It also covers the mount and umount commands, and the
/etc/fstab file

What You Should Be Able to Do


After completing this unit, you should be able to:
• Describe the structure of the filesystem
• Mount and unmount CD-ROMs and floppy disks

How You Will Check Your Progress


Accountability:
• Checkpoint questions
• Machine exercises

© Copyright IBM Corp. 2001, 2003 Unit 7. A Tour through Linux 7-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
'HVFULEHWKHVWUXFWXUHRIWKHILOHV\VWHP
0RXQWDQGXQPRXQW&'520VDQGIORSS\GLVNV

Figure 7-1. Objectives LX023.0

Notes:

7-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
'LUHFWRU\6WUXFWXUH

$OO/LQX[GLUHFWRULHVDUHFRQWDLQHGLQRQHYLUWXDOXQLILHG
ILOHV\VWHP
3K\VLFDOGHYLFHVDUHPRXQWHGRQPRXQWSRLQWV
)ORSS\GLVNV
+DUGGLVNSDUWLWLRQV
&'520GULYHV
1RGULYHOHWWHUVOLNH$&

ELQ GHY KRPH PQW URRW WPS YDU 


ERRW HWF OLE SURF VELQ XVU ORVWIRXQG

Figure 7-2. Directory Structure LX023.0

Notes:
All Linux directories and files are contained in one virtual “unified filesystem”. This means
that all physical devices with filesystems on them (floppy disks, hard disk partitions,
CD-ROM drives) are all combined into one giant tree structure. Among other things, this
means that Linux does not use “drive letters”, such as A:, C:, and so forth.
For the layout of this unified filesystem, most Linux distributions closely follow the Linux File
System Hierarchy Standard, a collaborative document that defines the names and
locations of many files and directories. The standard can be viewed at
http://www.pathname.com/fhs
The standard closely follows the conventional UNIX filesystem, with some minor
modifications. In the next few graphics we will view the contents of the various directories.

© Copyright IBM Corp. 2001, 2003 Unit 7. A Tour through Linux 7-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

ELQOLEVELQ


ELQ GHY KRPH PQW URRW WPS YDU 


ERRW HWF OLE SURF VELQ XVU ORVWIRXQG
ELQFRQWDLQVH[HFXWDEOHVIRUHYHU\XVHU
VELQFRQWDLQVV\VWHPDGPLQLVWUDWLRQH[HFXWDEOHV
OLEFRQWDLQVOLEUDULHV
6KRXOGDOZD\VEHDYDLODEOH
$WV\VWHPERRW
,QVLQJOHXVHUPRGH
:KHQERRWLQJIURPUHVFXHGLVN
&DQQRWEHLQVHSDUDWHILOHV\VWHPV
Figure 7-3. /bin, /lib, and /sbin LX023.0

Notes:
/bin, /lib and /sbin contain executables and libraries which always need to be available,
even in the worst of scenarios, because these tools are essential for system maintenance
and recovery.
The difference between /bin and /sbin is in the people who will use them: /bin is for
everybody, and /sbin are typically tools only needed by the system administrators.
Therefore you will not find /sbin in the search path ($PATH) of a normal user, but you will in
the path of a system administrator.
Libraries are shared parts of code, which is available to every program that may want to
use the code. Since different programs use the same routines for, for instance, writing to
the screen, it saves disk space to put these routines into one central library, instead of into
every individual program.
These three directories can not be on a separate filesystem, but must reside in the root
filesystem.

7-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
ERRW


ELQ GHY KRPH PQW URRW WPS YDU 


ERRW HWF OLE SURF VELQ XVU ORVWIRXQG

&RQWDLQVNHUQHOLPDJHDQGVRPHRWKHUJRRGLHV
6KRXOGEHORFDWHGEHORZF\OLQGHUDQGRU*%
*RRGKDELWWRDOZD\VPDNHLWDVHSDUDWHILOHV\VWHP

Figure 7-4. /boot LX023.0

Notes:
The /boot directory contains the kernel images, some other things related to these images
and the files needed for the bootloader (LILO or GRUB). All these things are located in a
separate directory in order to be able to put it on a separate filesystem.
The reason for this is a technical limitation in the BIOS standard: The BIOS standard
specifies various system calls that can be used to read data from disk. All these system
calls are limited to 1023 cylinders or, when Linear Block Addressing (LBA) is used, 8
gigabytes.
Linux itself, once booted, bypasses the BIOS completely and uses its own routines for
accessing the disk. LILO and GRUB, the programs that loads the kernel into memory, use
the BIOS however and is therefore limited to 1023 cylinders or 8 gigabyte of disk space
which it can access.
It is therefore vitally important to have everything that is required to boot the operating
system below this limit. This is done by placing these things in a separate directory in the
filesystem tree, and placing this directory on a separate filesystem which itself is located

© Copyright IBM Corp. 2001, 2003 Unit 7. A Tour through Linux 7-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

entirely below cylinder 1023 or 8 GB. This filesystem usually requires only a few
megabytes, so creating such a partition shouldn't be a problem.
BIOS manufacturers have noted this problem and have created proprietary extensions to
their own BIOS which allow operating systems to access data above 1024 cylinders or 8
gigabytes to be used through the BIOS. These extensions are not standard however, and
LILO and GRUB do not (yet) know how to use the extensions of every BIOS manufacturer
- if the extensions are present at all. That means that in some cases you are lucky and are
able to put /boot somewhere at the end of the disk, or dispense with a separate /boot
partition altogether, and in some cases you are not. This can usually only be determined by
trial and error. This is usually not worth the risk, leading to a very simple rule-of-the-thumb:
if your disk is larger than 1023 cylinders or if your disk is larger than 8 gigabytes, create a
separate /boot filesystem.

7-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
GHY


ELQ GHY KRPH PQW URRW WPS YDU 


ERRW HWF OLE SURF VELQ XVU ORVWIRXQG
&RQWDLQVVSHFLDOILOHVWKDWUHSUHVHQWKDUGZDUHGHYLFHV
%ORFNVSHFLDOGHYLFHIRUH[DPSOHDKDUGGLVN
&KDUDFWHUVSHFLDOGHYLFHIRUH[DPSOHPRXVHDQG
NH\ERDUG
(DFKGHYLFHKDVDPDMRUDQGPLQRUQXPEHU
,GHQWLILFDWLRQZLWKLQWKHNHUQHO
&DQQRWEHDVHSDUDWHILOHV\VWHP

Figure 7-5. /dev LX023.0

Notes:
The /dev directory contains special files that represent the hardware of your system. By
writing to these devices and/or reading from it, one can usually (but not always) interact
almost directly with the hardware. Note, however, that this generally is not a particularly
safe thing to do. Access to these devices is therefore usually restricted to root.
There are two types of special files in the /dev directory1:
• Character special devices (permissions start with c). These devices can be read from
and written to sequentially. Examples: tty (terminals), mouse, null (the bit bucket), zero
(a null-character generator), random (a random number generator).
• Block special devices (permissions start with b). These devices can be read from and
written to with random access. Examples: floppy and hard disks, memory.
Block and character special devices have a major and a minor number which is used for
identifying the device within the kernel.

1 Note that two other types of special files exist too: Named Pipes and UNIX Sockets. These are generally not located in /dev, but in /tmp

or /var, since they are created on-the-fly by the programs that use them.

© Copyright IBM Corp. 2001, 2003 Unit 7. A Tour through Linux 7-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Block and character special devices can be created with the mknod command (see the
manual page for mknod).
There are several devices on a system which are created dynamically, while the system is
running. The most common example is a so-called pty, a program terminal, which is the
logical hardware device which represents the virtual terminal a networked user uses to
login to the system. (A user logging in on the console uses a tty, a user logging in over the
network uses a pty.) The number of users logging in over the network is usually not known
beforehand. That's why these devices are created on-the-fly when a user logs in. They are
therefore not stored in /dev but in a separate directory, /dev/pts. The Linux kernel is usually
configured not to create more than 256 different ptys, but this option can be changed
during the kernel compile.

7-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
HWF


ELQ GHY KRPH PQW URRW WPS YDU 


ERRW HWF OLE SURF VELQ XVU ORVWIRXQG

&RQWDLQVV\VWHPZLGHFRQILJXUDWLRQILOHV
6RPHVXEV\VWHPVKDYHPXOWLSOHILOHVDQGWKHUHIRUHXVHD
VHSDUDWHGLUHFWRU\
HWF;FRQWDLQV;:LQGRZ6\VWHPFRQILJXUDWLRQ
HWFVNHOFRQWDLQVGHIDXOWXVHUFRQILJXUDWLRQILOHV
HWFV\VFRQILJFRQWDLQVV\VWHPFRQILJXUDWLRQ
&DQQRWEHDVHSDUDWHILOHV\VWHP

Figure 7-6. /etc LX023.0

Notes:
/etc contains the system-wide configuration files. These files apply to each and every
program that is running, and each and every user.
Some programs or subsystems create their own subdirectory in /etc, since they have more
than just a few configuration files, and want to keep these files together. As an example:
• /etc/X11 contains configuration files specifically for the X Window System.
• /etc/skel contains default user configuration files. The contents of /etc/skel are copied to
the user's home directory when that user and his home directory are created.
• /etc/sysconfig contains distribution-specific system configuration files.

© Copyright IBM Corp. 2001, 2003 Unit 7. A Tour through Linux 7-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

KRPH


ELQ GHY KRPH PQW URRW WPS YDU 


ERRW HWF OLE SURF VELQ XVU ORVWIRXQG

IUHG ELOO MDQH

+RPHGLUHFWRULHVRIXVHUV
&DQEHDVHSDUDWHILOHV\VWHP

Figure 7-7. /home LX023.0

Notes:
/home contains the home directories of the users. Within home, each user has its own
directory, identified by the username. For instance, /home/bill. On a system with a lot of
active users, /home is usually put on a separate filesystem.

7-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
PQW


ELQ GHY KRPH PQW URRW WPS YDU 


ERRW HWF OLE SURF VELQ XVU ORVWIRXQG

IORSS\ FGURP ZLQ

0RXQWSRLQWVIRURWKHUILOHV\VWHPV
&DQEHDVHSDUDWHILOHV\VWHP
1RWH6X6(XVHVPHGLDLQVWHDGRIPQWIRUIORSS\DQG
FGURPPRXQWSRLQWV

Figure 7-8. /mnt LX023.0

Notes:
/mnt is usually used as a placeholder for all the mount points you will need for mounting
non-standard filesystems. For example:
• /mnt/floppy for a floppy drive
• /mnt/cdrom for your cd-rom drive
• /mnt/win95 for a Windows 95 partition
• /mnt/os2 for an OS/2 partition and so on.
SuSE uses the /media directory as a placeholder for the mountpoints for various media:
/media/cdrom, /media/floppy and so forth.

© Copyright IBM Corp. 2001, 2003 Unit 7. A Tour through Linux 7-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

SURF


ELQ GHY KRPH PQW URRW WPS YDU 


ERRW HWF OLE SURF VELQ XVU ORVWIRXQG

9LUWXDOILOHV\VWHP
5HSUHVHQWVNHUQHODQGSURFHVVLQIRUPDWLRQ

Figure 7-9. /proc LX023.0

Notes:
/proc is a virtual filesystem which exists only in the imagination of the kernel. It is used for
accessing the kernel's data structures, for instance, the interrupts, ioports and so on, and
for accessing process information. For instance:
• /proc/interrupts contains all the interrupts (IRQs) the kernel knows of
• /proc/dma contains all the DMA (Direct Memory Access) channels
• /proc/ioports contains all the configured I/O (Input/Output) ports
• /proc/net/sockstat contains statistical information about network sockets
• /proc/1/environ contains the environment of process 1
• /proc/self/cwd contains the current working directory of the process that tried to access
this file

7-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
URRW


ELQ GHY KRPH PQW URRW WPS YDU 


ERRW HWF OLE SURF VELQ XVU ORVWIRXQG

+RPHGLUHFWRU\RIWKHURRWXVHU
6KRXOGQRWEHDVHSDUDWHILOHV\VWHP

Figure 7-10. /root LX023.0

Notes:
/root is the home directory of the root user. It should not be a separate filesystem: If there
was a problem in mounting this filesystem, then root would not be able to login and fix it...

© Copyright IBM Corp. 2001, 2003 Unit 7. A Tour through Linux 7-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

WPS


ELQ GHY KRPH PQW URRW WPS YDU 


ERRW HWF OLE SURF VELQ XVU ORVWIRXQG

7HPSRUDU\VWRUDJHVSDFHIRUSURJUDPVXVHUV
&DQEHDVHSDUDWHILOHV\VWHP
6RPHWLPHVDXWRPDWLFFOHDQXSPHFKDQLVPDFWLYH

Figure 7-11. /tmp LX023.0

Notes:
/tmp is used as a temporary storage space for programs and users. Temporary in this
context means a couple of minutes, hours at most, instead of days and weeks.
Some system administrators have automatic cleanup jobs running every night that clean
/tmp of files older than a few days.

7-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
XVU


ELQ GHY KRPH PQW URRW WPS YDU 


ERRW HWF OLE SURF VELQ XVU ORVWIRXQG

81,;6\VWHP5HVRXUFHV ELQ OLE VELQ

&RQWDLQVDOOSURJUDPVOLEUDULHVDQGVRRQZKLFKDUHQRW
HVVHQWLDOIRUV\VWHPERRWDQGHPHUJHQF\RSHUDWLRQV
&DQEHDVHSDUDWHILOHV\VWHP
&DQEHPRXQWHGRYHU1)6
&DQEHUHDGRQO\
XVUORFDOLQWHQGHGIRUSURJUDPVQRWLQWKHGLVWULEXWLRQ
0D\EHDVHSDUDWHILOHV\VWHPWRR
Figure 7-12. /usr LX023.0

Notes:
/usr is by far the largest filesystem on a freshly installed Linux system. It contains all the
programs that need to be available on the system, but need not be available at boot time or
in an emergency. Therefore, this filesystem can be mounted remotely, over a network,
using NFS. This is frequently done to save disk space on workstations: all the workstations
then mount /usr from a central server. Furthermore, this filesystem may be a read-only
filesystem, greatly reducing security threats.
Some important subdirectories of /usr are:
• /usr/bin, /usr/sbin, /usr/lib - The equivalents of /bin, /sbin and /lib.
• /usr/dict - Contains dictionary files
• /usr/doc - Documentation
• /usr/etc - Network-wide configuration files, if /usr is mounted over NFS
• /usr/games - Your favorite place
• /usr/info, /usr/man - Info and manual pages for commands

© Copyright IBM Corp. 2001, 2003 Unit 7. A Tour through Linux 7-15
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

• /usr/src - Sources
• /usr/local - Intended for programs that are not included in the distribution. These
programs may come from another source, or be developed locally.
The advantage of doing this in /usr/local is that this directory is never overwritten by a
distributions upgrade. So even if a new program was installed with the same name as
your own program, your program will still exist. You only need to figure out the correct
$PATH settings afterwards.
If you will be using /usr/local to create local programs, it is a good idea to make this a
separate filesystem. This will make it easier to make backups of your local programs,
and makes it safer to do upgrades.

7-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
YDU


ELQ GHY KRPH PQW URRW WPS YDU 


ERRW HWF OLE SURF VELQ XVU ORVWIRXQG
)LOHVRIYDULDEOHVL]H
ORJILOHV WPS VSRRO ORJ
ORFNILOHV
'LUHFWRULHVZLWKYDULDEOHFRQWHQW
PDLO
VFKHGXOLQJ
SULQWLQJ
7HPSRUDU\VWRUDJHVSDFHORQJHUWKDQWPS
&DQEHDVHSDUDWHILOHV\VWHP
Figure 7-13. /var LX023.0

Notes:
/var holds files that may vary greatly in size. Typical examples of these files include logfiles,
usually stored in /var/log. But other applications also generate files of which the size or
contents vary greatly. These are then also stored somewhere in /var.
/var/tmp is sometimes also used as temporary storage space, just like /tmp, but with a
longer retention period (weeks or more).
/var/spool contains spool files. Spool files are created when a program has a piece of data
which it cannot process right now. Examples include email messages (in
/var/spool/mqueue) and print files (in /var/spool/lpd).
/var/run contains information about processes that are running, such as process ID
numbers.
/var/lock contains lockfiles: files that with their existence signal that a certain resource is
locked or a certain program is running and that a second instance of that program is not
allowed.

© Copyright IBM Corp. 2001, 2003 Unit 7. A Tour through Linux 7-17
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

ORVWIRXQG


ELQ GHY KRPH PQW URRW WPS YDU 


ERRW HWF OLE SURF VELQ XVU ORVWIRXQG

([LVWVLQHYHU\ILOHV\VWHP
3ODFHZKHUHORVWIRXQGILOHVDUHVWRUHGDIWHUDFUDVK
UHFRYHU\E\IVFN

Figure 7-14. /lost+found LX023.0

Notes:
Every filesystem has a lost+found directory, which is created when you create the
filesystem. It is normally empty. However, should a system crash occur when the filesystem
is not in a stable state, then fsck (filesystem-check) will check the filesystem and place any
files it found not to have a name in lost+found. The system administrator will then have to
decide who that file belonged to and find a way to "give it back" to the rightful owner.

7-18 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
2WKHU'LUHFWRULHVLQ


ELQ GHY KRPH PQW URRW WPS YDU 


ERRW HWF OLE SURF VELQ XVU ORVWIRXQG

RSWXVHGIRUVRPHVRIWZDUHIURPH[WHUQDOSURYLGHUV
6HSDUDWHILOHV\VWHPDGYLVDEOH
:KDWHYHU\RXFUHDWH\RXUVHOI

Figure 7-15. Other Directories in / LX023.0

Notes:
Various other directories may be present in the root of your filesystem. It is of course up to
you to decide which directories to create and what to store in them.
One directory is a good idea to create though: the /opt directory. Sometimes commercial
software for Linux installs itself in this directory. You may even want to make this a separate
filesystem.
On a SuSE system, subsystems like GNOME, KDE and OpenOffice are installed in /opt.

© Copyright IBM Corp. 2001, 2003 Unit 7. A Tour through Linux 7-19
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHPRXQW&RPPDQG

7KHPRXQWFRPPDQGPRXQWVDILOHV\VWHP
0DNHVLWSDUWRIWKHXQLILHGILOHV\VWHPVWUXFWXUH
PRXQW>WW\SH@>RRSWV@GHYLFHPRXQWSQW

PRXQWWYIDWGHYIGPQWIORSS\
PRXQWWLVRRURGHYKGFPQWFGURP


XVUYDUWPS


ELQOLE;5
Figure 7-16. The mount Commands LX023.0

Notes:
The mount command is used to "mount" a filesystem on a "mountpoint". It can best be
compared to attaching a branch to a tree. After a filesystem (a disk partition, a CD-ROM
device or a floppy disk, for instance) has been mounted, it has become part of the unified
filesystem and can be accessed.
The syntax of the mount command is:
mount [-t type] [-o options] device mountpoint
The type specifies the filesystem type, for example ext2, vfat or iso9660. The options may
indicate read-only, for instance. The device identifies the device name which contains the
filesystem to be mounted. The mountpoint identifies the (empty) directory where the
filesystem should be mounted.
As an example, suppose you have a floppy disk which was formatted by Windows 95, and
contains a file called myfile.txt. To access this file, you first insert the floppy in the disk
drive, and then execute the command
mount -t vfat /dev/fd0 /mnt/floppy

7-20 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty The file on the floppy disk is now accessible as /mnt/floppy/myfile.txt.


The same goes for CD-ROM drives. The only difference is that CD-ROM is a read-only
media, so you need to mount the CD with the "ro" option, which stands for "read-only".

© Copyright IBM Corp. 2001, 2003 Unit 7. A Tour through Linux 7-21
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHXPRXQW&RPPDQG

7KHXPRXQWFRPPDQGXQPRXQWVDILOHV\VWHP
7DNHVLWRXWRIWKHXQLILHGILOHV\VWHPVWUXFWXUH
)LOHV\VWHPVKRXOGQRWEHEXV\
$OZD\VXQPRXQWDIORSS\RU&'EHIRUHHMHFWLQJLW

XPRXQW^GHYLFH_PRXQWSQW`

XPRXQWGHYIG
XPRXQWPQWIORSS\
XPRXQWGHYKGF
XPRXQWPQWFGURP

Figure 7-17. The umount Command LX023.0

Notes:
Unmounting a filesystem is done with the umount command. This command only needs
one argument, which is either the device name or the mount point of the filesystem to be
unmounted. Unmounting a filesystem can only be done if the filesystem is no longer in use.
A filesystem is in use when one of the three conditions below is true:
• A user currently has a file opened on the filesystem.
• A user is currently running a program from that filesystem.
• A user uses a directory on that filesystem as its current working directory.
Always umount a filesystem, in particular a floppy disk, before ejecting it. (Most CD-ROM
players have a software eject which is disabled by the kernel while the CD is mounted, but
floppy drives typically have a hardware eject which can’t be disabled.)

7-22 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KHHWFIVWDE)LOH

HWFIVWDEOLVWVDOONQRZQILOHV\VWHPVRQWKHV\VWHP
6\QWD[
GHYLFHPRXQWSRLQWW\SHRSWLRQVGXPSIVFN
)LOHV\VWHPVZLWKWKHQRDXWRRSWLRQDUHQRWPRXQWHG
DXWRPDWLFDOO\EXWFDQEHXVHGDVWHPSODWHVIRUPRXQW

FDWHWFIVWDE
GHYKGDPQWZLQYIDWGHIDXOWV
GHYKGDERRWH[WGHIDXOWV
GHYKGDH[WGHIDXOWV
GHYKGDVZDSVZDSGHIDXOWV
GHYKGFPQWFGURPLVRQRDXWRRZQHUUR
GHYIGPQWIORSS\DXWRQRDXWRRZQHU
QRQHSURFSURFGHIDXOWV
QRQHGHYSWVGHYSWVJLG PRGH 

Figure 7-18. The /etc/fstab File LX023.0

Notes:
The /etc/fstab file lists all known filesystems on the system. On a large server, this might
add up to dozens of filesystems, each with their own mountpoint and special options. We're
not going to cover the file in great depth, but you need to be aware of it at least.
The file lists every filesystem known to the system on a single line, where each line
consists of six columns:
• The first column identifies the device name2.
• The second column identifies the mount point.
• The third column identifies the filesystem type. A very useful type which can be used
here is auto, which forces the system to autodetect the type of filesystem on the device.
This is especially useful for floppy disks.
2
Red Hat and some other distributions use a modified mount command which also allows you to specify the label of an ext2/ext3
filesystem here. When such a label is encountered here, all ext2/ext3 filesystems on all disks are searched for a filesystem with that
particular label. That filesystem is then mounted at the mountpoint specified.
The advantage of this is that you don't have to change your /etc/fstab file after adding or removing disks and/or partitions.
An /etc/fstab line which uses the labels instead of device names will look like this:
LABEL=/ / ext3 defaults 1 1

© Copyright IBM Corp. 2001, 2003 Unit 7. A Tour through Linux 7-23
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

• The fourth column identifies the options.


• The fifth column is a parameter for the dump program.
• The sixth column is a parameter for the fsck program.
All filesystems listed in this file will be mounted automatically at the corresponding
mountpoint when the system boots, except for the filesystems which have the noauto
option. As you can see in the visual, this applies to /mnt/cdrom and /mnt/floppy3.
The noauto entries are nevertheless useful in this file, since the mount command uses
this file to complete the information about a filesystem if only a partial mount command is
given. And that's the important thing about this visual: When the floppy disk and the
CD-ROM entries are configured as above, the only command needed to mount a floppy
disk is:
mount /mnt/floppy
which will be expanded by the mount command to
mount -t auto -o owner /dev/fd0 /mnt/floppy
based on the information in the /etc/fstab file. And the same goes for the command to
mount a CD (mount /dev/cdrom).
The owner option by the way allows a regular user to perform the mount command. When
this option is set, you don't need to be root on the system to mount that particular device at
that particular mountpoint.
When you are using a graphical desktop environment such as KDE or GNOME, your
distribution may actually have made things even simpler than this: Some distributions come
with a floppy disk and CD-ROM button on the desktop which executes the mount and
umount command automatically when you click on it.

3
As mentioned before, SuSE uses /media/floppy and /media/cdrom instead of /mnt/floppy and /mnt/cdrom.

7-24 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&KHFNSRLQW

7)/LQX[XVHVGULYHOHWWHUV $%&DQGVRIRUWK 
MXVWOLNH:LQGRZV

7KHEHVWORFDWLRQIRUWKHPRXQWFRPPDQGZRXOGEH
DHWF
EELQ
FVELQ
GXVUVELQ

:KHUHDUHPRVWV\VWHPZLGHFRQILJXUDWLRQILOHV
VWRUHG"

Figure 7-19. Checkpoint LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 7. A Tour through Linux 7-25
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

6XPPDU\

6WUXFWXUHRIWKHILOHV\VWHP
ELQOLEVELQ
ERRW
HWF
KRPHURRW
WPS
XVU
YDU
6SHFLDOILOHV\VWHPV
SURF
PQW
6SHFLDOILOHV
GHY

Figure 7-20. Unit Summary LX023.0

Notes:

7-26 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 8. Editing Files

What This Unit Is About


This unit discusses the way various files can be edited, and covers vi,
the most common editor found on any UNIX system.

What You Should Be Able to Do


After completing this unit, you should be able to:
• Determine the type of file using file
• Edit text files with vi
• Discuss other text file editors such as kedit
• Discuss the ways non-text files can be edited

How You Will Check Your Progress


Accountability:
• Checkpoint questions
• Machine exercises

© Copyright IBM Corp. 2001, 2003 Unit 8. Editing Files 8-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
'HWHUPLQHWKHW\SHRIILOHXVLQJILOH
(GLWWH[WILOHVZLWKYL
'LVFXVVRWKHUWH[WILOHHGLWRUVVXFKDVNHGLW
'LVFXVVWKHZD\VQRQWH[WILOHVFDQEHHGLWHG

Figure 8-1. Objectives LX023.0

Notes:

8-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
(GLWLQJ)LOHV

8VHILOHFRPPDQGWRGHWHUPLQHWKHFRQWHQWRIDILOH

ILOHHWFSDVVZG
HWFSDVVZG$6&,,WH[W
ILOHXVUELQSDVVZG
XVUELQSDVVZG(/)ELW/6%H[HFXWDEOH

7RHGLWWH[WILOHVXVHDQHGLWRU
1RQWH[WILOHVFDQRQO\EHFKDQJHGXVLQJWKHDSSOLFDWLRQ
WKDWFUHDWHGWKHPRUZLWKDKH[HGLWRU
%XWPRVWFRQILJXUDWLRQILOHVXQGHU/LQX[DUHWH[WILOHV

Figure 8-2. Editing Files LX023.0

Notes:
When we are editing a file, we are changing the content of the file. For this, we need an
editor.
Since Linux does not impose any structure on the contents of the file, there is no editor
under Linux which can edit any file available. Different files need to be edited using different
editors.
To determine the file type, the file program is used. This program reads the first few bytes
of the file and compares it to a database of known file types. If there is a match, then the
type of the file is displayed.
If the file turns out to be a text file, then you can edit this file with a text editor. On a typical
Linux system, there's usually a large assortment of text editors available, including vi,
kedit, emacs and so forth. Non-text files usually need to be edited through the application
that created them, or with a so-called "hex-editor", an editor which displays the file in
hexadecimal format and thus is able to display and modify non-printable characters.

© Copyright IBM Corp. 2001, 2003 Unit 8. Editing Files 8-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Most configuration files on a Linux system are text files. This makes it possible to perform
most system administration tasks with just a simple text editor.

8-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KHYLWH[WHGLWRU

'HIDXOWHGLWRULQDOO81,;RSHUDWLQJV\VWHPV
8VXDOO\WKHRQO\HGLWRUDYDLODEOHLQHPHUJHQFLHV
5HODWLYHO\KDUGWROHDUQEXWUHDOO\SRZHUIXO
$VD/LQX[XVHU\RXVKRXOGEHDEOHWRXVHYLIRUEDVLF
HGLWLQJWDVNV
%XWLW
V2.LI\RXSUHIHUDQRWKHUHGLWRUIRUGDLO\ZRUN
YLLQ/LQX[LVXVXDOO\YLP YLLPSURYHG 
6\QWD[KLJKOLJKWLQJ
$UURZNH\V'HO%6ZRUNLQLQVHUWPRGH
0XOWLOHYHOXQGR
0RXVHVXSSRUW

Figure 8-3. The "vi" text editor LX023.0

Notes:
vi, which officially stands for "visual interpreter", is the most commonly available editor in all
UNIX operating systems. The reason for this is that it was the first, and for a long time only
editor which was capable of editing a file in full-screen mode. Before vi, all editors were
line-based: they could only display and edit one line at a time.
Considering today’s standards, vi is relatively hard to learn. Editors like kedit for example
have a graphical interface and are therefore much easier to use for novices. But if you need
to do system management on a remote system, connected via a slow network or modem
connection, kedit is not an option.
The same goes for emergency situations. When a system crashes and won't boot in the
normal fashion anymore, you need to fall back to some sort of rescue mode. This rescue
mode is usually started from CD-ROM or over the network, and makes only the minimum
amount of tools available to get the system up and running again. In such a rescue mode,
the only editor available is usually vi.

© Copyright IBM Corp. 2001, 2003 Unit 8. Editing Files 8-5


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

The last reason for learning vi is that certain programs (such as mail and news readers)
use an external editor if the user needs to type more than a few words (the body of your
email message for instance). In all but a few cases, the external editor called is vi.
So it is important to learn vi, at least enough to make simple changes to text files. That
doesn't mean that vi has to be your preferred editor, and that you need to learn all features.
If that's what you want, that's fine. But if you prefer kedit or emacs (to name two ends of
the spectrum) for your daily work, that's fine too.
When executing the vi command in Linux, in most distributions, the program actually
started is vim - VI Improved. vim is downwards compatible with vi, but offers a large
number of advantages and improvements over traditional vi. The visual lists some of them.
For a complete list, start vi(m) and execute the command :help vi_diff.txt

8-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
YL0RGHV

YLNQRZVWKUHHPRGHVRIRSHUDWLRQ
&RPPDQGPRGH IRUVLPSOHRQHOHWWHUFRPPDQGV
(GLWPRGH LQVHUWWH[W
H[PRGH IRUFRPSOLFDWHGFRPPDQGV
&DQHDVLO\FKDQJHEHWZHHQPRGHV
&RPPDQGPRGH (GLWPRGH

$OORZV\RXWRW\SHVLPSOH
$OORZV\RXWRLQVHUWWH[W
RQHOHWWHUFRPPDQGV

H[PRGH

$OORZV\RXWRH[HFXWH
FRPSOH[FRPPDQGV

Figure 8-4. vi Modes LX023.0

Notes:
The apparent complexity of vi is largely due to the concept of different modes that vi uses,
and that you constantly need to change between them.
The first mode that you need to know about is the command mode. When vi is in this
mode, you can type simple, one-letter commands that do specific things. There are as
many commands as there are letters in the alphabet, where the lowercase and uppercase
letter (and sometimes the control-sequence too) have a different meaning.
The second mode is the edit mode. This mode allows you to enter characters that show up
in the file.
The third mode is the ex mode. The "ex" line editor was the direct predecessor of vi. It was
really powerful, but did not have full-screen capabilities. Most of the powerful ex commands
have been integrated in vi, as the ex mode.

© Copyright IBM Corp. 2001, 2003 Unit 8. Editing Files 8-7


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

6WDUWLQJYL
YLP\ILOHW[W

a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
P\ILOHW[W>1HZ)LOH@  $OO

Figure 8-5. Starting vi LX023.0

Notes:
vi does editing in a buffer. When a session is initiated, one of two things happen:
• if the file to be edited exists, a copy of the file is put into a buffer in /tmp by default.
• if the file does not exist, an empty buffer is opened for this session.
Tildes represent empty lines that are not part of the file you are editing.
The editor starts in command mode.

8-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&XUVRU0RYHPHQWLQ&RPPDQG0RGH

N
XSDUURZ!
*
K O
OHIWDUURZ! ULJKWDUURZ!
A 
M
GRZQDUURZ!
*

Figure 8-6. Cursor Movement in Command Mode LX023.0

Notes:
To move about in your file make sure you are in command mode.
<left arrow> or h one character left
<right arrow> or l one character right
^ move to beginning of line
$ move to end of line
<up-arrow> or k one line up
<down-arrow> or j one line down
1G go to the first line
G go to the last line
Pay attention to the uppercase commands!

© Copyright IBM Corp. 2001, 2003 Unit 8. Editing Files 8-9


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

(GLWLQJ7H[WLQ&RPPDQG0RGH

7RGHOHWHDVLQJOHFKDUDFWHU XQGHUFXUVRU [
7RGHOHWHDVLQJOHFKDUDFWHUOHIWRIFXUVRU ;
7RUHSODFHDVLQJOHFKDUDFWHU U
8QGRWKHODVWFKDQJH X
7RUHSHDWODVWFRPPDQG 

FRPPDQGPRGH

Figure 8-7. Editing Text in Command Mode LX023.0

Notes:
To execute one of the illustrated commands, you must be in command mode.
There are several different ways to perform the delete functions.

8-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
6ZLWFKLQJWR(GLW0RGH

7RLQVHUWWH[WDWEHJLQRIOLQH ,
7RLQVHUWWH[WEHIRUHFXUVRU L
7RDSSHQGWH[WDIWHUFXUVRU D
7RDSSHQGWH[WDWHQGRIOLQH $
7RJREDFNWRFRPPDQGPRGH (6&!

,L$D
&RPPDQGPRGH (GLWPRGH

(6&

Figure 8-8. Switching to Edit Mode LX023.0

Notes:
There are a number of ways to get from command mode to edit mode:
I (Capital i) Insert text at beginning of current line.
i Insert text before current cursor position.
a Append text after current cursor position.
A Append text at end of line.
To exit the edit mode, press the Escape key.

© Copyright IBM Corp. 2001, 2003 Unit 8. Editing Files 8-11


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

$GGLQJ7H[WLQ(GLW0RGH

7KLVILOHFRQWDLQVVRPHOLQHV
/LQH
$QGWKLVLVOLQH
/LQHIROORZVOLQH
7KHODVWOLQHLVOLQH
a
a
a
a
a
,16(57  $OO

.H\VWURNHLVZLWFKHVYLWRHGLWPRGH1HZFKDUDFWHUV
FDQEHLQVHUWHGDWWKHFXUUHQWSRVLWLRQRIWKHFXUVRU

Figure 8-9. Adding Text in Edit Mode LX023.0

Notes:
After starting vi, you are in the command mode. If you want to type some text, you have to
change to the edit mode of vi.
To enter edit mode, enter the i command. This will place you in edit mode. Look at the last
line in vi because it should state now that you are in edit mode (it shows “-- INSERT --”).
To exit from input mode, press the <esc> key. The bottom line should no longer show
“-- INSERT --”.

8-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
([LWLQJWKH(GLW0RGH

7KLVILOHFRQWDLQVVRPHOLQHV
/LQH
$QGWKLVIRUH[DPSOHLVOLQH
/LQHIROORZVOLQH
7KHODVWOLQHLVOLQH
a
a
a
a
a
a
  $OO

.H\VWURNH(6&OHDYHVWKHHGLWPRGH

Figure 8-10. Exiting the Edit Mode LX023.0

Notes:
To leave the edit mode, use the Escape key.

© Copyright IBM Corp. 2001, 2003 Unit 8. Editing Files 8-13


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

6HDUFKLQJIRU3DWWHUQV

7RVHDUFKIRUDSDWWHUQ LQFRPPDQGPRGH  SDWWHUQ!


7RUHSHDWWKHSUHYLRXVVHDUFK Q

7KLVILOHFRQWDLQVVRPHOLQHV
/LQH
$QGWKDWIRUH[DPSOHLVOLQH
/LQHIROORZVOLQH
7KHODVWOLQHLVOLQH
a
a
a
a
a
a
OLQH

Figure 8-11. Searching for Patterns LX023.0

Notes:
vi can also search for patterns. This is done with the / (slash) command. To repeat a
previous search, use the n command.

8-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
5HSODFLQJ3DWWHUQV

$GYDQFHGVHDUFKDQGUHSODFHFDQEHGRQHLQH[PRGH
7RUHSODFHROGZLWKQHZ VROGQHZJ

7KLVILOHFRQWDLQVVRPHOLQHV
/LQH
$QGWKDWIRUH[DPSOHLVOLQH
/LQHIROORZVOLQH
7KHODVWOLQHLVOLQH
a
a
a
a
a
a
VWKLVWKDWJ

Figure 8-12. Replacing Patterns LX023.0

Notes:
Advanced search and replace functions are available in ex mode. The command
:%s /old/new/g for instance replaces all occurrences of the word "old" with "new"..

© Copyright IBM Corp. 2001, 2003 Unit 8. Editing Files 8-15


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&XW&RS\DQG3DVWH

7RFXWDZKROHOLQHLQWREXIIHU GG
7RFRS\DZKROHOLQHLQWREXIIHU \\
7RFXWDZRUGIURPWKHFXUUHQWFXUVRU
SRVLWLRQWRLWVHQG GZ
7RSDVWHFRQWHQWVRIEXIIHUVKHUH S
7RFXWFRS\PXOWLSOHOLQHVSUHFHHGFRPPDQGE\
QXPEHUGG\\

Figure 8-13. Cut, Copy and Paste LX023.0

Notes:
The dd and yy commands allow you to cut and copy a single line into a buffer. The p
command then retrieves the buffer contents and adds it after the current line.
To cut or copy multiple lines at once, precede the command by the number of lines you will
want to cut or copy.

8-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&XWDQG3DVWH

7KLVILOHFRQWDLQVVRPHOLQHV
/LQH
$QGWKDWIRUH[DPSOHLVOLQH
/LQHIROORZVOLQH
7KHODVWOLQHLVOLQH

FXWOLQHE\SUHVVLQJGG
7KLVILOHFRQWDLQVVRPHOLQHV
/LQH
/LQHIROORZVOLQH
7KHODVWOLQHLVOLQH
$QGWKDWIRUH[DPSOHLVOLQH

DQGLQVHUWLWDIWHUOLQHE\SUHVVLQJS
Figure 8-14. Cut and Paste LX023.0

Notes:
The dd and the p commands are used to move (a number of) lines. Use the proper keys
(that is, h, j, k or l) to go to the line you want to move. Now give the dd command. This will
remove the line you were in and place it in a buffer.
Use the move keys again to go to the place where you want the line to reappear. Press the
p command if you want the line to reappear under the line where the cursor is in. Use the
P command if you want the line to reappear above the line the cursor is in.
You can also delete a couple of lines with the dd command. To delete 12 lines, enter 12dd.
The u command will UNDO your last command if you make an error. So, if you delete
something in error, immediately type the u command to retrieve it.

© Copyright IBM Corp. 2001, 2003 Unit 8. Editing Files 8-17


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&RS\DQG3DVWH

7KLVILOHFRQWDLQVVRPHOLQHV
/LQH
$QGWKDWIRUH[DPSOHLVOLQH
/LQHIROORZVOLQH
7KHODVWOLQHLVOLQH

FRS\OLQHE\SUHVVLQJ\\
7KLVILOHFRQWDLQVVRPHOLQHV
/LQH
$QGWKDWIRUH[DPSOHLVOLQH
/LQHIROORZVOLQH
7KHODVWOLQHLVOLQH
$QGWKDWIRUH[DPSOHLVOLQH

DQGLQVHUWLWDIWHUOLQHE\SUHVVLQJS
Figure 8-15. Copy and Paste LX023.0

Notes:
To copy and paste text, you can use the same steps you used with cut and paste. The only
difference is the yy command instead of the dd command.

8-18 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
YL2SWLRQV

2SWLRQVHQWHUHGLQH[PRGHFKDQJHWKHEHKDYLRURIWKHYL
HGLWRU
VHWDOO
VHWDXWRLQGHQWQRDXWRLQGHQW
VHWQXPEHUQRQXPEHU
VHWOLVWQROLVW
VHWVKRZPRGHQRVKRZPRGH
VHWWDEVWRS [
VHWLJQRUHFDVHQRLJQRUHFDVH
VHWZUDSPDUJLQ [
VHWW[QRW[
VHWKOVHDUFKQRKOVHDUFK
V\QWD[RQRII
7RPDNHWKLVRSWLRQVDYDLODEOHWRDOOYLVHVVLRQV
SXWLWLQWRDH[UFRUYLPUFILOHLQ\RXU+20(GLUHFWRU\

Figure 8-16. vi Options LX023.0

Notes:
vi has many settings for operation. Some of these will affect the way text is presented,
while others will make editing easier for novice users.
:set all display all settings
:set autoindent sets autoindent on
:set ai idem
:set noai turns autoindent off
:set number enables line numbers
:set nu idem
:set nonu turn line numbers off
:set list display non-printable characters
:set nolist hide non-printable characters
:set showmode show the current mode of operation (default on)

© Copyright IBM Corp. 2001, 2003 Unit 8. Editing Files 8-19


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

:set noshowmode hide the mode of operation


:set tabstop=4 set tab to 4 character jumps
:set ts=4 idem
Beware of tab stop settings: They only apply to your local
display. What is inserted in the file is actually the tab character
itself, which will be expanded to spaces whenever the file is
read. The number of spaces depend on the terminal settings at
that moment, not at the terminal settings from the time the file
was created.
:set ignorecase ignore case sensitive
:set ic idem
:set noic case sensitive
:set wrapmargin=5 set the margin for automatic word wrapping from one line to the
next.
:set wrapmargin=0 turn off word wrapping
:set tx set MS-DOS style line endings (CR/LF)
:set notx set UNIX style line endings (LF)
:set hlsearch set highlighting of search results on
:set nohlsearch set highlighting of search results off
:syntax on/off set syntax highlighting on/off
You may want to create a .exrc or .vimrc file in your home directory containing these
commands (without the leading colon). The settings in this file will then be read and applied
when starting vi(m).

8-20 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
([LWLQJYL

7RVDYHDQGH[LWLQFRPPDQGPRGH ==
7RVDYHLQH[PRGH Z
7RIRUFHIXOO\VDYHILOHLQH[PRGH Z
7RTXLWZLWKRXWVDYLQJLQH[PRGH T
7RIRUFHIXOO\H[LWLQH[PRGH T
7RVDYHDQGH[LWLQH[PRGH UHFRPPHQGHG ZT
7RVDYHDQGH[LWLQH[PRGHVKRUWHU [

Figure 8-17. Exiting vi LX023.0

Notes:
There are a number of ways to exit vi, both in command mode and ex mode.
The :w! command is useful if you are editing a read-only file but want to write it
nevertheless. vi then tries to remove the read-only attribute, write the file, and set the
read-only attribute again. Obviously, if vi cannot remove the read-only attribute (because
the user is not the owner, for instance), vi generates an error.
The :q! command is useful if you want to exit vi without saving your changes.

© Copyright IBM Corp. 2001, 2003 Unit 8. Editing Files 8-21


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

YL&KHDW6KHHW
&RPPDQGPRGH (GLWPRGH
7RHGLWPRGH
, L D $
&DQQRZW\SH
FXWFRS\SDVWHOLQH MRLQOLQHV FXUVRUPRYH
WH[W1RWHLQ
GG \\ S * - YLPDUURZNH\V
GHOHWHFKDUZRUG VHDUFKUHSHDW N 'HO%DFNVSDFH
ZLOOZRUN
[ ; GZ  Q AK O
H[PRGH VDYH H[LW XQGRUHGR M
 == X * (6&!

([PRGH
VHDUFKDQGUHSODFH (6&!RU(QWHU!
VROGQHZJ
FKDQJHVHWWLQJV VDYHH[LW
VHW Z Z T TZT[

Figure 8-18. vi Cheat Sheet LX023.0

Notes:
You can use this page as a quick reference for some of the most used commands in vi.

8-22 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
2WKHU(GLWRUV

$W\SLFDO/LQX[GLVWULEXWLRQFRPHVZLWKDODUJHQXPEHURI
HGLWRUV([DPSOHV
7H[WPRGHHGLWRUV
SLFR UHDOO\VLPSOH
2ULJLQDOYL
HPDFV HYHQPRUHSRZHUIXODQGFRPSOLFDWHGWKDQYL
*UDSKLFDOPRGHHGLWRUV
NHGLWNZULWH
JHGLW
+H[HGLWRUVDOORZ\RXWRFKDQJHQRQWH[WILOHVLI\RXNQRZ
WKHLQWHUQDOVWUXFWXUH
NKH[HGLW

Figure 8-19. Other Editors LX023.0

Notes:
If you don't want to use vi, or can't use vi on the file you want to edit, there's usually more
editors available. The visual just shows a shortlist. And if you don't like any of the editors
that are available, you're free to write your own (that's the main reason that there are so
many editors around in the first place!)

© Copyright IBM Corp. 2001, 2003 Unit 8. Editing Files 8-23


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&KHFNSRLQW
7)<RXQHHGWROHDUQYLEHFDXVHYLLVWKHEHVWHGLWRU
IRUDQ\MRE

:KDWGRHVWKHILOHFRPPDQGGR"
D,WORRNVDWWKHH[WHQVLRQWRGHWHUPLQHWKHW\SHRIILOH
E,WORRNVDWWKHILUVWIHZFKDUDFWHUVRIWKHILOHDQGFRPSDUHV
WKLVWRDGDWDEDVHRINQRZQILOHW\SHV
F,WDVNVWKHNHUQHOIRULQIRUPDWLRQDERXWWKHILOH
G,WPDNHVDZLOGJXHVV

:KDWLVDKH[HGLWRU"

Figure 8-20. Checkpoint LX023.0

Notes:

8-24 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
8QLW6XPPDU\

7KHPRVWFRPPRQHGLWRURQDQ\81,;LVYL
YLKDVWKUHHPRGHVRIRSHUDWLRQFRPPDQGPRGHHGLW
PRGHDQGH[PRGH
YLPDNHVDFRS\RIWKHILOH\RXDUHHGLWLQJLQDQHGLW
EXIIHU7KHFRQWHQWVDUHQRWFKDQJHGXQWLO\RXVDYHWKH
FKDQJHV
$W\SLFDO/LQX[GLVWULEXWLRQFRPHVZLWKDORWRIRWKHU
HGLWRUVDVZHOO

Figure 8-21. Unit Summary LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 8. Editing Files 8-25


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

8-26 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 9. Working with Processes

What This Unit Is About


This unit discusses the concept of processes, and how the user works
with them.

What You Should Be Able to Do


After completing this unit, you should be able to:
• Define a Linux process
• Describe the relationship between parent and child processes
• Explain the purpose of a shell
• Start foreground and background processes
• Explain the concept of signals and use them to terminate
processes
• Explain the concept of priorities and manage them

How You Will Check Your Progress


Accountability:
• Checkpoint questions
• Machine exercises

© Copyright IBM Corp. 2001, 2003 Unit 9. Working with Processes 9-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
'HILQHD/LQX[SURFHVV
'HVFULEHWKHUHODWLRQVKLSEHWZHHQSDUHQWDQGFKLOG
SURFHVVHV
([SODLQWKHSXUSRVHRIDVKHOO
6WDUWIRUHJURXQGDQGEDFNJURXQGSURFHVVHV
([SODLQWKHFRQFHSWRIVLJQDOVDQGXVHWKHPWRWHUPLQDWH
SURFHVVHV
([SODLQWKHFRQFHSWRISULRULWLHVDQGPDQDJHWKHP

Figure 9-1. Objectives LX023.0

Notes:

9-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
:KDWLVD3URFHVV"

$SURJUDPLVDQH[HFXWDEOHILOH
/RDGLQJDSURJUDPLQWR5$0DQGH[HFXWLQJLWLQLW
VRZQ
HQYLURQPHQWLVFDOOHGDSURFHVV

SURFHVVHQYLURQPHQW
3URJUDPQDPH 8VHUDQGJURXS,'
'DWD 3URFHVV,' 3,'
2SHQ)LOHV 3DUHQW3,' 33,'
&XUUHQW'LUHFWRU\ 3URJUDPYDULDEOHV
DGGLWLRQDOSDUDPHWHUV

7RVHHWKH3,'RI\RXUFXUUHQWVKHOOSURFHVVW\SH
HFKR

Figure 9-2. What is a Process? LX023.0

Notes:
A program or a command that is actually running on a system is referred to as a process.
Linux can run a number of different commands at the same time as well as many
occurrences of the same program (such as vi) at the same process.
The Linux kernel holds an internal table, called the process table, in which the information
about running processes is kept.
A shell is a special process that is able to read user commands and can start the
appropriate program. One of the built-in commands of the shell is echo, which displays
something on the screen, and one of the built-in shell variables is $$, which displays the
Process ID (PID) of the shell.

© Copyright IBM Corp. 2001, 2003 Unit 9. Working with Processes 9-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

6WDUWLQJDQG6WRSSLQJD3URFHVV

$OOSURFHVVHVDUHVWDUWHGE\RWKHUSURFHVVHV
3DUHQW&KLOGUHODWLRQVKLS

OVO

EDVK IRUN

H[HF OVOH[LW

$SURFHVVFDQEHWHUPLQDWHGEHFDXVHRIWZR
UHDVRQV
7KHSURFHVVWHUPLQDWHVLWVHOIZKHQGRQH
7KHSURFHVVLVWHUPLQDWHGE\DVLJQDOIURPDQRWKHU
SURFHVV

Figure 9-3. Starting and Stopping a Process LX023.0

Notes:
All processes in a Linux system are started by another process, so for each and every
process you can identify the parent (the process that started this particular process) and
the children (the processes that were started by this particular process), if any.
There is one exception to this. The init process is started by the kernel itself, and will
always have Process ID 11.
Processes do not run forever. They can be terminated because of two reasons:
• Because the process terminates itself, either automatically (when the work has been
done) or based on user input (such as a user entering "ZZ" in vi).
• When another process sends a "signal" to the process.

1 Actually, there are a few more processes that are started by the kernel. These processes usually have PID 2, 3 and so forth, and their

name usually starts with the letter "k". The amount of processes and their names vary from kernel version to kernel version.

9-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
/RJLQ3URFHVV(QYLURQPHQW

/LQX[6\VWHP
ORJLQ VELQPLQJHWW\
/RJLQ SDVVZRUG
 IRUNVELQEDVK
 EDVK ORJLQVKHOO

(QYLURQPHQW

3URJUDP EDVK
8,'  MRKQ
*,'  XVHUV
RSHQILOHV GHYWW\
3,' 

Figure 9-4. Login Process Environment LX023.0

Notes:
When a user approaches a Linux system and wants to start working with it, he or she is
greeted with the login prompt. This login prompt is generated by the login process2. The
user types his login name, and the login program asks for a password. If the user also
types in the correct password, then the login program looks up the favorite shell of the user
and starts this shell program. This first shell is called the login shell.
In a graphical environment, things work differently:
The graphical login prompt is generated by a display manager (xdm, kdm and gdm are the
most common display managers). When the user correctly authenticates himself, his
window manager is started. The window manager can then start a terminal window, which
in turn starts a shell. Since in a graphical environment more than one terminal window can
be opened, a user can run multiple shells simultaneously.

2
This is not entirely true. The first login prompt is generated by getty, telnetd, sshd or another program that opens that particular tty.
When the user types in his username, the login program is started with that username as parameter. The login program then asks for the
password, and if authentication fails, it displays the second login prompt. Complicated eh?

© Copyright IBM Corp. 2001, 2003 Unit 9. Working with Processes 9-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

3DUHQWVDQG&KLOGUHQ
HFKR


EDVK
HFKR


GDWH
7KX0DU&(7
FWUOG!

HFKR


3,' 33,'
EDVK  
EDVK  
GDWH  
Figure 9-5. Parents and Children LX023.0

Notes:
The PID is the process identification number used by the kernel to distinguish the different
processes. The PPID is the parent process identification number, or in other words, the PID
of the process which started this one.
The special environment variable $$ identifies the PID of the current shell.
The echo command is built into the shell, so it doesn't need to create a subshell to be run.
In the example above, a second bash shell is started as a way to illustrate the parent/child
relationship with processes. As another example, a second, different shell could be started
(for example csh) to run specific shell scripts or programs.

9-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
0RQLWRULQJ3URFHVVHV

7KHSVFRPPDQGGLVSOD\VSURFHVVVWDWXVLQIRUPDWLRQ

SVDX[
86(53,'&380(096=56677<67$767$577,0(&200$1'
URRW"60DULQLW
URRW"6:0DU>NHYHQWG@
URRW"6:0DU>NDSPG@
URRW"6:0DU>NVZDSG@

URRWSWV5SVDX[

SVVXSSRUWVDODUJHQXPEHURIRSWLRQV
D DOOSURFHVVHVDWWDFKHGWRDWHUPLQDO
[ DOORWKHUSURFHVVHV
X SURYLGHVPRUHFROXPQV
RSWLRQVDUHW\SHGZLWKRXWDOHDGLQJ
Figure 9-6. Monitoring Processes LX023.0

Notes:
ps prints process information. When no options are given, it only prints the processes that
were started on your current terminal.
ps supports a large number of options. The most common invocation is ps -aux, which
displays all processes, with and without a tty (-a and -x) in a user-oriented format (-u).

© Copyright IBM Corp. 2001, 2003 Unit 9. Working with Processes 9-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

9LHZLQJ3URFHVV+LHUDUFK\

SVWUHHVKRZVSURFHVVKLHUDUFK\

SVWUHH
LQLWDSPG
_DWG
_FURQG
_JSP
_KWWSG >KWWSG@
_LQHWG
_NDWWUDFWLRQNVV
_NGP;
_CNGPNZPNEJQGZP
__NIP
__NSDQHO
__NURRWZP
__NYWEDVKPDQVKJXQ]LS
__COHVV
_CVWDUWNGHDXWRUXQ
_NIOXVKG

Figure 9-7. Viewing Process Hierarchy LX023.0

Notes:
pstree is a very simple tool which allows you to view the process hierarchy. It also supports
a number of options that allow you to include the PID, for instance.

9-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&RQWUROOLQJ3URFHVVHV

3URFHVVHVFDQEHFRQWUROOHGLQWZRZD\V
)URPWKHVKHOOWKDWVWDUWHGLWXVLQJLWVMREQXPEHU
)URPDQ\ZKHUHHOVHRQWKHV\VWHPXVLQJLWV3,'
$FWLRQVWKDWFDQEHSHUIRUPHGRQDUXQQLQJSURFHVV
7HUPLQDWH
.LOO
6WRS&RQWLQXH
7KHVHDFWLRQVDUHSHUIRUPHGE\VHQGLQJVLJQDOV

Figure 9-8. Controlling Processes LX023.0

Notes:
Once a process has started, it can be controlled in two ways:
• From the shell that started the process, by referring to its job number.
• From anywhere else on the system, by using its Process ID.
Various actions can be performed on a process, including terminate, kill, stop and continue.
If a process was started from a regular, interactive shell, then the notion of foreground and
background comes into play as well. A foreground process is a process that will receive
any keyboard input that is typed into the terminal. A background process will not receive
any keyboard input. Only one process can run in the foreground at once.

© Copyright IBM Corp. 2001, 2003 Unit 9. Working with Processes 9-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

6WDUWLQJ3URFHVVHV

)RUHJURXQG3URFHVVHV
ILQGQDPH5($'0(
EDVK ZDLW

)RUHJURXQGSURFHVVHVDUHLQYRNHGE\VLPSO\W\SLQJD
FRPPDQGDWWKHFRPPDQGOLQH

%DFNJURXQG3URFHVVHV
ILQGQDPH5($'0(
EDVK

%DFNJURXQGSURFHVVHVDUHLQYRNHGE\SXWWLQJDQ DW
WKHHQGRIWKHFRPPDQGOLQH

Figure 9-9. Starting Processes LX023.0

Notes:
Processes that are started from and require interaction with the terminal are called
foreground processes. As long as a foreground process runs, you are not able to run
another command in the system. Processes that are run independently of the initiating
terminal are referred to as background processes.
Background processes are most useful with commands that take a long time to run and do
not need to interact with the user.
A background process is started by ending the command line with a &. This must be the
last character on the command line.
When a background process is started, you will see two numbers.
[1] 417
This means:
[1] this is the first process you are running in the
background.

9-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty 417 this is the process id of this process

© Copyright IBM Corp. 2001, 2003 Unit 9. Working with Processes 9-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

-RE&RQWUROLQWKH%DVK6KHOO

FWUO]! VXVSHQGVIRUHJURXQGWDVN

MREV OLVWVEDFNJURXQGRUVXVSHQGHGMREV

IJ UHVXPHVXVSHQGHGWDVNLQWKH
IRUHJURXQG

EJ UHVXPHVXVSHQGHGWDVNLQWKH
EDFNJURXQG

6SHFLI\DMREQXPEHUIRUEJIJDQGNLOOXVLQJMRE

Figure 9-10. Job Control in the Bash Shell LX023.0

Notes:
You can stop a foreground process by pressing <Ctrl-z>. This does not terminate the
process; it suspends it so that you can subsequently restart it.
To restart suspended processes in the background, use the bg command. To bring a
suspended or background process into the foreground, use the fg command.
To find out what suspended/background jobs you have, issue the jobs command. This
command will show you the job number of a process.
The bg, fg and kill commands can be used with a job number. For instance, to kill job
number 3, you can issue the command: kill %3.
The jobs command does not list jobs that are started with the nohup command if the user
has logged off and then logged back into the system. On the other hand, if a user invokes a
job with the nohup command and then issues the jobs command without logging off, the
job will be listed.

9-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
-RE&RQWURO([DPSOH

ILQGQDPH5($'0(
>@
MREV
>@ UXQQLQJ ILQGQDPH5($'0(
IJ
XVUVKDUHGRFSDFNDJHVJUXE5($'0(

FWUO]!
>@VWRSSHG ILQGQDPH5($'0(
EJ
MREV
>@ UXQQLQJ ILQGQDPH5($'0(
NLOOILQG

Figure 9-11. Job Control Example LX023.0

Notes:
It is not mandatory to use job numbers with fg, bg and kill. Look at the bg and kill
commands to see how to use process ids and process names.

© Copyright IBM Corp. 2001, 2003 Unit 9. Working with Processes 9-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

.LOO6LJQDOV

6HYHUDOVLJQDOVFDQEHVHQWWRDSURFHVV
8VLQJNH\ERDUGLQWHUUXSWV LIIRUHJURXQGSURFHVV
8VLQJWKHNLOOFRPPDQG
6\QRSVLVNLOOVLJQDO3,'
8VLQJWKHNLOODOOFRPPDQGWRNLOODOOQDPHGDSSV
6\QRSVLVNLOODOOVLJQDODSSOLFDWLRQ
0RVWLPSRUWDQWVLJQDOV

6LJQDO .H\ERDUG 0HDQLQJ 'HIDXOWDFWLRQ


 KDQJXS HQGSURFHVV
 &WUO& LQWHUUXSW HQGSURFHVV
 &WUO? TXLW HQGSURFHVV FRUHGXPS
 NLOO HQGSURFHVVFDQQRWEH
UHGHILQHGKDQGOHGE\NHUQHO
 WHUPLQDWH HQGSURFHVV

Figure 9-12. Kill Signals LX023.0

Notes:
If you want to control a process from outside the shell (or other process) that started it, you
need to use signals. Signals are the UNIX way of "nudging" a process into doing
something.
When a process is running in the foreground, you can use keyboard interrupts (Ctrl-key) to
send a signal. Otherwise, you need to use the kill or killall command to send a signal.
Most signals are delivered to the application itself. Technically, this means that the
programmer of an application can write a special subroutine (called a signal handler) that is
executed when a signal arrives. If the programmer did not write these special signal
handlers, then the kernel will perform the default action for that signal, which in most cases
means that the application will be terminated.
For us, only a few signals are important.
The hangup (01) signal is sent to a process if its parent dies, for example, if you log off
when a background process is running. Most daemons (discussed later) redefine this
signal to mean "re-read configuration file".

9-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty The interrupt signal (02) is generated when the user presses the interrupt key (usually
<Ctrl-c>) on the keyboard. The key is in different places depending upon the system and
the terminal type.
Users pressing the quit key (usually <Ctrl-\>) generates the quit signal (03). Again, this is in
different places on different systems.
The difference between Ctrl-c (signal 02) and Ctrl-\ (signal 03), from a programmer
standpoint is that Ctrl-\ by default generates a so-called "core dump". This is a file, usually
called core, which contains the state of the program at the moment Ctrl-\ was pressed. By
using a "debugger", such as gdb, the programmer can then use this core dump to figure
out what is going on in the program. In all but a very few cases, a core dump is not
interesting for a regular user and can be deleted.
The most powerful signal you can send to a process is a signal 9, because this signal is
never delivered to the process, but handled by the Linux kernel immediately. A process can
thus never redefine this signal. Processes which refuse to be killed by other signals can
thus be killed with the kill -9 command. There is a drawback to this however: Since the
process is killed right away, it has no chance of writing data to disk and closing files
correctly. This may lead to corrupted data. Use kill -9 therefore only as a last resort.
The kill command by default sends a signal of 15 to a process. This is the regular
terminate signal.
To list all the signals supported use the kill -l command. This list also shows you the names
of signals. Instead of the signal number you could also use the signal name. kill -9 PID
equals kill -SIGKILL PID.
Note that the number of the signal bears no resemblance to its strength or priority.
The killall command was created in Linux since most users do not know the PID of the
process they want to kill, but only the name. This meant that they first needed to do a ps
command to determine the PID of the process before they could issue the kill command.
To short-circuit this, the killall command was invented. This command does not accept a
PID, but rather expects the name of a running process as arguments. It then sends the
signal to ALL processes with that name.
As an example, there are a few programs on a Linux system that are notorious for leaving
child processes running when the master process ends. Examples include netscape, tkrat
and wine. All these child processes can be killed with a single command, such as killall
netscape, killall tkrat or killall wine.

© Copyright IBM Corp. 2001, 2003 Unit 9. Working with Processes 9-15
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

5XQQLQJ/RQJ3URFHVVHV

7KHQRKXSFRPPDQGZLOOVWRSDSURFHVVIURPEHLQJNLOOHGLI
\RXORJRIIWKHV\VWHPEHIRUHLWFRPSOHWHVE\LQWHUFHSWLQJDQG
LJQRULQJWKH6,*+83DQG6,*48,7 KDQJXSDQGTXLW VLJQDOV

QRKXSILQGQDPH5($'0(
QRKXSDSSHQGLQJRXWSXWWRCQRKXSRXW
ORJRXW

Figure 9-13. Running Long Processes LX023.0

Notes:
nohup will tell the process to ignore signals 01 and 03 (hangup and quit). This will allow the
process to continue if you log off the system.
Since all processes need to have an associated parent process, commands started with
nohup will get the init process as the parent when you log off the system.
nohup is designed to be used for background processes as it has little meaning when used
with a foreground process.

9-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
0DQDJLQJ3URFHVV3ULRULWLHV
3URFHVVHVDUHVFKHGXOHGDFFRUGLQJWRSULRULW\

 G\QDPLFSDUWRISULRULW\
 FDOFXODWHGE\VFKHGXOHU


XVHUGHILQHGSULRULW\
QHJDWLYHYDOXHVDUH
%DVHSULRULW\ 
DOORZHGRQO\WRURRW 


UHVHUYHGIRUNHUQHO
 WKUHDGV


Figure 9-14. Managing Process Priorities LX023.0

Notes:
Processes on a Linux system are scheduled according to priority: When the CPU is free to
run a process, it looks through the process table for a process with the lowest "priority
number". This process will then get a timeslice on the CPU.
The priority number of a process is continuously changed. There are basically three factors
that influence this:
• After a process has had a certain amount of CPU time, its priority number is increased,
meaning that next time the CPU becomes available, the process is less likely to be first
in the list.
• After a process has been idle (not using CPU time) for a while (either because it is
waiting for something to happen, or because other processes are keeping the CPU
busy), the priority number is decreased.
• The priority number can never become lower than the "nice value" that was set for that
process.

© Copyright IBM Corp. 2001, 2003 Unit 9. Working with Processes 9-17
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

This scheme results in a usage pattern where every process with the same nice value will
get an equal amount of CPU time. Processes with a higher nice value will get less CPU
time than processes with a low nice value.

9-18 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KHQLFH&RPPDQG

7KHQLFHFRPPDQGLVXVHGWRVWDUWDSURFHVVZLWKDXVHU
GHILQHGSULRULW\
QLFH>QYDOXH!@RULJLQDOFRPPDQG!

QLFHQP\BSURJUDP
>@
SVO
) 8,' 3,' 35,1, 96=&200$1'
EDVK
P\BSURJUDP
SVO

Figure 9-15. The nice command LX023.0

Notes:
To decrease the priority of a process when starting that process, use the nice command.
By default, nice sets a priority of 10 for a process, but this can be changed with the -n
option.
Only root can set negative nice values.
Note that, because of the priority mechanism, even on a busy system, a process with a
nice value of 20 will get some CPU time.

© Copyright IBM Corp. 2001, 2003 Unit 9. Working with Processes 9-19
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHUHQLFH&RPPDQG

7KHUHQLFHFRPPDQGLVXVHGWRFKDQJHWKHSULRULW\RID
FXUUHQWO\UXQQLQJSURFHVV
UHQLFHQHZBSULRULW\!3,'!

UHQLFH
ROGSULRULW\QHZSULRULW\
SVO
) 8,' 3,' 35,1, 96=&200$1'
EDVK
P\BSURJUDP
SVO
UHQLFH
UHQLFHVHWSULRULW\3HUPLVVLRQGHQLHG

Figure 9-16. The renice Command LX023.0

Notes:
When you want to change the priority of a process which is already running, use the renice
command

9-20 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
,QWHJUDWHG3URFHVV0DQDJHPHQW

9DULRXVLQWHJUDWHGWRROVH[LVWIRUSURFHVVPDQDJHPHQW
WRSJSPNSP
$YDLODELOLW\GHSHQGVRQGLVWULEXWLRQ

Figure 9-17. Integrated Process Management LX023.0

Notes:
Various tools exist that offer integrated process management. Examples of these are top
(which runs in a text terminal) and kpm (which runs in a graphical environment).
Both of these tools are highly configurable: you can select the things you want to see about
each process, and you can sort the processes the way you want.
But the biggest advantage is that the display is refreshed every few seconds (the amount of
seconds is configurable as well). Together with some generic information about the system
(number of users, CPU usage, memory usage), this makes it useful for getting a quick
impression of what the system is doing. A large number of system administrators therefore
keep these tools running all day, despite the CPU cost. (Running top or kpm typically costs
about 2-5% CPU time.)

© Copyright IBM Corp. 2001, 2003 Unit 9. Working with Processes 9-21
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

'DHPRQV

7KHZRUG'DHPRQUHIHUVWRDQHYHUHQGLQJSURFHVVXVXDOO\D
V\VWHPSURFHVVWKDWFRQWUROVDV\VWHPUHVRXUFHVXFKDVWKH
SULQWHUTXHXHRUSHUIRUPVDQHWZRUNVHUYLFH

3ULQW4XHXH OSG

SULQWMRE

SULQWMRE

SULQWMRE

GHYOS

Figure 9-18. Daemons LX023.0

Notes:
A daemon3 means a background process that typically starts when you start your system
and runs until you shut it down. These processes are typically used to control access to a
system resource, or to perform a network service.
lpd is one example of a daemon. lpd tracks print job requests and the printers available to
handle them. The lpd daemon maintains queues of outstanding requests and sends them
to the proper device at the proper time.
Technically speaking, daemons are nothing more than regular background processes. It's
just the purpose that gives them another name.

3
A daemon originally means a sort of a friendly ghost or spirit, which guards your interests on behalf of you.

9-22 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&KHFNSRLQW

7)$Q\XVHUFDQVHQGDVLJQDOWRDSURFHVVRIDQRWKHU
XVHUDQGFDXVHWKLVSURFHVVWRKDOW

,IDSURFHVVLVKDQJLQJWKHSURSHURUGHURIWU\LQJWR
WHUPLQDWHLWZLWKWKHORZHVWFKDQFHRIGDWDFRUUXSWLRQLV
DNLOO&WUO&NLOO&WUO?
E&WUO=NLOONLOONLOO&WUO&
FNLOONLOO&WUO&&WUO=
G&WUO&&WUO?NLOONLOO

:KDWLVDGDHPRQ"

Figure 9-19. Checkpoint LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 9. Working with Processes 9-23
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

8QLW6XPPDU\

$OOSURFHVVHVDUHVWDUWHGE\DSDUHQWSURFHVV H[FHSW
IRULQLWZKLFKLVVWDUWHGE\WKHNHUQHO
(YHU\SURFHVVLVLGHQWLILHGZLWKD3URFHVV,GHQWLILHU 3,'
$VSHFLDOSURFHVVLVWKHVKHOOZKLFKFDQLQWHUSUHWXVHU
FRPPDQGV
3URFHVVHVFDQWHUPLQDWHE\WKHPVHOYHVRUXSRQ
UHFHSWLRQRIDVLJQDO
6LJQDOVFDQEHVHQWE\WKHVKHOOXVLQJDNH\ERDUG
VHTXHQFHRUE\WKHNLOODQGNLOODOOFRPPDQGV
3URFHVVHVDUHVWDUWHGZLWKHTXDOSULRULW\EXWWKLVFDQEH
FKDQJHGXVLQJWKHQLFHDQGUHQLFHFRPPDQGV
$GDHPRQLVDEDFNJURXQGSURFHVVWKDWW\SLFDOO\FRQWUROV
DV\VWHPUHVRXUFHRURIIHUVDQHWZRUNVHUYLFH

Figure 9-20. Unit Summary LX023.0

Notes:

9-24 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 10. Shell Basics

What This Unit Is About


This unit gives the student an introduction to the advanced features of
the shell.

What You Should Be Able to Do


After completing this unit, you should be able to:
• Explain the function of the shell
• Discuss metacharacters and reserved words
• Use wildcards to access files with similar names
• Use redirection and pipes
• Use command substitution
• Describe and use the most common filters
• Group commands in order to control their execution
• Work with shell variables
• Apply quoting
• Use aliases
• Write and invoke basic shell scripts

How You Will Check Your Progress


Accountability:
• Checkpoint questions
• Machine exercises

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
([SODLQWKHIXQFWLRQRIWKHVKHOO
'LVFXVVPHWDFKDUDFWHUVDQGUHVHUYHGZRUGV
8VHZLOGFDUGVWRDFFHVVILOHVZLWKVLPLODUQDPHV
8VHUHGLUHFWLRQDQGSLSHV
8VHFRPPDQGVXEVWLWXWLRQ
'HVFULEHDQGXVHWKHPRVWFRPPRQILOWHUV
*URXSFRPPDQGVLQRUGHUWRFRQWUROWKHLUH[HFXWLRQ
:RUNZLWKVKHOOYDULDEOHV
$SSO\TXRWLQJ
8VHDOLDVHV

Figure 10-1. Objectives LX023.0

Notes:

10-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KH6KHOO

7KHVKHOOLVWKHXVHULQWHUIDFHWR/LQX[

FRPPDQGLQWHUSUHWHU

FDQEHFRQILJXUHG

DYDLODEOHVKHOOV
EDVK
NVK
FVK
WKHVKHOO

SURFHVVPDQDJHPHQW
IXQFWLRQV
ZLOGFDUGV
YDULDEOHV

Figure 10-2. The Shell LX023.0

Notes:
The shell is a special program in any UNIX operating system, including Linux, because it
allows the user to interact with the operating system.
It does this by allowing the user to type a command and subsequently interprets and
executes this command. The shell also has a number of commands and control structures
built-in, which allow it to be used as a comprehensive programming language.
A huge number of shells have been written by various people since the first shell, simply
called sh was released. A lot of these shells are also available for Linux.
In most distributions the default shell is bash, which stands for Bourne Again SHell.

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

6KHOO)HDWXUHV

:KHQWKHXVHUW\SHVDFRPPDQGYDULRXVWKLQJVDUH
GRQHE\WKHVKHOOEHIRUHWKHFRPPDQGLVDFWXDOO\
H[HFXWHG
:LOGFDUGH[SDQVLRQ ">@
,QSXW2XWSXWUHGLUHFWLRQ !!!!
&RPPDQGJURXSLQJ ^FRPFRP`
/LQHFRQWLQXDWLRQ ?
6KHOOYDULDEOHH[SDQVLRQ 9$5
$OLDVH[SDQVLRQ GLU!OVO
6KHOOVFULSWLQJ  ELQEDVK
)RUH[DPSOHWKHOV GRFFRPPDQGFRXOGEHH[SDQGHG
WRELQOVFRORU WW\P\GRFGRFXVHUGRFEHIRUH
H[HFXWLRQ GHSHQGLQJRQVHWWLQJVDQGILOHVSUHVHQW

Figure 10-3. Shell Functions LX023.0

Notes:
As said, the shell allows you to type your command, after which it will interpret it and
execute the corresponding program. However, before it executes the program it performs
certain transformations on the command you just entered. If you know what these
transformations are, and how to use them, it will make your life much simpler.
Some of these transformations are listed in the visual. We will cover them in this unit. But
these are not the only things that the shell can do. Just like when we talked about vi, we are
only going to scratch the surface here. For more in-depth information, read the manual,
read the excellent book "Learning the bash shell" from O'Reilly (ISBN 1-6592-347-2), or go
to any of IBM's other Linux courses, in particular the LX23 (Bash Shell Programming).

10-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
0HWDFKDUDFWHUVDQG5HVHUYHG:RUGV

0HWDFKDUDFWHUVDUHFKDUDFWHUVWKDWWKHVKHOOLQWHUSUHWVDV
KDYLQJDVSHFLDOPHDQLQJ
([DPSOHV
!_" >@?
Ca  ^`

5HVHUYHGZRUGVDUHZRUGVWKDWWKHVKHOOLQWHUSUHWVDV
VSHFLDOFRPPDQGV
([DPSOHV
FDVHGRGRQHHOLIHOVHHVDFILIRUIXQFWLRQ
LILQVHOHFWWKHQXQWLOZKLOH

Figure 10-4. Metacharacters and Reserved Words LX023.0

Notes:
In order for the shell to make a distinction between the actual command and the actual
parameters that you typed, and the hints you want to give to the shell to let it do something,
there has to be some sort of agreement on what the shell can touch in your command and
what not. As part of this agreement, a number of metacharacters and reserved words have
been defined.
Metacharacters are individual characters which have a special meaning to the shell. They
can appear anywhere in your command and will always be handled by the shell itself.
Reserved words are words that the shell interprets as special commands. They only have a
special meaning if they appear as a single word, surrounded by whitespace (whitespace is
the beginning of the line, one or more spaces or tabs, or the end of the line). function for
instance is a reserved word, but functions is not.
You should never name your file or program after a reserved word, nor should your
filenames ever contain a reserved character1.

1
Technically, it is possible, but it will only get you in trouble later.

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

%DVLF:LOGFDUG([SDQVLRQ
:KHQWKHVKHOOHQFRXQWHUVDZRUGZKLFKFRQWDLQVD
ZLOGFDUGLWWULHVWRH[SDQGWKLVWRDOOPDWFKLQJILOHQDPHV
LQWKHJLYHQGLUHFWRU\


OVDKRPHWX[
HWZIHZP\ILOHQHQHVWQHWQHZWHVWWHVWWHVW KRPH
"PDWFKHVDVLQJOHFKDUDFWHU
HFKRQH" WX[
QHWQHZ
WHVW
HFKR"H" WHVW
IHZQHWQHZ WHVW
P\ILOH
PDWFKHVDQ\VWULQJLQFOXGLQJWKHQXOOVWULQJ QH
HFKRQ QHZ
QHQHWQHZQHVW QHVW
HFKR Z QHW
QHZIHZ IHZ
Z
HW

Figure 10-5. Basic Wildcard Expansion LX023.0

Notes:
One of the first things the shell will do after it has read your command is to try to perform
wildcard expansion. This means that it will start looking in your command for words that
contain (or solely consist of) one or more wildcards. It will then look in the filesystem to see
if it can expand that word to one or more filenames that match the pattern.
The most often used wildcards are "*" (star or asterisk) and "?" (question mark).
The * matches zero or more arbitrary characters, with one exception: An asterisk all by
itself matches any filename in the current directory except for hidden filenames (filenames
that start with a dot).
The ? matches exactly one arbitrary character.
Note that wildcard expansion is done for each and every command that is entered by the
user, even if the program that started doesn't accept any filenames as parameters at all!
Important note: If wildcard expansion fails (thus: there is no file in the filesystem that
matches the pattern supplied), then the wildcards will be passed as parameters to the
program, instead of the expanded filenames. This may lead to unexpected results.

10-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
$GYDQFHG:LOGFDUG([SDQVLRQ
7KHZLOGFDUGV>@DQGPDWFKLQFOXVLYHOLVWV

HFKRQH>VWZ@ 
QHWQHZ

KRPH
HFKR >@
WHVWWHVW
WHVW WX[

HFKR>WQ@ WHVW
WHVW
P\ILOHIHZ
WHVW
P\ILOH
HFKR">\@ >@ QH
WHVWWHVW QHZ
QHVW
QHW
IHZ
Z
HW

Figure 10-6. Advanced Wildcard Expansion LX023.0

Notes:
At certain times, the ? and * wildcards give a match that is too broad. You might for
instance only want filenames that start with the letters a or b. In that case, inclusive lists
can be used. An inclusive list is defined with square brackets (“[“ and “]”) which contain the
letters to match. The dash sign can be used to enumerate, and the exclamation mark can
be used to invert the list (all characters match except the ones listed). See the visual for
examples.

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

)LOH'HVFULSWRUV

(YHU\SURJUDPKDVDQXPEHURIILOHGHVFULSWRUV
DVVRFLDWHGZLWKLW
7KUHHGHVFULSWRUVDUHDVVLJQHGE\WKHVKHOOZKHQWKH
SURJUDPVWDUWV 67',167'287DQG67'(55
2WKHUGHVFULSWRUVDUHDVVLJQHGE\WKHSURJUDPZKHQLW
RSHQVILOHV

6WDQGDUGLQ 
6WDQGDUG,Q 67',1  
FRPPDQG
6WDQGDUG2XW 67'287 ! 
VWDQGDUGRXW  VWDQGDUGHUURU 
6WDQGDUG(UURU 67'(55 ! 

Figure 10-7. File Descriptors LX023.0

Notes:
Three files are automatically opened for each process in the system. These files are
referred to as standard input (stdin), standard output (stdout) and standard error
(stderr).
Standard input is where a command expects to find its input, by default the keyboard.
Standard out and standard error are where the command expects to put its output, by
default the screen. These defaults can be changed using redirection.

10-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
,QSXW5HGLUHFWLRQ

'HIDXOW6WDQGDUG,QSXW

FDW
$PVWHUGDP
$PVWHUGDP
8WUHFKW
8WUHFKW
FWUOG!

67',1UHGLUHFWHGIURPILOH
FDWFLWLHV
$PVWHUGDP
8WUHFKW


Figure 10-8. Input Redirection LX023.0

Notes:
The symbol < tells cat to take input from the file instead of the keyboard.
The file table for the redirection example will look like the following:

Descriptor Default When command is running

0 keyboard file “cities”

1 screen screen

2 screen screen

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2XWSXW5HGLUHFWLRQ

'HIDXOW6WDQGDUG2XWSXWGHYWW\
OV
ILOHILOHILOH

5HGLUHFWRXWSXWWRDILOH
OV!OVRXW

5HGLUHFWDQGDSSHQGRXWSXWWRDILOH
OV!!OVRXW

&UHDWHDILOHZLWKUHGLUHFWLRQ
FDW!QHZBILOH
6DYHWKLVOLQH
&WUO'!

Figure 10-9. Output Redirection LX023.0

Notes:
Redirection allows standard output to go to somewhere other than the screen (default). In
the example, standard output has been redirected with > to go the file named ls.out.
The file descriptor table in this example will hold the following values:

Descriptor Default When command runs

0 keyboard keyboard

1 screen file “ls.out”

2 screen screen

Using ordinary redirection will overwrite an existing file. To avoid this, use the >> (no space
between them) to append output to an existing file.

10-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
(UURU5HGLUHFWLRQ

'HIDXOW6WDQGDUG(UURUGHYWW\
FDWILOHD
FDWILOHD1RVXFKILOHRUGLUHFWRU\

5HGLUHFWHUURURXWSXWWRDILOH
FDWILOHD!HUURUILOH
FDWHUURUILOH
FDWILOHD1RVXFKILOHRUGLUHFWRU\

5HGLUHFWDQGDSSHQGHUURUVWRDILOH
FDWILOHD!!HUURUILOH

'LVFDUGHUURURXWSXW
FDWILOHD!GHYQXOO

Figure 10-10. Error Redirection LX023.0

Notes:
There can be no space between the 2 and the >.
The special file /dev/null is a bottomless pit where you can be redirect unwanted data. All
data sent there is just thrown away.
/dev/null has the unique property of always being empty. It is commonly referred to as the
bit bucket. The file descriptor table for the first error redirection example will contain the
following:

Descriptor Default When command runs

0 keyboard keyboard

1 screen screen

2 screen error.file

and for the second:

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Descriptor Default When command runs

0 keyboard keyboard

1 screen screen

2 screen error.file

10-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&RPELQHG5HGLUHFWLRQ

&RPELQHGUHGLUHFWV
FDWFLWLHV!FLWLHVFRS\!HUURUILOH
FDW!!FLWLHVFRS\!!HUURUILOHPRUHFLWLHV

$VVRFLDWLRQ
7KLVUHGLUHFWVVWGHUUWRZKHUHVWGRXWLVUHGLUHFWHG

FDWFLWLHV!FLWLHVFRS\! 
ZULWHVERWKVWGHUUDQGVWGRXWWRFLWLHVFRS\

EHFDUHIXODERXWWKLV
FDWFLWLHV! !FLWLHVFRS\
ZULWHVVWGHUUWRGHYWW\DQGVWGRXWWRFLWLHVFRS\

Figure 10-11. Combined Redirection LX023.0

Notes:
With the association examples, the order in which redirections are specified is significant.
In the first example, file descriptor 1 is associated with the file specified, outfile. Then the
example associates descriptor 2 with the file associated with file description 1, outfile.
If the order of the redirection is reversed, the errors are redirected to the same place as
standard out. But standard out at this point has not been redirected yet, so the default
value will be used, which is the screen. So the error messages will be redirected to the
screen. Remember that the default error messages are sent to the screen.
In bash, the sequence "&>" is identical to "2>&1".

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

3LSHV

$VHTXHQFHRIWZRRUPRUHFRPPDQGVVHSDUDWHGE\D
YHUWLFDOEDU _ LVFDOOHGDSLSHRUSLSHOLQH

OVO_ZFO

7KHVWDQGDUGRXWSXWRIFRPPDQGEHFRPHVWKHVWDQGDUG
LQSXWRIFRPPDQG

6WGLQ  6WGRXW  6WGLQ  6WGRXW 


FRPPDQG FRPPDQG

6WGHUU  6WGHUU 

Figure 10-12. Pipes LX023.0

Notes:
Two or more commands can be separated by a pipe (“|”, vertical bar) on a single command
line. The requirement is that any command to the left of a pipe must send output to
standard output. Any command to the right of the pipe must take its input from standard
input.
Note that everything ls sends to standard out will now be counted by wc.

10-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
)LOWHUV

$ILOWHULVDFRPPDQGWKDWUHDGVIURPVWDQGDUGLQ
WUDQVIRUPVWKHLQSXWLQVRPHZD\DQGZULWHVWRVWDQGDUG
RXW7KH\FDQWKHUHIRUHEHXVHGDWLQWHUPHGLDWHSRLQWV
LQDSLSHOLQH

OV_JUHSGRF_ZFO


Figure 10-13. Filters LX023.0

Notes:
A command is referred to as a filter if it can read its input from standard input, alter it in
some way, and write its output to standard output. A filter can be used as an intermediate
command between pipes.
A filter is commonly used with a string of piped commands, as in the example above. The
ls command lists all the files in the current directory and then pipes this information to the
grep command. The grep commands will be covered in more detail later in the course, but
in this example, the grep command is used to find all file names which contain ".doc". The
output of grep is piped to the wc -l command. The result is that the command counts the
number of files in our current directory beginning with an "n". In this example, the grep
command is acting as a filter.

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-15
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&RPPRQ)LOWHUV

H[SDQGXQH[SDQG&KDQJHWDEVWRVSDFHVDQGYLFH
YHUVD
VHG$OORZVVWULQJVXEVWLWXWLRQV
DZN3DWWHUQVFDQQLQJDQGSURFHVVLQJ
IPW,QVHUWOLQHZUDSVVRWH[WORRNVSUHWW\
WDF'LVSOD\OLQHVLQUHYHUVHRUGHU
WU6XEVWLWXWHFKDUDFWHUV
JUHS2QO\GLVSOD\VOLQHVWKDWPDWFKDSDWWHUQ
QO1XPEHUOLQHV
SU)RUPDWIRUSULQWHU

Figure 10-14. Common Filters LX023.0

Notes:
There exists a large number of programs which can be used as a filter on an average UNIX
system. The list above shows the more common ones.
expand expands all TAB characters to spaces, ensuring that everything is aligned properly.
The number of tab stops can be specified as a parameter. unexpand does exactly the
opposite.
sed allows string substitutions. It works like the global editing facilities in vi, but doesn't edit
a file. Instead, it filters standard input to standard output, executing the specified
substitutions on the go. A short example: sed s/old/new/ < oldfile > newfile will copy
oldfile to newfile, changing all occurrences of "old" to "new".
awk is a pattern scanning and processing language. awk scans each line of text and
applies the necessary procedures to that line. A short example: awk { print $1 } < infile
only prints the first field of each line of "infile" to stdout.

10-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty sed and awk are really powerful commands - so powerful that some people refer to them
as programming languages. O'Reilly has a book about them in case you're interested.
They are also covered in the LX23 (Linux Bash Programming) course.
fmt is a text formatter. It takes unformatted text and formats them so that it looks pretty,
inserting for instance line breaks, spaces and so forth where necessary.
tac (inverse of cat) displays the lines in reverse order, last line first.
tr converts individual characters. Here's how you convert all uppercase characters to
lowercase: tr '[A-Z]' '[a-z]'.
grep scans individual lines for a pattern and only displays them if there is a match. It is very
useful for filtering specific things out of a large file.
nl numbers all lines.
pr formats your output for a printer, adding headers, footers, page numbers and page
breaks in the process.

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-17
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

6SOLW2XWSXW

7KHWHHFRPPDQGUHDGVVWDQGDUGLQSXWDQGVHQGVWKH
GDWDWRERWKVWDQGDUGRXWDQGDILOH

OV_ZFO


OV_WHHOVVDYH_ZFO


FDWOVVDYH
ILOH
ILOH
ILOH

Figure 10-15. Split Output LX023.0

Notes:
The tee command is a command that can be used to capture a snapshot of information
going through a pipe. tee puts a copy of the data in a file as well as passing it to standard
output to be used by the next command. tee does not alter the data flowing through the
pipe.

10-18 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&RPPDQG6XEVWLWXWLRQ

&RPPDQG6XEVWLWXWLRQDOORZV\RXWRXVHWKHRXWSXWRID
FRPPDQGDVDUJXPHQWVIRUDQRWKHUFRPPDQG
8VHEDFNWLFNV C RU QRWDWLRQ

UPLCOV GRF_JUHSYNHHSPHC

HFKR7KHUHDUH SVD[_ZFO SURFHVVHVUXQQLQJ

Figure 10-16. Command Substitution LX023.0

Notes:
Command substitution allows you to use the output (stdout) of a command as arguments
for another command. This is typically used in a situation where you have a complicated
command which delivers a series of filenames or usernames, and need to use these
filenames or usernames as arguments.
Two notations are possible: with backticks (‘) and with the $() notation.
The examples in the visuals are equal and work as follows:
• The ls command generates a list of files in the current directory ending in “.doc”
• The grep -v command filters the list of files, and removes all lines (filenames) that
contain the word “keepme”. (The -v option to grep reverses the functionality of grep:
only lines NOT containing the pattern are shown.)
• The resulting list is used as arguments to the rm command.
In short, the command listed removes all files with names ending in “.doc”, except for files
with “keepme” in their name.

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-19
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&RPPDQG*URXSLQJ

0XOWLSOHFRPPDQGVFDQEHHQWHUHGRQWKHVDPHOLQH
VHSDUDWHGE\DVHPLFRORQ 

GDWHSZG

&RPPDQGVFDQEHJURXSHGLQWRRQHLQSXWRXWSXWVWUHDP
E\SXWWLQJFXUO\EUDFHVDURXQGWKHP

^HFKR3ULQWGDWHGDWHFDWFLWLHV`_OSU

&RPPDQGVFDQEHH[HFXWHGLQDVXEVKHOOE\SXWWLQJ
URXQGEUDFHVDURXQGWKHP

 HFKR3ULQWGDWHGDWHFDWFLWLHV _OSU

Figure 10-17. Command Grouping LX023.0

Notes:
Placing multiple commands separated by a ; on a single line produces the same result as
entering each command on a separate command line. There is no relationship between the
commands, nor is any input or output redirection being done.
Commands can be grouped into one input/output stream by putting curly braces (“{“ and
“}”) around them. This combines their input/output streams into one.
You can also group commands into one input/output stream by putting round braces (“(“
and “)”) around them. In this case, the grouped commands are executed in a subshell.

10-20 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
6KHOO9DULDEOHV

9DULDEOHVDUHSDUWRIWKHHQYLURQPHQWRIDSURFHVV
$YDULDEOHKDVDQXQLTXHQDPH
7KHILUVWFKDUDFWHUPXVWQRWEHDGLJLW
7RDVVLJQDYDOXHWRDYDULDEOHXVH
YDULDEOH YDOXH
9$5 +HOORFODVV

9$5 

Figure 10-18. Shell Variables LX023.0

Notes:
Another feature of the shell is the expansion of shell variables. Shell variables can be set
using the variable=value command (note that it is not allowed to put a space between the
variable name and the equal sign). They are always stored as strings, even if the value is
an integer. Their length is unlimited.

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-21
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

5HIHUHQFLQJ6KHOO9DULDEOHV

7RUHIHUHQFHWKHYDOXHRIDYDULDEOHXVH
YDULDEOH

HFKR9$5
+HOORFODVV

HFKR9$5


Figure 10-19. Referencing Shell Variables LX023.0

Notes:
To reference a variable, use the $variable expression.

10-22 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
([SRUWLQJ6KHOO9DULDEOHV

7KHH[SRUWFRPPDQGLVXVHGWRSDVVYDULDEOHVIURPD
SDUHQWWRDFKLOGSURFHVV
&KDQJHVPDGHWRYDULDEOHVLQDFKLOGSURFHVVGRQRW
DIIHFWWKHYDULDEOHVLQLWVSDUHQW

H[SRUW[ 
EDVK
HFKR[

[ 
HFKR[

H[LW
HFKR[


Figure 10-20. Exporting Shell Variables LX023.0

Notes:
Variables by default are local to the shell they are defined in, which means that programs
(including subshells) that are running as child process of this shell cannot reference the
variables.
Only when a variable is “exported”, is it made available for all subsequent child processes
(including subshells) too.
The export command will export a variable or will list exported variables if no parameters
are provided.
If you change the value of a variable in a subshell, that change does not affect the parent
process.

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-23
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

6WDQGDUG6KHOO9DULDEOHV

7KHVKHOOXVHVVHYHUDOVKHOOYDULDEOHVLQWHUQDOO\
7KHVHYDULDEOHVDUHDOZD\VZULWWHQLQXSSHUFDVH
([DPSOH
3,'RIFXUUHQWVKHOO
3$7+3DWKZKLFKLVVHDUFKHGIRUH[HFXWDEOHV
363ULPDU\VKHOOSURPSW
366HFRQGDU\VKHOOSURPSW
3:'&XUUHQWZRUNLQJGLUHFWRU\
+20(+RPHGLUHFWRU\RIXVHU
/$1*/DQJXDJHRIXVHU
2YHUZULWLQJWKHVHYDULDEOHVE\DFFLGHQWFDQFDXVH
XQH[SHFWHGUHVXOWV
$OZD\VXVHORZHUFDVHYDULDEOHVLQ\RXURZQVKHOO
VFULSWVWRDYRLGFRQIOLFWV

Figure 10-21. Standard Shell Variables LX023.0

Notes:
The shell always defines and uses a large number of shell variables itself. These variables
are almost always written with uppercase letters.
The most important shell variables for us are:
$ The Process ID of the shell
PATH The search path for programs to be executed. If the user types a command
and this command is not a built-in command and contains no indication of
where it might be stored (such as ./command, which indicates that the
command is stored in the current directory), then all directories in the
variable $PATH are searched (in order of appearance).
Note that if the current directory (indicated with a dot) is not part of the
$PATH variable, then the current directory will not be searched. This is
considered a safety feature and therefore the default in most distributions.
PS1 The primary command prompt. This prompt is shown when the shell is able
to accept a command.

10-24 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Special character sequences exist which can be used in this prompt, and
which will be expanded to, for instance, the current username, directory or
time of the day. See the manual page of bash for details.
PS2 The secondary command prompt. This prompt is shown for instance after
the user ended a line with the line continuation character (backslash).
PWD The current working directory.
HOME The home directory of the user.
LANG The current language of the user. This variable is used for instance when
sorting data (some countries list the é between e and f, and other countries
list it after the z), when generating error messages and a lot of other things.
If you experience strange results, try LANG=C, which gives the default
ASCII sorting order.
There are far more shell variables that the shell uses internally. If you overwrite them
accidentally, you might experience strange problems. It is therefore a good idea to use
lowercase variables in your own shell scripts.

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-25
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

5HWXUQ&RGHVIURP&RPPDQGV

$FRPPDQGUHWXUQVDYDOXHWRWKHSDUHQWSURFHVV%\
FRQYHQWLRQ]HURPHDQVVXFFHVVDQGDQRQ]HURYDOXH
PHDQVDQHUURURFFXUUHG
$SLSHOLQHUHWXUQVDVLQJOHYDOXHWRLWVSDUHQW
7KHHQYLURQPHQWYDULDEOH"FRQWDLQVWKHUHWXUQFRGHRI
WKHSUHYLRXVFRPPDQG

ZKRDPL
WX[
HFKR"

FDWILOHD
FDWILOHD1RVXFKILOHRUGLUHFWRU\
HFKR"


Figure 10-22. Return Codes from Commands LX023.0

Notes:
After a program exits, a return code is sent to the parent process. This number can thus be
used to tell the parent the termination status of the child process. By convention, a return
code of 0 means that the process ran correctly. A return code other than 0 indicates that
something went wrong during the execution of the command.
After a program has run, the shell makes the return code available by using the shell
variable $?.

10-26 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
4XRWLQJ0HWDFKDUDFWHUV

:KHQ\RXZDQWDPHWDFKDUDFWHU127WREHLQWHUSUHWHG
E\WKHVKHOO\RXQHHGWRTXRWHLW
4XRWLQJDVLQJOHFKDUDFWHULVGRQHZLWKWKHEDFNVODVK ?
HFKR7KHDPRXQWLV86?
7KHDPRXQWLV86

4XRWLQJDVWULQJLVGRQHZLWKVLQJOH
RUGRXEOH  
TXRWHV
'RXEOHTXRWHVDOORZLQWHUSUHWDWLRQRIC EDFNWLFN 
DQG?
DPRXQW 
HFKR
7KHDPRXQWLVDPRXQW

7KHDPRXQWLVDPRXQW
HFKR7KHDPRXQWLVDPRXQW
7KHDPRXQWLV

Figure 10-23. Quoting Metacharacters LX023.0

Notes:
When you want a certain metacharacter NOT to be interpreted by the shell, you need to
quote it. Quoting prevents the shell from interpreting metacharacters.
There are three ways a metacharacter can be quoted:
• The first method is by putting a backslash (\) directly in front of the character to be
quoted. This ensures that the next character is passed onto the command without being
interpreted. (The backslash itself is a regular metacharacter, which can be quoted too.)
• The second method is by using single quotes ('). This assures that any metacharacter
within the quotes is being be passed onto the command without being interpreted. It is
useful if you've got a larger number of characters to quote.
• The last method is by using double quotes ("). This passes on any metacharacter within
the quotes onto the command, except for the dollar ($), the backtick (‘) and the
backslash (\). This allows you to use variables, command interpolation and quoting
non-metacharacters within a string.

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-27
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

4XRWLQJ1RQ0HWDFKDUDFWHUV

7KHEDFNVODVKFDQDOVREHXVHGWRJLYHDVSHFLDO
PHDQLQJWRDQRQPHWDFKDUDFWHU
)RULQVWDQFH
?Q QHZOLQH
?W WDE
?E EHOO
$EDFNVODVKIROORZHGGLUHFWO\E\(QWHULVXVHGIRUOLQH
FRQWLQXDWLRQ
7KHFRQWLQXHGOLQHLVLGHQWLILHGZLWKWKH36SURPSW
GHIDXOW! 

FDWKRPHMRKQP\GLUP\VXGLUGDWDLQIRUPDWLRQOHWWHU?
!SLFWXUHVORJRMSJ

Figure 10-24. Quoting Non-Metacharacters LX023.0

Notes:
The backslash character may also be used to give a special meaning to a
non-metacharacter. Some examples:
• \n will be expanded to a newline
• \t will be expanded to the tab character
• \b will be expanded to the bell sign.
A backslash directly followed by the Enter key is used for line continuation.

10-28 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
$OLDVHV

7KHDOLDVFRPPDQGDOORZV\RXWRVHWXSDOLDVHVIRU
RIWHQXVHGFRPPDQGV
([DPSOHV

DOLDVOO
OVO

DOLDVUP
UPL

7RVKRZDOOFXUUHQWO\GHILQHGDOLDVHV
DOLDV
7RGHOHWHDQDOLDV
XQDOLDVOO
OO
EDVKOOFRPPDQGQRWIRXQG

Figure 10-25. Aliases LX023.0

Notes:
The shell also supports aliases. An alias is typically a short letter combination which
expands into a far larger command. By making this large command an alias, you save
yourself a lot of typing, especially if you use that command a lot.
Aliases are defined with the alias command. To show all aliases, use the alias command
without an argument. To remove an alias, use the unalias command.
Most distributions define a number of aliases by default.

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-29
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&KHFNSRLQW

7)$ILOWHULVDFRPPDQGZKLFKUHDGVDILOHSHUIRUPV
RSHUDWLRQVRQWKLVILOHDQGWKHQZULWHVWKHUHVXOW
EDFNWRWKLVILOH

7KHRXWSXWRIWKHOVFRPPDQGLV
RQHWZRWKUHHIRXUILYH
VL[VHYHQHLJKWQLQHWHQ
:KDWZLOOWKHRXWSXWEHLI,UXQWKHOV"H FRPPDQG"
DWKUHHVHYHQWHQ
EVHYHQWHQ
FRQHWKUHHILYHVHYHQHLJKWQLQHWHQ
G"H 

Figure 10-26. Checkpoint LX023.0

Notes:

10-30 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
8QLW6XPPDU\

7KHVKHOOLVWKHFRPPDQGLQWHUSUHWHURI/LQX[
7KHGHIDXOWVKHOOLQ/LQX[LVEDVK
$VKHOOKDVDQXPEHURIDGGLWLRQDOIHDWXUHVVXFKDV
ZLOGFDUGH[SDQVLRQDOLDVH[SDQVLRQUHGLUHFWLRQ
FRPPDQGJURXSLQJYDULDEOHH[SDQVLRQ
0HWDFKDUDFWHUVDUHDQXPEHURIFKDUDFWHUVWKDWKDYHD
VSHFLDOPHDQLQJWRWKHVKHOO
5HVHUYHGZRUGVDUHZRUGVWKDWKDYHDVSHFLDOPHDQLQJ
WRWKHVKHOO

Figure 10-27. Unit Summary LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 10. Shell Basics 10-31
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

10-32 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 11. Linux Utilities

What This Unit Is About


This unit covers some of the more common command-line utilities in a
Linux system.

What You Should Be Able to Do


After completing this unit, you should be able to:
• Use the find and locate command to search for files
• Use the cut command to list specific columns of a file
• Use the grep command to search text files for patterns
• Use the head and tail commands to view specific lines in a file
• Use the sort command to sort the contents of a file
• Use the type, which and whereis commands to find commands
• Use the file command to find out the content of a file
• Use the join and paste commands to combine files
• Manipulate files with gzip, gunzip and zcat

How You Will Check Your Progress


Accountability:
• Checkpoint questions
• Machine exercises

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV
$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
8VHWKHILQGDQGORFDWHFRPPDQGWRVHDUFKIRUILOHV
8VHWKHFXWFRPPDQGWROLVWVSHFLILFFROXPQVRIDILOH
8VHWKHJUHSFRPPDQGWRVHDUFKWH[WILOHVIRUSDWWHUQV
8VHWKHKHDGDQGWDLOFRPPDQGVWRYLHZVSHFLILFOLQHVLQ
DILOH
8VHWKHVRUWFRPPDQGWRVRUWWKHFRQWHQWVRIDILOH
8VHWKHW\SHZKLFKDQGZKHUHLVFRPPDQGVWRILQG
FRPPDQGV
8VHWKHILOHFRPPDQGWRILQGRXWWKHFRQWHQWRIDILOH
8VHWKHMRLQDQGSDVWHFRPPDQGVWRFRPELQHILOHV
0DQLSXODWHILOHVZLWKJ]LSJXQ]LSDQG]FDW

Figure 11-1. Objectives LX023.0

Notes:

11-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KHILQG&RPPDQG

6HDUFKRQHRUPRUHGLUHFWRU\VWUXFWXUHVIRUILOHVWKDW
PHHWFHUWDLQVSHFLILHGFULWHULD
'LVSOD\WKHQDPHVRIPDWFKLQJILOHVRUH[HFXWH
FRPPDQGVDJDLQVWWKRVHILOHV

6\QWD[
ILQGSDWKH[SUHVVLRQ

Figure 11-2. The find Command LX023.0

Notes:
The find command recursively searches the directory tree for each specified path, seeking
files that match a Boolean expression.
The output of the find command depends on the terms specified by the final parameter.
The syntax of the command could be written down as:
find <from where> <search for> <do something to it>

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

6DPSOH'LUHFWRU\6WUXFWXUH

KRPH

MRH
EOXHV
SKRQH
SKRQH
SKRQH

FRORU VKDSH VL]H


EOXH ER[ ELJ
EURZQ FLUFOH JLDQW
JUHHQ SKRQH OLWWOH
VTXDUH VPDOO

Figure 11-3. Sample Directory Structure LX023.0

Notes:

11-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
8VLQJILQG

*HQHUDOO\\RXZDQWWRVHDUFKDGLUHFWRU\VWUXFWXUHIRU
ILOHVZLWKFHUWDLQQDPHVDQGOLVWWKHQDPHVIRXQG
FGKRPHMRH
ILQGQDPHSKRQH
VKDSHSKRQH
SKRQH

2QPDQ\RWKHU81,;V\VWHPVZLWKILQG\RXKDYHWRWHOO
LWVSHFLILFDOO\WRSULQWWKHQDPHVXVLQJSULQW
ILQGQDPHSKRQHSULQW
VKDSHSKRQH
SKRQH

Figure 11-4. Using find LX023.0

Notes:
Note that the directory search is recursive meaning that find will search the current
directory and all the subdirectories underneath it.
If not specified otherwise, the find command will match both directories and files.
The examples on the foil will search for all files with the name phone, starting in the current
directory (.).
Note that the -print option is the default and is not required. This was not always the case.
In UNIX versions that have not yet implemented the POSIX standard for the find
command, the -print option is required for the result to be displayed or used in a pipe.

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

([HFXWLQJ&RPPDQGVZLWKILQG

7KHH[HFRSWLRQH[HFXWHVDFRPPDQGRQHDFKRIWKHILOH
QDPHVIRXQG

ILQGQDPH
E
H[HFOVL^`?
 FRORUEOXH
 FRORUEURZQ
 VKDSHER[
 VL]HELJ
 EOXHV

^`LVDSODFHKROGHUIRUHDFKILOHQDPH7KHEDFNVODVK
HVFDSHVWKHIROORZLQJVHPLFRORQ

Figure 11-5. Executing Commands with find LX023.0

Notes:
The command following the -exec option, in this case the ls command, is executed for
each file name found. find replaces the {} with the names of the files matched. {} is used as
a placeholder for matches.
Note the use of the escaped ";" to terminate the command that find is to execute. The \; is
hard coded with the find command and is required for use with -exec and -ok options.
$ find . -name 'b*' -exec ls -l {} \;
is equivalent to
$ find . -name 'b*' -ls

11-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
,QWHUDFWLYH&RPPDQG([HFXWLRQ

7KHRNRSWLRQDOVRFDXVHVFRPPDQGH[HFXWLRQEXWRQ
DQLQWHUDFWLYHEDVLV

ILQGQDPHE? RNUP^`?
UPFRORUEOXH!"\
UPFRORUEURZQ!"\
UPVKDSHER[!"\
UPVL]HELJ!"\
UPEOXHV!"\

Figure 11-6. Interactive Command Execution LX023.0

Notes:
It is a good idea to use the -ok option rather than the -exec option if there are not a lot of
files that match the search criteria.

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

$GGLWLRQDOILQG2SWLRQV

W\SH I RUGLQDU\ILOH
G GLUHFWRU\
VL]H Q ODUJHUWKDQQEORFNV
Q VPDOOHUWKDQQEORFNV
QF HTXDOWRQFKDUDFWHUV
PWLPH [ PRGLILHGPRUHWKDQ[GD\VDJR
[ PRGLILHGOHVVWKDQ[GD\VDJR
[ PRGLILHG[GD\VDJR
SHUP RQXP DFFHVVSHUPLVVLRQVPDWFKRQXP
PRGH DFFHVVSHUPLVVLRQVPDWFKPRGH
XVHU XVHU ILQGVILOHVRZQHGE\XVHU
QHZHU UHIILOH ILOHZDVPRGLILHGPRUHUHFHQWO\
WKDQUHIILOH
R /RJLFDO25
D /RJLFDO$1'

Figure 11-7. Additional find Options LX023.0

Notes:
There are many other options to the find command, which are listed in the on-line
manuals.
Some options of find are:
-type allow searches for only files or only directories.
-size search for files that exactly match a size (-size 10), that are
more than a size (-size +10) or that are below a certain size
(-size -10). Size values are expressed in blocks.
-mtime search for files that have been modified in the time parameter
supplied. The times are in days relative to the current day plus
24 hours. The times can be an exact match, older or newer than
the time specified.
-perm search for files that have a certain permission mask (see
chmod).
-newer search for files that are newer than the reference file.

11-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty -o allow multiple conditions to be matched (find a or b).


-a require multiple conditions to be matched (find a and b)

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

ILQG([DPSOHV

ILQGSHUP
VL]HOLWWOH

)LOHPDWFKHVH[SUDQGH[SU
ILQGQDPH
V
W\SHIDVL]H?
!H[HFOVL^`?
VKDSHVTXDUH
VL]HVPDOO

)LOHPDWFKHVH[SURUH[SU
ILQGQDPHELJRQDPH
F

FRORU
VKDSHFLUFOH
VL]HELJ

Figure 11-8. find Examples LX023.0

Notes:
The first example searches for file names, not directory names, which are greater than
1024 bytes (2 blocks of 512 bytes). Once these have been found, the ls -i command will be
executed on them.
The second example will find all the files (files and directories) that have their permissions
set as 777 and were modified more than four days ago.
The third example will show you both files and directories that have big as a name or
whose name starts with a c.
The last example will show you all the files in the system that are owned by the user who is
stored in the variable $USER (probably the user who runs this command). The error
messages are redirected to the bit bucket.

11-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
ORFDWH&RPPDQG

ORFDWHDOORZV\RXWRTXLFNO\ILQGDILOHRQWKHV\VWHP
EDVHGRQVLPSOHFULWHULD

ORFDWHSDVVZG
XVUVKDUHPDQPDQSDVVZGJ]
XVUVKDUHPDQPDQSDVVZGJ]
HWFSDVVZG
XVUELQSDVVZG

5HTXLUHVWKDWWKHVXSHUXVHUUXQVXSGDWHGEUHJXODUO\
0RVWGLVWULEXWLRQVUXQXSGDWHGEDXWRPDWLFDOO\
6X6(GRHVQRWLQVWDOOORFDWHXSGDWHGEE\GHIDXOW

Figure 11-9. locate Command LX023.0

Notes:
The locate command also searches for files in the directory tree. There are two
differences, if you compare locate to find:
• locate can only work with very simple criteria.
• locate uses a database which was created earlier.
This means that locate is faster in use, but requires a little effort to set up: The superuser
has to run the updatedb command regularly (preferably every day or so) to keep the
database up to date. Most distributions are configured to run updatedb every night.

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHFXW&RPPDQG

3XOOVHOHFWHGFROXPQVRUILHOGVIURPRQHRUPRUHILOHV
6\QWD[
FXWI LHOGV G HOLPLWHU ILOH V
FXWF KDUDFWHUV ILOH V

Figure 11-10. The cut Command LX023.0

Notes:
The cut command is used to pull columns out of text files.
The content of a file determines what syntax you should use.
The first syntax can be used when there is a special character used to mark the columns.
The second syntax is used when the number of columns is not equal for each line.

11-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
FXW([DPSOH

FDWHWFSDVVZG
URRW[%LJ%URWKHUURRWELQEDVK
VKXWGRZQ[VKXWGRZQVELQVELQVKXWGRZQ
WX[[KRPHWX[ELQEDVK
WX[[KRPHWX[ELQEDVK

FXWIGHWFSDVVZG
URRWURRWELQEDVK
VKXWGRZQVELQVELQVKXWGRZQ
WX[KRPHWX[ELQEDVK
WX[KRPHWX[ELQEDVK

Figure 11-11. cut Example LX023.0

Notes:
/etc/passwd is divided into seven columns separated by a colon (:).
If you want to display only the first, sixth and seventh column, you could use the example
on the foil. With the -f option, you specify which columns you want to see, and the -d option
tells cut the delimiter between columns.
What would be the output of the following command:
$ cut -f1 -do /etc/passwd?
The output would be:
r
shutd
tux1:!:500:500::/h
tux2:!:501:501::/h
This syntax can only be used correctly if the file is divided into columns that are separated
with a special delimiter character.

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

FXW([DPSOH 

SV
3,'77<67$77,0(&200$1'
S6EDVK
S5SV

SV_FXWF
3,'&200$1'
EDVK
SV

Figure 11-12. cut Example (2) LX023.0

Notes:
In some files, the columns are not evenly divided among the lines. The output of ps is an
example of this. We see five columns, but what is the delimiter character between these
columns? We cannot say that a space is the delimiter because the first line has fewer
columns than the third and fourth lines.
If we run ps | cut -f5 -d" ", we would get this as output: Stat
In order to overcome this problem we cannot use the syntax that defines columns with
delimiters. Instead we have to tell cut what characters we want to see.
ps | cut -c-5,20- tells the cut command only to display the characters specified;
characters 1 to 5 and characters 20 and further.

11-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KHJUHS&RPPDQG

6HDUFKHVRQHRUPRUHILOHVRUVWDQGDUGLQSXWIRUOLQHV
PDWFKLQJSDWWHUQ

6LPSOHPDWFKRU5HJXODU([SUHVVLRQ

6\QWD[
JUHS>RSWLRQV@SDWWHUQ>ILOH@

Figure 11-13. The grep Command LX023.0

Notes:
The grep (Global Regular Expression Print) command searches for the pattern specified
and writes each matching line to standard output.
The search can be for simple text, like a string or a name. grep can also look for logical
constructs, called regular expressions, that use patterns and wildcards to symbolize
something special in the text. Only lines that start with an uppercase T, for example.
The command displays the name of the file containing the pattern if more than one file is
specified for the search.

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-15
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

JUHS6DPSOH'DWD)LOHV

3KRQH
$OOHW  LQWHUQ
-XGLWK  LQWHUQ
.HHV  H[WHUQ
/HR  H[WHUQ
1DQQLH  H[WHUQ
3HWHU  LQWHUQ

3KRQH
$OOHW  LQWHUQ
-XGLWK  LQWHUQ
.HHV  H[WHUQ
/HR  LQWHUQ
1DQQLH  LQWHUQ
3HWHU  H[WHUQ

Figure 11-14. grep Sample Data Files LX023.0

Notes:
This foil shows the sample files used to illustrate the examples that will follow.

11-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
%DVLFJUHS

JUHSSKRQH
-XGLWKLQWHUQ

JUHSSKRQH
SKRQH-XGLWKLQWHUQ
SKRQH-XGLWKLQWHUQ
SKRQH/HRLQWHUQ
SKRQH1DQQLHLQWHUQ
JUHSY-XGLWKSKRQH
$OOHWLQWHUQ
.HHVH[WHUQ
/HRLQWHUQ
1DQQLHLQWHUQ
3HWHUH[WHUQ

Figure 11-15. Basic grep LX023.0

Notes:
grep searches for the string given. If not specified otherwise, grep will not see the
difference between a whole word matching the pattern or just a portion of a word matching
the pattern.
The -v option reverses the working of grep: only lines that do not match are displayed.

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-17
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

JUHSZLWK5HJXODU([SUHVVLRQV

3DWWHUQVZLWKPHWDFKDUDFWHUVVKRXOGEHLQVLQJOHTXRWHV


VRWKDWWKHVKHOOZLOOOHDYHLWDORQH

9DOLGPHWDFKDUDFWHUVZLWKJUHS A>@
$Q\VLQJOHFKDUDFWHU
=HURRUPRUHRFFXUUHQFHVRIWKH
SUHFHGLQJFKDUDFWHU
>DI@$Q\21(RIWKHFKDUDFWHUVLQWKH
UDQJHDWKURXJKI
AD$Q\OLQHWKDWVWDUWVZLWKD
]$Q\OLQHWKDWHQGVZLWK]

Figure 11-16. grep with Regular Expressions LX023.0

Notes:
The purpose of regular expressions on lines is the same as wildcards for file names.
When a * is used with the grep command to specify a regular expression, it will match zero
or more occurrences of the previous character. If you want to use it to match zero or more
arbitrary characters, it should be preceded by a dot, which means any single character.
The following is a chart that compares grep metacharacters to the shells.

grep grep Interpretation shell shell Interpretation


^ begins a line ^ "old" bourne pipe symbol
$ ends a line $ variable
. any single character ? any single character
.* any number of any characters * any number of any characters
[-] single character range [-] single character range

11-18 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
5HJXODU([SUHVVLRQ

'LVSOD\DOOWKHSURFHVVHVWKDWEHORQJWRWX[

BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB

8VLQJJUHSZULWHFRPPDQGVWRVHOHFWWKHIROORZLQJOLQHV
IURPWKHSKRQHILOH
6HOHFWDOOWKHOLQHVRIWKHILOH EODQNDQGQRQEODQN

JUHSBBBBBBBBBBBSKRQH

6HOHFWDOOWKHOLQHVWKDWFRQWDLQDQHDQGHQGLQD

JUHSBBBBBBBBBBBSKRQH

Figure 11-17. Regular Expression LX023.0

Notes:
Answers:
1. To display all processes running on the system that belong to tux1, enter:
$ ps aux | grep tux1
2. Select all the lines of the file (blank and non-blank), enter:
$ grep '.*' phone1
3. Select all the lines that contain an e and end in a 0, enter:
$ grep 'e.*0$' phone1

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-19
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

JUHS2SWLRQV

Y 3ULQWOLQHVWKDWGRQRWPDWFK

F 3ULQWRQO\DFRXQWRIPDWFKLQJOLQHV

O 3ULQWRQO\WKHQDPHVRIWKHILOHVZLWKPDWFKLQJOLQHV

Q 1XPEHUWKHPDWFKLQJOLQHV

L ,JQRUHWKHFDVHRIOHWWHUVZKHQPDNLQJFRPSDULVRQV

Z 'RDZKROHZRUGVHDUFK
Figure 11-18. grep Options LX023.0

Notes:

11-20 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
2WKHUJUHSV

IJUHSDOORZVRQO\IL[HGVWULQJV QRUHJXODUH[SUHVVLRQV
HJUHSDOORZVIRUPXOWLSOH DOWHUQDWH SDWWHUQV

HJUHS
__
SKRQH
-XGLWK  LQWHUQ
/HR  H[WHUQ
1DQQLH  H[WHUQ

:KDWGRHVWKHIROORZLQJFRPPDQGGR"

JUHSSKRQH_JUHSLQWHUQ
""""""""

Figure 11-19. Other greps LX023.0

Notes:
egrep is slightly slower than normal grep because it allows you to "or" patterns together
using the "|". To match all the patterns against a line takes a little bit more time than just
matching one pattern.
fgrep is slightly faster because there is no interpretation that must take place first. Every
regular expression must be evaluated first and this takes a little bit of time.
The answer to the question on this foil is: Display all lines in phone1 that contain both the
string 30 and the string intern.
With a pipe from one grep to another, you can define an and-construct.

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-21
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHVRUW&RPPDQG

7KHVRUWFRPPDQGVRUWVWKHOLQHVLQWKHILOHVSHFLILHGDQG
ZULWHVWKHUHVXOWWRVWDQGDUGRXWSXW

VRUWW GHOLPLWHU ILHOGRSWLRQVILOH

FDWDQLPDOV
GRJ
FDW
SHQJXLQ

VRUWDQLPDOV
FDW
GRJ
SHQJXLQ

Figure 11-20. The sort Command LX023.0

Notes:
To specify a delimiter with sort, use the -t option. This option has the same function as the
-d option for cut. The -t option tells sort what character separates fields. This is often a :
(colon), \t (tab) or \n (new line) character.

11-22 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
VRUW([DPSOHV

VRUWDQLPDOV
FDW
SHQJXLQ
GRJ
VRUWWDQLPDOV
SHQJXLQ
GRJ
FDW
VRUWWQDQLPDOV
GRJ
FDW
SHQJXLQ

2SWLRQV
GVRUWVLQGLFWLRQDU\RUGHU2QO\OHWWHUVGLJLWVDQGVSDFHVDUH
FRQVLGHUHGLQFRPSDULVRQV
UUHYHUVHVWKHRUGHURIWKHVSHFLILHGVRUW
QVRUWVQXPHULFILHOGVLQDULWKPHWLFYDOXH

Figure 11-21. sort Examples LX023.0

Notes:
$ sort animals will sort the file animals on the first character of each line.
$ sort +0.1 animals will force a sort on the second character of each line.
$ sort -t. +1 animals forces sort to sort on the second (+1) column. Columns are
separated here with a dot. Be aware that sort will always try to perform an ASCII sort.
$ sort -t. -n +1 animals will perform a numeric sort on the second (+1) column.

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-23
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHKHDGDQGWDLO&RPPDQGV

7KHKHDGFRPPDQGFDQEHXVHGWRYLHZWKHILUVWIHZ
OLQHVRIDILOHRUILOHV7KHFRPPDQGV\QWD[LV
KHDG>OLQHV@ILOH V
KHDGP\ILOH
OVO_KHDG

7KHWDLOFRPPDQGGLVSOD\VWKHODVWIHZOLQHVRIDILOHRU
ILOHV7KHFRPPDQGV\QWD[LV
WDLO>^OLQHV_OLQHV_I`@ILOH V

WDLOILOH
WDLOILOH
WDLOIILOH

Figure 11-22. The head and tail Commands LX023.0

Notes:
The head command will show you the first ten lines of a file by default. You can change the
default by specifying a number to head.
The tail command can be used with either a positive or a negative number.
-no_of_lines indicates the number of lines to read beginning from the end of
the file. This will display the last n lines of the file. -15 means the
last 15 lines.
+no_of_lines indicates the number of the line where you want to start
displaying the lines. +15 means start at line 15.
The tail -f command can be used to monitor the growth of a file being written by another
process. The -f option causes the tail command to continue to read additional lines from
the input file as they become available.
For example:
tail -f logfile

11-24 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty will display the last ten lines of the logfile file. The tail command continues to display lines
as they are added to the logfile. The display continues until <Ctrl-c> is pressed.
The -f option of tail can only be used when you specify a file. It cannot be used when tail
has to read its input from STDIN.

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-25
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHW\SHZKLFKDQGZKHUHLV&RPPDQGV

7RILQGRXWZKDWWKHSDWKWRDFRPPDQGLVXVHW\SH
W\SHILQGHFKR
ILQGLVXVUELQILQG
HFKRLVDVKHOOEXLOWLQ

7RILQGRXWZKHUHWKHELQDU\LVORFDWHGXVHZKLFK
ZKLFKILQGHFKR
XVUELQILQG
ELQHFKR

7RORFDWHWKHELQDU\VRXUFHDQGPDQXDOSDJHILOHVRID
FRPPDQGXVHZKHUHLV
ZKHUHLVILQGHFKR
ILQGXVUELQILQGXVUPDQPDQILQG
HFKRELQHFKRXVUPDQPDQHFKR

Figure 11-23. The type, which and whereis Commands LX023.0

Notes:
What if you are writing a program that uses grep and you must include the full path name,
but you do not know where the command resides? The type command can tell you.
When you type the name of a command, the shell searches for the command in your
search path and runs the first one it finds. You can find out which copy of the program the
shell runs by using the type utility.
An alternative to type is which. This command only looks in your search path. Note the
different answers for echo. which does not know that echo is also a shell built-in. The
reason for this difference is that type is a shell built-in itself, and which is not.
To locate a command, try using the whereis command, which looks in a few standard
locations instead of using your search path. The whereis command will also display any
manual page and source code files found.
The type command also reports on shell built-ins whereas the whereis command doesn't.
A problem that could show up is shown on the foil. The type command tells you that the
echo command is a shell built-in, but the whereis command tells you that there is an

11-26 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty executable in /bin. The problem is that when you issue the echo command the built-in is
run and not the executable in /bin.

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-27
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHILOH&RPPDQG

:LWKWKHILOHFRPPDQG\RXFDQILQGRXWZKDWWKHW\SHRI
GDWDLQWKHILOHLV

ILOHHWFSDVVZGELQOVKRPHSHWHUWPSIDNHMSJ
HWFSDVVZG $6&,,WH[W
ELQOV (/)ELW/6%H[HFXWDEOH,QWHO
YHUVLRQG\QDPLFDOO\OLQNHGVWULSSHG
KRPHSHWHU GLUHFWRU\
WPSIDNHMSJ3')GRFXPHQWYHUVLRQ

Figure 11-24. The file Command LX023.0

Notes:
The file command can be used to determine the type of a file. This can be useful for a
couple of reasons. First, it can tell you what files are readable before you potentially hang
your screen by trying to display an executable file. Second, it can help you determine what
kind of binary file it is and what operating system version it was compiled under.
The file command uses the /usr/share/magic file to identify files that have some sort of
magic number; that is, any file containing a numeric or string constant that indicates the
type.
Using file on a non-existing file results in an error message stating that it could not get a file
status.
You could use the file command to find out if a command is a shell script or an executable.
To find out enter this:
$ file ‘which command‘

11-28 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KHJ]LSJXQ]LSDQG]FDW&RPPDQGV
7RFRPSUHVVRUXQFRPSUHVVILOHVXVHJ]LSJXQ]LSRU]FDW

OVOILOH
UZUZUWHDPWHDP$SUILOH
J]LSYILOH
ILOH UHSODFHGZLWKILOHJ]
OVOILOHJ]
UZUZUWHDPWHDP$SUILOHJ]
]FDWILOH
 RXWSXWLVWKHVDPHDVWKHRXWSXWRIWKHFDWFRPPDQGZLWK
WKHXQFRPSUHVVHGILOH
JXQ]LSILOH
OVOILOH
UZUZUWHDPWHDP$SUILOH

Figure 11-25. The gzip, gunzip, and zcat Commands LX023.0

Notes:
The gzip command compresses data, using the Lempel-Ziv coding (LZ77), to reduce the
size of files. A compressed file replaces each file with a .gz appended to its name. The
compressed file retains the same ownership, modes and modification time of the original
file.
If compression does not reduce the size of the file, a message is written to stderr and the
original file is not replaced.
The -v option writes the percentage of compression that took place.
The zcat command allows the user to expand and view a compressed file without
uncompressing that file first. It does not rename the expanded file or remove the .gz
extension. It simply writes the expanded output to stdout.
The gunzip command restores the original file that was compressed by the gzip
command. Each compressed file is removed and replaced by the expanded copy. The
expanded file has the same name as the compressed version without the .gz extension.
Files compressed with the compress command can also be uncompressed with gunzip.

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-29
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Depending on what packages you installed, the following commands may also be
available:
• zgrep
• zless
• zmore

11-30 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KHMRLQDQGSDVWH&RPPDQGV

MRLQDQGSDVWHFRPELQHILOHV

FDWRQH
DDSSOHDQRWKHU
EEHHEHDVW
FDWWZR
DDSH
EEURNHQ
MRLQRQHWZR
DDSSOHDQRWKHUDSH
EEHHEHDVWEURNHQ
SDVWHRQHWZR
DDSSOHDQRWKHUDDSH
EEHHEHDVWEEURNHQ

Figure 11-26. The join and paste Commands LX023.0

Notes:
The join and paste commands allow you to merge files together.

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-31
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&KHFNSRLQW
7)7KHFRPPDQGSVDX[_JUHSWX[_JUHSQHWVFDSH
OLVWVDOOQHWVFDSHSURFHVVHVRIDXVHUQDPHGWX[
:KLFKFRPPDQGZRXOGEHVWEHXVHGWRORFDWHDOOILOHV
LQ\RXUV\VWHPWKDWEHJLQZLWKWKHVWULQJWHDP"
DILQGQDPHAWHDP
EILQGQDPHWHDP 
FILQGQDPH WHDP 
GILQGW\SHIQDPHWHDP

7UDQVODWHWKHIROORZLQJFRPPDQGLQWR\RXUQDWLYH
ODQJXDJH
OVO5_HJUHSW[W_WDE_VRUWUQ_WDLO_KHDG

Figure 11-27. Checkpoint LX023.0

Notes:

11-32 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
8QLW6XPPDU\
7KHIROORZLQJFRPPDQGVZHUHFRQVLGHUHG
7KHILQGFRPPDQGLVXVHGWRUHFXUVLYHO\VHDUFK
GLUHFWRULHVIRUILOHVZLWKSDUWLFXODUFKDUDFWHULVWLFV
7KHJUHSFRPPDQGLVXVHGWRVHOHFWHQWLUHOLQHV
FRQWDLQLQJDSDUWLFXODUSDWWHUQ
7KHKHDGDQGWDLOFRPPDQGVDUHXVHGWRYLHZVSHFLILF
OLQHVLQDILOH
7KHVRUWFRPPDQGVRUWVWKHFRQWHQWVRIDILOHE\WKH
RSWLRQVVSHFLILHG
)LQGRXWZKHUH\RXFDQILQGFRPPDQGVZLWKW\SHZKHUH
DQGZKHUHLV
7KHJ]LS]FDWDQGJXQ]LSFRPPDQGVFDQEHXVHGWR
FUHDWHDQGZRUNZLWKFRPSUHVVHGILOHV

Figure 11-28. Unit Summary LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 11. Linux Utilities 11-33
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

11-34 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 12. Shell Scripting

What This Unit Is About


This unit introduces basic shell programming concepts.

What You Should Be Able to Do


After completing this unit, you should be able to:
• Invoke shell scripts in three separate ways and explain the
difference
• Pass positional parameters to shell scripts and use them within
scripts
• Implement interactive shell scripts
• Use conditional execution and loops
• Perform simple arithmetic

How You Will Check Your Progress


Accountability:
• Checkpoint questions
• Exercises

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
,QYRNHVKHOOVFULSWVLQWKUHHVHSDUDWHZD\VDQGH[SODLQ
WKHGLIIHUHQFH
3DVVSRVLWLRQDOSDUDPHWHUVWRVKHOOVFULSWVDQGXVHWKHP
ZLWKLQVFULSWV
,PSOHPHQWLQWHUDFWLYHVKHOOVFULSWV
8VHFRQGLWLRQDOH[HFXWLRQDQGORRSV
3HUIRUPVLPSOHDULWKPHWLF

Figure 14-1. Objectives LX023.0

Notes:

12-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
:KDWLVD6KHOO6FULSW"

$VKHOOVFULSWLVDFROOHFWLRQRIFRPPDQGVVWRUHGLQDWH[W
ILOH

SZG
GDWH
OVO

FDWVFULSW
SZG
GDWH
OVO


Figure 12-2. What is a Shell Script LX023.0

Notes:
A “shell script” basically is a collection of shell commands stored in a text file. This makes it
easier to repeat a sequence of commands and is especially handy for automating your
work.

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

,QYRNLQJ6KHOO6FULSWV 

7KHVFULSWGRHVQRWKDYHWREHPDUNHGH[HFXWDEOHEXW
PXVWEHUHDGDEOH
EDVKLQYRNHVDVFULSWLQDFKLOGVKHOO

FDWVFULSW
GDWH
EDVKVFULSW

6WDUWRIVXEVKHOO

5XQQLQJDFRPPDQGIURPVFULSW
EDVK

EDVK

GDWH

Figure 12-3. Invoking Shell Scripts (1) LX023.0

Notes:
There are three ways of invoking a shell script. The visual shows the first method. With this
method, a bash subshell is started with the scriptname as argument. Obviously for this to
work, the script needs to be readable. It does not have to be executable however, nor does
it have to be in the $PATH.
With this method, the script is executed within the shell that was started. This means that
any environment variable changes will be not be propagated to the initial shell.

12-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
,QYRNLQJ6KHOO6FULSWV 

8VHWKHFKPRGFRPPDQGWRPDNHWKHVFULSWH[HFXWDEOH
7KHQUXQWKHVFULSWDVLILWZHUHDFRPPDQG
7KHVFULSWLVUXQLQDFKLOGVKHOO
FKPRGVFULSW
VFULSW

6WDUWRIVXEVKHOO

5XQQLQJDFRPPDQGIURPVFULSW
EDVK

EDVK

GDWH

Figure 12-4. Invoking Shell Scripts (2) LX023.0

Notes:
The second method of invoking a shell script is by making it executable with chmod. This
allows you to call the script directly. As with the first method, the script is executed in a
subshell and thus any changes to environment variables will not be propagated to the initial
shell.
If you make sure that the script is located somewhere in your $PATH, then you can invoke
the script with just its scriptname. If the script is not in your $PATH, then you have to invoke
it with its relative or absolute pathname.

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

,QYRNLQJ6KHOO6FULSWV 

8VHWKH GRW RUVRXUFHFRPPDQGWRH[HFXWHWKHVFULSW


LQ\RXUFXUUHQWVKHOOHQYLURQPHQW
6FULSWVH[HFXWHGZLWKWKHGRWFRPPDQGFDQFKDQJH\RXU
FXUUHQWHQYLURQPHQW

VFULSW
VRXUFHVFULSW

WKHGDWHFRPPDQGLVLQYRNHG
E\\RXUFXUUHQWVKHOO

EDVK
VFULSW
GDWH

Figure 12-5. Invoking Shell Scripts (3) LX023.0

Notes:
The third method is by invoking the script using the . (dot) or source command. In this
case, the script is executed in the current shell. This means that the script will be able to
make changes to environment variables in the current shell.

12-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
,QYRNLQJ6KHOO6FULSWV,Q$QRWKHU6KHOO

7RPDNHVXUHWKHVKHOOVFULSWDOZD\VUXQVLQWKHVKHOO
ZKHUHLWZDVLQWHQGHGIRU VKEDVKFVK XVHWKH
IROORZLQJRQWKHILUVWOLQHRI\RXUVFULSW
ELQEDVK
7KHVFULSWQRZDOZD\VUXQVLQEDVK
(YHQLIWKHXVHUVGHIDXOWVKHOOLVVRPHWKLQJHOVH
:LWKWKLVWKH GRW QRWDWLRQWRLQYRNHDVKHOOVFULSWZLWKLQ
WKHFXUUHQWVKHOOLVQRORQJHUSRVVLEOH

Figure 12-6. Invoking Shell Scripts In Another Shell LX023.0

Notes:
A shell is a very personal choice. Under Linux, most people prefer the bash shell, but
people from an AIX background might prefer the pdksh, and C programmers might prefer
the csh. If your script was written for the bash shell and contains bash-specific commands
or constructs, you might want to make sure that the script is always invoked in a bash
shell. This is done by adding the following line on top:
#!/bin/bash
When a shell - any shell - encounters a shell script that starts with the magic marker ‘#!’,
then it knows that this script is to be executed using the command that follows the magic
marker, in our case /bin/bash.
The same magic marker can also be used to identify perl scripts (‘#!/usr/bin/perl’), awk
scripts (‘#!/usr/bin/awk’) and so forth.
There is one disadvantage: a shell script which starts like this will always be executed in a
subshell. It is therefore no longer possible to invoke this script with . (dot) or source so that
the script is able to modify environment variables in the initial shell.

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7\SLFDO6KHOO6FULSW&RQWHQWV

+DQGOLQJRIVKHOOVFULSWDUJXPHQWV
&RPSOH[5HGLUHFWLRQ
&RQGLWLRQDO([HFXWLRQ
5HSHDWHG([HFXWLRQ
8VHU,QWHUIDFLQJ
$ULWKPHWLF

Figure 12-7. Typical Shell Script Contents LX023.0

Notes:
As said, a shell script is nothing more than a series of shell commands. Any shell command
can be used in a shell script and vice versa. Having said that, there are a few things which
are typically only found in shell scripts because using them on the command line would be
silly or overly complicated. The rest of the unit is coverage of these things.

12-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
6KHOO6FULSW$UJXPHQWV

3DUDPHWHUVFDQEHSDVVHGWRVKHOOVFULSWVDVDUJXPHQWV
RQWKHFRPPDQGOLQH
7KHVHDUJXPHQWVDUHVWRUHGLQVSHFLDOVKHOOYDULDEOHV
UHIHUWRHDFKRIWKHDUJXPHQWV
#LV
 LV
LVWKHQXPEHURISDUDPHWHUV
FDWDVFULSW
ELQEDVK
HFKR)LUVWSDUDPHWHU
HFKR6HFRQGSDUDPHWHU
HFKR1XPEHURISDUDPHWHUV
DVFULSWWZRRQH
)LUVWSDUDPHWHUWZR
6HFRQGSDUDPHWHURQH
1XPEHURISDUDPHWHUV

Figure 12-8. Shell Script Arguments LX023.0

Notes:
Arguments, also called “positional parameters” can be passed to shell scripts when the
shell script is invoked. Within the shell script, they are available as special shell variables:
• The positional parameters themselves are available as $1, $2, $3 and so forth.
Positional parameters after number 9 must be referenced using the curly braces { } and
a number, like ${10}.
The curly brace notation for numbers above 9 is rarely used, since large numbers of
parameters are typically handled using the shift command, which we will discuss later.
• The amount of positional parameters is stored in $#.
• All positional parameters are stored in $@ and $*. The only difference is the way they
are stored:
$@ is equal to “$1” “$2” “$3”...
$* is equal to “$1 $2 $3...”

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

The difference is important when using $@ and $* as parameters for another


command.

12-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&RPSOH[5HGLUHFWLRQ

7RUHGLUHFWIL[HGWH[WLQWRDFRPPDQGXVH(1'
FDW(1'!FLWLHV
$PVWHUGDP
5RWWHUGDP
(1'

7RDYRLGODUJHDUJXPHQWOLVWVXVH[DUJV
UP W[W
EDVKELQUP$UJXPHQWOLVWWRRORQJ
ILQGQDPH W[W_[DUJVUP


$YRLGVODUJHDUJXPHQWOLVWVE\UXQQLQJWKHFRPPDQG
PXOWLSOHWLPHVLIQHFHVVDU\

Figure 12-9. Complex Redirection LX023.0

Notes:
In the previous units we’ve already seen redirection using >, >> and <. This allows us to
redirect input and output to a file. But what if we want to input some static content to a
command? In that case we can use the << operator. This allows us to specify the input to a
command on the lines that follow that command in our script, until we reach the specified
delimiter. In the visual above, the content of the file cities would be:
Amsterdam
Rotterdam
"END" is the delimiter string. It will not be included in the file. Note that this delimiter should
start at the start of a new line. It is not allowed to put any characters (including spaces) in
front of the delimiter.
Another form of complex redirection is the xargs command. It is used to avoid the situation
where a command such as cat ‘ls *.txt‘ would possibly dump so many filenames onto the
argument list of cat that certain limits would be exceeded. With xargs, the arguments to
use are fed from stdin, which can handle unlimited input, and the command to execute is
executed as many times as necessary, without ever reaching shell limits. Furthermore,

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

xargs has a large number of options that determine how the final command(s) will actually
be formatted. For more information, see its manual page.

12-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&RQGLWLRQDO([HFXWLRQ

7KHUHWXUQFRGHIURPDFRPPDQGRUJURXSRIFRPPDQGV
FDQEHXVHGWRGHWHUPLQHZKHWKHUWRVWDUWWKHQH[W
FRPPDQG

GR
WKLV
LI FRPPDQG V
H
WUX
FRPPDQG V
IDO
VH
WKDW
UHWXUQV
FRPPDQG V

Figure 12-10. Conditional Execution LX023.0

Notes:
Conditional execution means that the execution of a command or block of commands is
dependent on the return code of another command.
There are two ways of making commands conditional:
• If you need to make one command conditional, then you can use the && or || notation.
• If you need to make a block of commands conditional, then you can use the if then else
fi notation.
In most cases, the return code to test is actually generated by the test command, which is
a really versatile command for testing for files, strings, variables and so forth.

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHWHVW&RPPDQG

7KHWHVWFRPPDQGDOORZV\RXWRWHVWIRUDJLYHQ
FRQGLWLRQ
6\QWD[
WHVWH[SUHVVLRQRU>H[SUHVVLRQ@
WHVWIP\ILOHW[W
HFKR"


([SUHVVLRQVWRWHVWILOHVWDWXV
IILOH! ILOHLVDQRUGLQDU\ILOH
GILOH! ILOHLVDGLUHFWRU\
UILOH! ILOHLVUHDGDEOH
ZILOH! ILOHLVZULWDEOH
[ILOH! ILOHLVH[HFXWDEOH
VILOH! ILOHKDVQRQ]HUROHQJWK
Figure 12-11. The test Command LX023.0

Notes:
The test command can be invoked in two ways:
test expression
[ expression ]
It doesn't matter which syntax you use. It is a question of taste and personal preference.
Various expressions are possible. This visual and the next lists a few of them.

12-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KHWHVW&RPPDQG 

6WULQJWHVWV
QVWULQJ! VWULQJLVQRWHPSW\
]VWULQJ! VWULQJLVHPSW\
VWULQJ! VWULQJ! VWULQJVDUHHTXDO
VWULQJ! VWULQJ! VWULQJVDUHQRWHTXDO

$ULWKPHWLFWHVWV
YDOXH!HTYDOXH! HTXDOV
YDOXH!QHYDOXH! QRWHTXDO
YDOXH!OWYDOXH! OHVVWKDQ
YDOXH!OHYDOXH! OHVVWKDQRUHTXDO
YDOXH!JWYDOXH! JUHDWHUWKDQ
YDOXH!JHYDOXH! JUHDWHUWKDQRUHTXDO

Figure 12-12. The test Command (2) LX023.0

Notes:
The visual lists some more examples of test expressions. Remember that in each and
every case the return value of the test command ($?) is set to 0 if the test is positive, and 1
if the test is negative.
Another thing to remember is to surround all your variables you use in a test expression
with double quotes. As an example, consider what would happen with the following
command:
test $VAR == "test"
If $VAR is not empty, then the test is carried out and the return code is set to 0 or 1,
depending on whether $VAR actually contained the word test or not. But if $VAR happens
to be empty or not defined, then the shell changes this statement into:
test == "test"
This statement is obviously incorrect, since the == operator needs two arguments, and
receives only one. In this case, test will give you a syntax error, and a return code of 2.
This could easily be prevented by using the following syntax:

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-15
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

test "$VAR" == "test"


Now, if $VAR is empty or not defined, the statement will be changed into:
test "" == "test"
This is a legal syntax. Obviously the return code is 1.

12-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KH DQG__FRPPDQGV

DQG,, YHUWLFDOEDUV FDQEHXVHGWRFRQGLWLRQDOO\


H[HFXWHDVLQJOHFRPPDQG

FRPPDQG FRPPDQG
LI FRPPDQGVXFFHVVIXO WKHQGR FRPPDQG

FRPPDQG__FRPPDQG
LI FRPPDQGQRWVXFFHVVIXO WKHQGR FRPPDQG

>IWHVWILOH@ UPWHVWILOH
>IORFNILOH@__WRXFKORFNILOH
>7(50 [WHUP@ HFKR7KLVLVQRWW\
FDWGRHVQRWH[LVW!GHYQXOO__HFKR?
!2KER\WKLVILOHGRHVQRWH[LVW

Figure 12-13. The && and || Commands LX023.0

Notes:
The first way of conditionally executing commands is by using the && and || operators.
These operators allow a single command to be executed, depending on the return code of
another single command.

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-17
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHLI&RPPDQG

7KHVWUXFWXUHRIWKHEDVLFLIVWDWHPHQWLV
LIVWDWHPHQWLVWUXH
WKHQ
FDUU\RXWWKLVVHWRIDFWLRQV
HOVH
FDUU\RXWWKLVVHWRIDFWLRQV
IL

FDWP\VFULSW
LI>0<B9$/8(HT@
WKHQ
HFKR0<B9$/8(FRQWDLQVWKHYDOXH
HOVH
HFKR0<B9$/8(LVQRW

IL


Figure 12-14. The if Command LX023.0

Notes:
The if then else fi construct allows you to execute multiple commands, based on the return
code of a command.
You do not always need an else statement, but you may use only one within an if
statement.
command1 && command2
is the same as
if command1
then
command2
fi
but the if statement is usually more readable, especially if there are a lot of commands to
be executed.

12-18 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&RPPDQG5HSHWLWLRQ

$ORRSLVDVHWRIFRPPDQGVWKDWLVH[HFXWHGRYHUDQG
RYHU
8QWLORUZKLOHDFHUWDLQFRQGLWLRQLVWUXH
2UIRUHDFKLWHPIURPDOLVW

FRPPDQG LIFRQGLWLRQ!LVWUXH
UHSHDWWKLVVHWRI
FRPPDQG FRPPDQGV
FRPPDQG

LIFRQGLWLRQ!LVIDOVH
OHDYHWKLVVHWRI
FRPPDQGV

Figure 12-15. Command Repetition LX023.0

Notes:
A "loop" is the programmers term for a set of commands that is executed over and over
again. Loops in the bash shell can be of these two forms:
• Loops that run until or while a certain condition is true
• Loops that are executed for each item of a list

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-19
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

7KHZKLOH&RPPDQG

7KHV\QWD[RIWKHZKLOHFRPPDQG

ZKLOHH[SUHVVLRQLVWUXH
GR
FRPPDQG V
GRQH
FDWP\ORRS
ZKLOHWUXH
GR
HFKR,W
VQRZ GDWH 
HFKR7KHUHDUHCSVDX[_ZFOCSURFHVVHV
VOHHS
GRQH


1RWHWKDWWKHH[SUHVVLRQWUXHLVDOZD\VWUXH

Figure 12-16. The while Command LX023.0

Notes:
The while loop will be executed only while the expression evaluates true. By using the true
argument with the while command, it forces the set of commands to be executed until the
script is interrupted, for instance, with <Ctrl-c>.
The sleep command suspends execution of a process for the specified number of
seconds.
The expression used in the while loop can be any command, but in practice it is most often
a test command, just like with if.

12-20 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KHIRU&RPPDQG

7KHVWUXFWXUHWKHIRUORRSLV

IRULGHQWLILHULQOLVW
GR
FRPPDQG V WREHH[HFXWHGRQLGHQWLILHU
GRQH
FDWP\BIRUORRS
IRUILOHLQWPSPLQHB
GR
FSILOHRWKHUBGLUILOH
GRQH


Figure 12-17. The for Command LX023.0

Notes:
The for command sets the identifier variable to each of the values from the list in turn and
executes the command block. Execution ends when the list is finished.
In the given example, the list for the for command has been formed by metacharacter
expansion into the file names in the /tmp directory.
Other examples are:
for fruit in Apple Pear Banana
do
echo I would like a $fruit
done
and
for file in ‘find /home -perm 777‘
do
echo Dangerous File Permissions on $file
done

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-21
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

6KLIWLQJ6KHOO6FULSW$UJXPHQWV

,I\RXH[SHFWDODUJHQXPEHURIVKHOODUJXPHQWV IRU
H[DPSOHILOHQDPHV XVHWKHVKLIWFRPPDQGLQDZKLOH
ORRSWRKDQGOHWKHPDOO
OLVWRIDUJXPHQWVDUJ DUJDUJDUJDUJ FRXQW
9DULDEOHV       
DIWHUILUVWORRS GHO   
DIWHUVHFRQGORRSGHOGHO     

FDWPDNHBEDFNXS
ZKLOH>JW@
GR
FSEDN
VKLIW
GRQH


Figure 12-18. Shifting Shell Script Arguments LX023.0

Notes:
while and for loops are typically used to evaluate a large number of command line
arguments. Shell scripts with a large number of arguments are typically shell scripts that
are called with wildcards. In that case, the number of arguments is unpredictable and can
easily exceed a hundred.
There are basically two methods of evaluating such a large number of arguments: by using
a for loop and by using a while loop. The for loop is the easiest and therefore not shown in
the visual. It would look like this:
for file in $@
do
cp $file $file.bak
done
Evaluating a large number of command line arguments using the while loop generally
involves the shift command. This command "shifts" the arguments up with one:
• $1 is deleted

12-22 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty • $2 is copied to $1, $3 is copied to $2 and so forth


• $# is decreased by one
So the basic construct works like this: As long as $1 is not empty, perform the operations
on $1 and then execute the shift command. The visual shows how this is implemented in
bash.
Although the while construct looks a little more complicated than the for construct, it is
used more often for handling large numbers of command line arguments. The reason for
this is that it gives far more flexibility. As an example, your script might accept a number of
options too. These should first be evaluated, possibly within a while construct, and then the
arguments should be evaluated, again in their own while construct.

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-23
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

8VHU,QWHUDFWLRQ7KHUHDG&RPPDQG

7KHUHDGFRPPDQGUHDGVRQHOLQHIURPVWGLQDQG
DVVLJQVWKHYDOXHVUHDGWRDYDULDEOH

FDWGHOILOH
ELQEDVK
8VDJHGHOILOH
HFKR3OHDVHHQWHUWKHILOHQDPH
UHDGQDPH
LI>IQDPH@
WKHQ
UPQDPH
HOVH
HFKRQDPHLVQRWDQRUGLQDU\ILOH
HFKRVRLWLVQRWUHPRYHG
IL

Figure 12-19. User Interaction: The read Command LX023.0

Notes:
The read command can be used to set more than one variable with a value. If more than
one argument is given, the first argument would be assigned to the first variable name
specified. The second argument would be assigned to the second variable and so on until
the last argument is reached.
If there are more arguments supplied than variable names defined, the last variable name
is given the value of all remaining arguments.
Usage is by standard programming convention. In this example, the usage statement is
preceded by a #, which indicates that it is a comment.
The example does not test for the file permissions. This would also have to be in effect.

12-24 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
$ULWKPHWLF

7KHEDVKVKHOOFDQSHUIRUPVLPSOHDULWKPHWLFRQLQWHJHUV
XVLQJWKHEXLOWLQOHWFRPPDQGRUWKH H[SU QRWDWLRQ
2SHUDWRUV 

OHW[ 
HFKR[

HFKR 

OHW[  
HFKR[

OHW[  
HFKR[

[     

Figure 12-20. Arithmetic LX023.0

Notes:
The bash shell allows you to do simple arithmetic using the let command. An alternative
notation for this command is the $(( )) notation.
The let command and the $(()) notation only works on integers and is limited by certain
bounds, because it uses a "signed long int" variable type for internal representation. This
means that, depending on the hardware architecture, the lowest number that can be stored
is -231 or -263 , and the highest number is 231 -1 or 263 -1.
The operators that can be used are:
• *, for multiplications
• /, for division (results are rounded down to the nearest integer)
• +, for addition
• -, for subtraction
• %, for the remainder of a division
• ( and ), for argument grouping

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-25
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

According to the POSIX standard, arithmetic is done before wildcard expansion and
command grouping. Because of this, the (, ) and * characters do not need to be escaped,
independent of whether you are using let or $(()). However, experience has shown that not
all versions of bash correctly implement this. If you want to be safe, make sure you
surround your expression with double quotes.
Also, make sure that any shell variables you use indeed contain integers: they should only
contain the digits 0-9.

12-26 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KHH[SU&RPPDQG

,I\RXUVKHOOGRHVQRWVXSSRUW RUOHWWKHQXVHWKH
H[SUFRPPDQGIRULQWHJHUDULWKPHWLF
1RWDVKHOOEXLOWLQVRDERXWWLPHVVORZHU
6DPHRSHUDWRUVDVOHW
HFKRCH[SUC


%HZDUHRIWKHVKHOOPHWDFKDUDFWHUV  DQG 
H[SU  
EDVKV\QWD[HUURUQHDUXQH[SHFWHGWRNHQC 
H[SU? ? ?


Figure 12-21. The expr Command LX023.0

Notes:
Not all shells support the built-in let command or the $(( )) notation. In that case, you will
have to use the expr command. This is not a shell built-in and thus takes time to start. In
practice, a script which does a lot of arithmetic is about 10 times slower when it has to use
expr.
The usage of expr differs slightly from let, because expr cannot do assignments to
environment variables directly. Instead, it prints the output of an arithmetic expression on
stdout. This output can then be assigned to a variable by command interpolation.
Just as with let, expr also suffers from the drawback that it can only do calculations on
integers, and has to stay within certain bounds (depending on the architecture and the
version of expr) to work properly.

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-27
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&RPPDQG6HDUFK2UGHU

5HVHUYHG
4XDOLILHG :RUG
SDWKQDPH

$OLDV

%XLOWLQ
FRPPDQG

)XQFWLRQ 3$7+
YDULDEOH

Figure 12-22. Command Search Order LX023.0

Notes:
You can see where the shell looks for the commands to be executed when it is ready.
Reserved words are those words that have a special meaning to the shell, such as: if, then,
else, while, and so forth.
Aliases are set and managed with the alias and unalias commands.
Built-in commands are those commands that are part of the shell. Examples include: cd,
umask, read and echo. If you cannot find a command in the manual pages, try searching in
the manual page of the bash shell.
Functions have not been covered in this unit. They can be thought of as shell scripts within
shell scripts.
The PATH variable is the last thing searched.

12-28 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&KHFNSRLQW

 :KDWZLOOWKHIROORZLQJSLHFHRIFRGHGR"
7(507<3( 7(50
LI>Q7(507<3(@
WKHQ
 LI>IKRPHWHDPFXVWRPBVFULSW@
 WKHQ
 KRPHWHDPFXVWRPBVFULSW
 HOVH
 HFKR1RFXVWRPVFULSWDYDLODEOH
 IL
HOVH
 HFKR<RXGRQ
WKDYHD7(50YDULDEOHVHW
IL

Figure 12-23. Checkpoint LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-29
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&KHFNSRLQW 

 :ULWHDVFULSWWKDWZLOOPXOWLSO\DQ\WZRQXPEHUV
WRJHWKHU

Figure 12-24. Checkpoint (2) LX023.0

Notes:

12-30 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
8QLW6XPPDU\

3RVLWLRQDO3DUDPHWHUVDUHXVHGWRSDVVWRVFULSWVWKH
YDOXHVRIYDULDEOH
7RWHVWIRUDSDUWLFXODUFRQGLWLRQWKHWHVWFRPPDQGFDQ
EHXVHG7KLVIHDWXUHLVIUHTXHQWO\FRXSOHGZLWKWKHLI
VWDWHPHQWWRFRQWUROWKHIORZRIDSURJUDPDQGDOORZIRU
FRQGLWLRQDOH[HFXWLRQZLWKLQVFULSWV
7KHUHDGFRPPDQGFDQEHXVHGWRLPSOHPHQWLQWHUDFWLYH
VFULSWV
7KHZKLOHDQGIRUFRPPDQGVDUHXVHGWRFUHDWHORRSVLQ
DVFULSW

Figure 12-25. Unit Summary LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 12. Shell Scripting 12-31
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

12-32 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 13. The Linux GUI

What This Unit Is About


This unit gives an introduction to the GUI that is used by Linux.

What You Should Be Able to Do


After completing this unit, you should be able to:
• List the main components of the X Window System
• List the function of the X Server
• List the function of a Window Manager
• List the main characteristics of Desktop Environments
• Switch between GNOME and KDE

How You Will Check Your Progress


Accountability:
• Checkpoint questions
• Machine exercises

© Copyright IBM Corp. 2001, 2003 Unit 13. The Linux GUI 13-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
/LVWWKHPDLQFRPSRQHQWVRIWKH;:LQGRZ6\VWHP
/LVWWKHIXQFWLRQRIWKH;6HUYHU
/LVWWKHIXQFWLRQRID:LQGRZ0DQDJHU
/LVWWKHPDLQFKDUDFWHULVWLFVRI'HVNWRS(QYLURQPHQWV
6ZLWFKEHWZHHQ*120(DQG.'(

Figure 13-1. Objectives LX023.0

Notes:

13-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KH/LQX[*UDSKLFDO8VHU,QWHUIDFH

7KH;:LQGRZ6\VWHPLVWKH*8,RI/LQX[
'HYHORSHGDW0,7LQ
&XUUHQWVWDQGDUGVERG\;&RQVRUWLXP
6KRUWQDPH;
;XVHVFOLHQWVHUYHUPRGHOZLWKQHWZRUNFRQQHFWLRQV
+LJKO\IOH[LEOH
(DV\H[FKDQJHRIFRPSRQHQWV
6XSSRUWVQHWZRUNHGDSSOLFDWLRQVDQGVHVVLRQV
LQGHSHQGHQWRIWKH26

Figure 13-2. The Linux Graphical User Interface LX023.0

Notes:
The X Window System, called X for short, is a network-based graphics system that was
developed at the Massachusetts Institute of Technology (MIT) in 1984. In 1985, MIT
released X (version 9) to the public, license free. It was designed as a generic,
UNIX-oriented basis for graphical user interfaces (GUIs). Prior to X, the only way to
communicate with a UNIX system was using commands in an ASCII environment.
In 1987, a group of vendors and researchers formed the X-Consortium to continue work on
this windowing system. X version 11 (X11) was released in 1987, and continues to be the
version of X that is used. There have been several releases of X, the most current being
release 6 (1994), better known as X11R6.
Linux doesn't use the original X Window System but an implementation called XFree86.
X is an open standard which heavily uses standard TCP/IP network connections. This
makes it ideal in a mixed UNIX/Linux environment, since it allows applications written for
and running on Linux to display their windows on any other X-capable system. In fact,
applications exist that are able to capture MS-Windows application windows and display
them on an X capable workstation over a network connection.

© Copyright IBM Corp. 2001, 2003 Unit 13. The Linux GUI 13-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&OLHQW6HUYHU$UFKLWHFWXUH

;:LQGRZ6\VWHP6HUYHU

:LQGRZ
$SSOLFDWLRQ $SSOLFDWLRQQ
0DQDJHU

Figure 13-3. Client/Server Architecture LX023.0

Notes:
The X Window System uses a client/server architecture, which makes it very flexible. The
central piece of software is the X Server. The X Server traps all keyboard and mouse
events and sends them to the appropriate application. If an application wants to put
something on the screen, it sends that data to the X Server, which then performs the
necessary hardware calls to the graphical adapter.
Any application can connect to the X Server, but there should always be one special
application active: the window manager. The window manager basically puts a border
around each application window and allows you to drag windows around. Another task of
the window manager is to allow you to resize windows.
There are numerous window managers available, each with its own style. The most
popular window managers are the window managers that come with the GNOME and KDE
projects (discussed later), but other window managers may also be present or can be
downloaded from the Internet: fvwm, fvwm95, twm, mwm, olvwm, afterstep and so forth.

13-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
;&RPSRQHQWV

$Q;6HUYHU
&RQWUROVNH\ERDUGPRXVHDQGRQHRUPRUHVFUHHQV
&RQWUROVUHVROXWLRQUHIUHVKUDWHDQGFRORUGHSWK
$OORZVVLPXOWDQHRXVDFFHVVE\VHYHUDOFOLHQWV
3HUIRUPVEDVLFJUDSKLFRSHUDWLRQV
)RUZDUGVNH\ERDUGDQGPRXVHHYHQWVWRWKHFRUUHFW
FOLHQWV
$Q;&OLHQW
,VIRULQVWDQFHDQDSSOLFDWLRQ
5HFHLYHVNH\ERDUGDQGPRXVHLQSXWVIURPVHUYHU
6HQGVRXWSXWWREHGLVSOD\HGWRVHUYHU
$:LQGRZ0DQDJHU
,VDVSHFLDO;&OLHQW
3HUIRUPVZLQGRZVGUHVVLQJRQRWKHUFOLHQWV
$OORZVRWKHUFOLHQWZLQGRZVWREHPRYHGLFRQLILHGDQG
VRIRUWK
Figure 13-4. X Components LX023.0

Notes:
The central component in any X configuration is the X server. This is a piece of software
which handles the low-level complexities of controlling a keyboard, mouse, graphical
adapter and monitor. One of the most important configuration choices that need to be made
while configuring this server is the resolution, the monitor refresh rate and the color depth.
When the X server is running, all keyboard and mouse events are received and forwarded
to the appropriate X clients (X clients identify to the server all the events they're interested
in). If the client wants to send output to the screen, then the X server ensures that it actually
appears on the screen.
X clients are the applications that the user started, or that are started by the system by
default. If an application is activated by the user (usually by clicking on it), it will be sent all
relevant keyboard and mouse events, and can react to it. If the client wants to output
something, then it sends these requests to the server, which displays them.
A special client is the window manager. This client usually does not have its own window,
but displays the borders around other windows, and thus ensures that windows can be
resized, moved and iconified.

© Copyright IBM Corp. 2001, 2003 Unit 13. The Linux GUI 13-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

The window manager is usually the first client that is started, and it may start other clients in
turn, if configured. Typical applications that are started by the window manager are task
bars1, launchers2, pagers3 and so forth.

1
A task bar is an area which shows all applications that are currently running.
2
A launcher allows you to start other applications, usually by using some sort of menu structure and/or start button.
3 A pager allows you to use multiple, virtual desktops. An application is only visible in one desktop, except for the pager, which is visible

in all desktops. This allows you to work with multiple windows easily.

13-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
;6HUYHUVLQ/LQX[

0RVWGLVWULEXWLRQVXVH;)UHH ZZZ[IUHHRUJ DV


WKHLU;6HUYHU
2SHQ6RXUFH
6XSSRUWVPRVWYLGHRDGDSWHUV
2WKHU;6HUYHUVIRU/LQX[DUHDYDLODEOHDVZHOO
0HWUR; KWWSZZZPHWUROLQNFRP
;L*UDSKLFV KWWSZZZ[LJFRP


Figure 13-5. X Servers in Linux LX023.0

Notes:
Most Linux distributions ship the XFree86 X Server by default. This open source product
supports most video adapters by default4.
Although XFree86 is a good choice in most situations, it is not always the optimum solution.
There is a niche market for a number of commercial X servers as well, the most important
of which are Metro-X and Xi Graphics.

4
XFree86 does not support video adapters of which the specifications are not known, or can only be obtained by signing a
Non-Disclosure Agreement (NDA). This was a big problem some years ago, when some of the biggest manufacturers of video adapter
cards did not disclose their specifications. Most manufacturers have changed their strategy now and disclose their specifications in full,
allowing them to be supported by XFree86.

© Copyright IBM Corp. 2001, 2003 Unit 13. The Linux GUI 13-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

;)UHH&RQILJXUDWLRQ

;)UHHQHHGVWREHFRQILJXUHGIRU\RXUKDUGZDUH
.H\ERDUG
0RXVH
*UDSKLFDODGDSWHU
0RQLWRU
7KLQJVWRFRQILJXUHUHIUHVKUDWHUHVROXWLRQFRORUGHSWK
&RQILJILOHHWF;;)&RQILJ
0DQXDOFRQILJXUDWLRQSRVVLEOHEXWKDUG
6HH;)UHH+2:72IRUGHWDLOV
$XWRPDWHGFRQILJXUDWLRQWRROVDYDLODEOH
'XULQJLQVWDOODWLRQRIGLVWULEXWLRQ
;)UHHWRROV[IFRQILJ;FRQILJXUH
'LVWULEXWLRQWRROVUHGKDWFRQILJ[IUHH 5HG+DW 
VD[\DVW 6X6(

Figure 13-6. XFree86 Configuration LX023.0

Notes:
XFree86 needs to be configured for your hardware:
• Keyboard configuration is needed because different keyboards may have different
keyboard layouts (QWERTY, AZERTY, ...) and may have additional keys, for instance to
compose special characters like é, ç and ß)
• Mouse configuration involves identifying the port to which the mouse is attached (PS/2,
serial, USB), and the number of buttons on the mouse.
• Graphical Adapter configuration involves identifying the chipset used, the clockchip
timings available and the amount of memory present.
• Monitor configuration requires you to configure the maximum horizontal
synchronization rate and the vertical refresh rate, and for instance any energy saving
features.
You also need to decide which resolution, refresh rate and color depth you want to use.
These values are all limited by the capabilities of your hardware.

13-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Let's start with color depth. In order to be able to display 256 different colors
simultaneously, you need 8 bits (1 byte) per pixel. (2 to the power of 8 is 256.) For 16
thousand colors, you need 16 bits (2 bytes) and for 4 million colors, you need 24 bits (3
bytes).5 Since the amount of memory on your graphical adapter is fixed, having a high
color depth means you can store less pixels and therefore will be limited to a lower
resolution.
Next, let's talk about refresh rate. This is the number of times the whole screen can be
redrawn. A low refresh rate will generate flicker, and will cause headaches in the long run.
For continued use, a refresh rate of 60 Hz6 is considered minimal, with some people
actually recommending 72 Hz or more. But monitors typically have a limited bandwidth,
meaning that they can only draw a limited number of pixels per second. So if your
resolutions goes up, you need to draw more pixels, and your refresh rate necessarily will
go down.
The last consideration is the resolution itself. By having more pixels on the screen, each
pixel will be smaller. But system fonts, windows and so forth typically have a fixed size,
measured in pixels. So the higher your resolution becomes, the smaller your letters and
windows will be.
As you can see, configuring color depth, refresh rate and resolution for your combination of
monitor and graphical adapter can be a daunting task. It is possible to do this configuration
by hand, but not recommended.
Various people have written tools for creating an XFree86 configuration file
(/etc/X11/XF86Config or /etc/X11/XF86Config-4) automatically. These tools are generally
run during installation, but can also be started by hand.
Depending on your distribution, the following tools may or may not be available:
• xf86config, X -configure (tools supplied by the XFree86 project)
• redhat-config-xfree86 (tool supplied by Red Hat)
• sax, sax2 (tools supplied by SuSE)
And there may well be others.

5 Some adapters support a color depth of 32 bits as well. This in reality is still a 24 bit color depth, but aligned on 32 bit boundaries for

increased performance with certain types of memory.


6
One Hertz (Hz) means "one per second".

© Copyright IBM Corp. 2001, 2003 Unit 13. The Linux GUI 13-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

'HVNWRS(QYLURQPHQWV

$'HVNWRS(QYLURQPHQWLV
$VHWRIWRROVOLEUDULHVDQGVWDQGDUGVWKDWDOORZV
GHYHORSPHQWRI;FOLHQWV
$VHWRI;FOLHQWV LQFOXGLQJRQHRUPRUHZLQGRZ
PDQDJHUV WKDWDUHGHYHORSHGZLWKWKHVHWRROV
OLEUDULHVDQGVWDQGDUGV
([DPSOHV
*120( *181HWZRUN2EMHFW0RGHO(QYLURQPHQW
.'( .'HVNWRS(QYLURQPHQW

$GYDQWDJHVRI'HVNWRS(QYLURQPHQWV
,QWHJUDWLRQ FXW SDVWHYLDFOLSERDUGGUDJ GURS
&RPPRQORRN WKHPHV

Figure 13-7. Desktop Environments LX023.0

Notes:
A Desktop Environment basically consists of two things:
• A set of tools, libraries and standards that allow a programmer to develop X clients.
• A set of X clients (usually including one or more window managers) that were
developed using these tools, libraries and standards.
The most popular examples of desktop environments today are GNOME and KDE.
Using a desktop environment instead of a collection of loose X clients has several
advantages:
• X clients that are developed as part of a desktop environment tend to have better
integration with other clients from that same environment. This makes things like
cross-application cut & paste and drag & drop possible.
• These X clients typically will have the same look and feel. In most cases, this
culminates in the use of "themes": a combination of colors and textures that look good
with each other (in the eyes of the person that developed a theme), and that, when
selected once, will be used by any client from that desktop environment.

13-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KH.'HVNWRS(QYLURQPHQW .'(

Figure 13-8. The K Desktop Environment (KDE) LX023.0

Notes:
The visual shows a screenshot of the K Desktop Environment. Several things can be
identified:
First, the desktop itself. On this are a number of icons which were created automatically
when the system was installed. Clicking on these icons launches various programs, varying
from the mount command (to mount the CD-ROM) to help browsers.
Second, the panel, which stretches all the way along the bottom of the screen. The panel is
divided into a number of areas:
• The first area starts with the KDE button, which starts a start menu just like Windows.
Then you will see a number of other buttons, which start various often-used programs.
• The second area shows the virtual desktops that are currently configured. As you can
see, only the first one is in use.
• The third area shows the applications that are currently running in this desktop.
• The fourth area holds a lock and an exit button. The lock button will lock your screen,
and the exit button will log you out.

© Copyright IBM Corp. 2001, 2003 Unit 13. The Linux GUI 13-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

• The fifth area holds icons for certain KDE applications, such as Klipper, the KDE
clipboard.
• The sixth area holds a clock.
The third thing that can be seen is the set of applications that are running. In the visual,
only a terminal window, a browser (Konqueror) and the GIMP have been started.

13-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
7KH*120('HVNWRS(QYLURQPHQW

Figure 13-9. The GNOME Desktop Environment LX023.0

Notes:
The visual shows a screenshot of a GNOME (GNU Object Modeling Environment) desktop,
again taken from a Red Hat system. As you can see, the basic functionality is not all that
different.

© Copyright IBM Corp. 2001, 2003 Unit 13. The Linux GUI 13-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

6WDUWLQJ;

,IORJJHGLQRQDWH[WWHUPLQDOUXQVWDUW[
2QO\VWDUWVDVLQJOHVHVVLRQ
:KHQVHVVLRQHQGV\RXDUHEDFNLQ\RXUWH[W
WHUPLQDO
,I\RXZDQWWRHQDEOHWKHJUDSKLFDOORJLQVFUHHQEULQJWKH
V\VWHPLQWRUXQOHYHO
7RVZLWFKPDQXDOO\XVHLQLWFRPPDQG
7RPDNHFKDQJHSHUPDQHQWHGLWHWFLQLWWDE
LGLQLWGHIDXOW

Figure 13-10. Starting X LX023.0

Notes:
X can be started in two ways.
The first way is by running the startx command. This command searches for the first free
virtual terminal and starts XFree86 on that terminal. It then starts your favorite window
manager of your favorite desktop environment. The window manager finally starts all other
applications that make up your desktop.
The second way is by switching to runlevel 57.
Switching to runlevel 5 can be achieved with the command init 5, and can be configured as
default runlevel by editing the file /etc/inittab: Find the line that currently says
id:3:initdefault:
and change it to
id:5:initdefault:
7
A "runlevel" is a system-wide parameter that determines the applications that are being started. They can loosely be compared to
Windows' hardware profiles.
Most distributions use runlevel 3 to identify multiuser mode without X, and runlevel 5 to identify multiuser mode with X.

13-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty When your system reboots, it will start in runlevel 5 automatically.


In runlevel 5, a so-called "display manager" is started. This program (depending on your
settings this will be xdm, kdm or gdm) will display a graphical login prompt. When a user
logs on, it will subsequently start the favorite window manager of that user, just as with
startx.

© Copyright IBM Corp. 2001, 2003 Unit 13. The Linux GUI 13-15
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&KRRVLQJ\RXU'HVNWRS(QYLURQPHQW

0RVWGLVWULEXWLRQVSURYLGHPXOWLSOHGHVNWRSHQYLURQPHQWV
7RFKRRVHEHWZHHQWKHPVHOHFWIURPWKH/RJLQSURPSW
(YHU\XVHUFDQKDYHKLVKHURZQSUHIHUHQFH

Figure 13-11. Choosing your Desktop Environment LX023.0

Notes:
Between distributions, there is no default way of selecting your favorite desktop
environment. Most distributions store the desktop environment in some hidden file in the
home directory of the user. This ensures that each user can have his own favorite
environment. But the name of the file is not really standardized, as are the tools that allow
you to change the file.
Fortunately, a generic way has been added to the graphical login prompt (gdm or kdm). A
pull-down menu allows you to choose between a number of available desktop
environments. Furthermore, your choice will be stored and will be listed as your preferred
choice next time you log in.

13-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&KHFNSRLQW
7)7KHPDLQFRQILJXUDWLRQILOHRI.'(LV
HWF;;)&RQILJ
:KDWVWDWHPHQWGHVFULEHVWKHIXQFWLRQRIWKH
;VHUYHUEHVW"
D,WUHFHLYHVLQSXWIURPWKHNH\ERDUGDQGPRXVHDQG
IRUZDUGVWKLVWRWKHDSSURSULDWHFOLHQWDQGLWUHFHLYHV
RXWSXWIURPWKHFOLHQWVDQGGLVSOD\VWKLVRQWKHVFUHHQ
E,WSHUIRUPVWKHZLQGRZGUHVVLQJ,WPDNHVVXUHWKDW
HYHU\DSSOLFDWLRQKDVDERUGHUDURXQGLWVZLQGRZVVR
WKDWWKHZLQGRZFDQEHUHVL]HGPRYHGDQGLFRQLILHG
F,WDOORZVWKHXVHUWRW\SHFRPPDQGVZKLOHLQD
JUDSKLFDOHQYLURQPHQW
G,WVKRZVDVHWRIH\HVORRNLQJDWWKHFXUVRU
+RZGR\RXVWDUW;"

Figure 13-12. Checkpoint LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 13. The Linux GUI 13-17
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

8QLW6XPPDU\

7KH*8,RI/LQX[LVEDVHGRQWKH;:LQGRZ6\VWHP ;
IRUVKRUW
;XVHVDFOLHQWVHUYHUPRGHO
7KHPRVWFRPPRQ;VHUYHUXQGHU/LQX[LV;)UHH
$'HVNWRS(QYLURQPHQWLVDVHWRIWRROVOLEUDULHVDQG
VWDQGDUGVWKDWDOORZGHYHORSPHQWRI;FOLHQWVDQGDVHW
RI;FOLHQWVGHYHORSHGZLWKWKLV
7KHPRVWFRPPRQ'HVNWRS(QYLURQPHQWVRQ/LQX[DUH
.'(DQG*120(
7RVZLWFKEHWZHHQ'HVNWRS(QYLURQPHQWVXVHWKH
SXOOGRZQPHQXIURPWKHJUDSKLFDOORJLQSURPSW

Figure 13-13. Unit Summary LX023.0

Notes:

13-18 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 14. Customizing the User Environment

What This Unit Is About


This unit demonstrates how a user's environment can be customized
to meet their specific preferences.

What You Should Be Able to Do


After completing this unit, you should be able to:
• List the order of login scripts
• Modify login scripts to customize the bash environment
• List the tools available for customizing the GUIHow You Will Check
Your Progress

Accountability
• Checkpoint questions
• Exercises

© Copyright IBM Corp. 2001, 2003 Unit 14. Customizing the User Environment 14-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
/LVWWKHRUGHURIORJLQVFULSWV
0RGLI\ORJLQVFULSWVWRFXVWRPL]HWKHEDVKHQYLURQPHQW
/LVWWKHWRROVDYDLODEOHIRUFXVWRPL]LQJWKH*8,

Figure 14-1. Objectives LX023.0

Notes:

14-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
%DVK,QLWLDOL]DWLRQ /RJLQ6KHOO

HWFSURILOH
+20(EDVKBSURILOH
RU+20(EDVKBORJLQ
RU+20(SURILOH

 %RXUQH$JDLQ6KHOO

+20(EDVKBORJRXW

Figure 14-2. Bash Initialization (Login Shell) LX023.0

Notes:
The first file that shell uses at login is /etc/profile. This file contains variables specifying the
basic environment for all processes and can only be changed by the system administrator.
Furthermore, this file runs commands in your environment when you log in.
Next, the shell executes $HOME/.bash_profile. This file serves the same purpose as
/etc/profile but this file can be changed by the user. If it is not found, $HOME/.bash_login
will be used, and if that file is not found, $HOME/.profile will be used.
Ensure that newly created variables do not inadvertently conflict with standard variables
such as MAIL, PS1, PS2, and so forth.

© Copyright IBM Corp. 2001, 2003 Unit 14. Customizing the User Environment 14-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

%DVK,QLWLDOL]DWLRQ QRQ/RJLQ6KHOO

aEDVKUF

 %RXUQH$JDLQ6KHOO LQWHUDFWLYH 

%$6+B(19

%RXUQH$JDLQ6KHOO QRQLQWHUDFWLYH 

Figure 14-3. Bash Initialization (non-Login Shell) LX023.0

Notes:
When a shell is started, but not as a login shell, /etc/profile and ~/.bash_profile are not
read. Instead, the bash shell either uses $HOME/.bashrc (for a non-login, interactive shell,
such as the shell that runs in a terminal window) or the $BASH_ENV script (for a
non-interactive shell, such as a shell executing a shell script).

14-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
%DVK,QLWLDOL]DWLRQZLWK5HGKDW([WHQVLRQV
HWFSURILOH
HWFSURILOHG VK
+20(EDVKBSURILOH
+20(EDVKUF
H[SRUW%$6+B(19 +20(EDVKUF
HWFEDVKUF

>XVHU#KRVWGLU@ %RXUQH$JDLQ6KHOO

+20(EDVKBORJRXW

Figure 14-4. Bash Initialization with Red Hat Extensions LX023.0

Notes:
On a Red Hat system, a number of extra files are called when a user starts bash.
• First, /etc/profile also calls every shell script in /etc/profile.d. In order not to confuse with
the csh shell, only scripts with the extension .sh are called.
• In $HOME/.bash_profile, $BASH_ENV is set to $HOME/.bashrc. This ensures that a
non-interactive, non-login shell initializes itself with the $HOME/.bashrc file too.
• Then, from $HOME/.bash_profile, $HOME/.bashrc is called. This ensures that even a
login shell initializes itself with the $HOME/.bashrc file.
• $HOME/.bashrc in turn calls /etc/bashrc. This ensures that global options can be
defined by the system administrator, even for non-login and non-interactive shells.
All files mentioned are customizable. As an example, the system administrator could add
scripts that send an alert (log file entry or mail) when a user logs in our out.
If you modify the shell scripts mentioned, there are two things to be aware of:

© Copyright IBM Corp. 2001, 2003 Unit 14. Customizing the User Environment 14-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

• Make sure you do not inadvertently change standard shell variables such as $HOME,
$MAIL and so forth.
• An upgrade of a system might overwrite these standard shell scripts.

14-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
%DVK,QLWLDOL]DWLRQZLWK6X6(([WHQVLRQV
HWFSURILOH
HWFSURILOHG VK
HWF6X6(FRQILJSURILOH
HWFSURILOHORFDO
HWFEDVKEDVKUF
+20(EDVKUF
+20(DOLDV
+20(SURILOH

KRVWGLU %RXUQH$JDLQ6KHOO

+20(EDVKBORJRXW

Figure 14-5. Bash Initialization with SuSE Extensions LX023.0

Notes:
SuSE has also extended the bash startup flow, but differently. Here, the /etc/profile script
has a far more important function. It calls, in turn:
• All shell scripts in /etc/profile.d. Again, to avoid confusion with csh-scripts, only scripts
with a .sh extension are called.
• /etc/SuSEconfig/profile. This script is modified by YaST when the system configuration
changes, and should not be changed by hand.
• /etc/profile.local. This script is for local customizations.
• /etc/bash.bashrc. This script contains system-wide bash customizations that are also
applied to non-login shells.
/etc/bash.bashrc also calls /etc/bash.bashrc.local, which can be used for local
customizations. This is not shown in the visual.
• $HOME/.bashrc. This script can obviously be modified by the user.

© Copyright IBM Corp. 2001, 2003 Unit 14. Customizing the User Environment 14-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

• $HOME/.alias. This script can also be modified by the user, and is used to define
user-specific aliases.
Obviously, after having called /etc/profile, bash also calls $HOME/.profile. This file is
virtually empty on a default SuSE system, but can be modified by the user.

14-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
.'(&XVWRPL]DWLRQ

Figure 14-6. KDE Customization LX023.0

Notes:
Although the KDE configuration consists of a large number of text files as well, you don’t
have to know or edit them by hand: KDE comes with a “control panel” which allows you to
modify your environment easily.

© Copyright IBM Corp. 2001, 2003 Unit 14. Customizing the User Environment 14-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

*120(&XVWRPL]DWLRQ

Figure 14-7. GNOME Customization LX023.0

Notes:
GNOME also comes with its own graphical configuration screens. As with KDE, your
changes are actually stored in text files which can also be modified by hand, using a text
editor such as vi, but this is hardly ever necessary.

14-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&KHFNSRLQW

 :KLFKILOHZRXOG\RXXVHWRFXVWRPL]H\RXUHQYLURQPHQW
YDULDEOHVDQGZK\WKLVILOH"

 :KDWGRWKHIROORZLQJYDULDEOHVGHILQHRQ\RXUV\VWHP"
 3$7+36

Figure 14-8. Checkpoint LX023.0

Notes:
Write down your answers here:

1.
2.

© Copyright IBM Corp. 2001, 2003 Unit 14. Customizing the User Environment 14-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

8QLW6XPPDU\

$QXPEHURIVKHOOVFULSWVDOORZ\RXWRFXVWRPL]H\RXU
VKHOOHQYLURQPHQW
%RWK.'(DQG*120(KDYHDQLQWHJUDWHGFRQWURO
FHQWHUIRUFXVWRPL]DWLRQ

Figure 14-9. Unit Summary LX023.0

Notes:

14-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 15. Basic System Configuration

What This Unit Is About


This unit covers the system configuration that typically needs to be
done on a Linux workstation.

What You Should Be Able to Do


After completing this unit, you should be able to:
• Discuss System Management tools
• Install and deinstall additional software
• Configure a printer
• Configure a soundcard
• Configure a network adapter

How You Will Check Your Progress


Accountability:
• Checkpoint questions
• Machine exercises

© Copyright IBM Corp. 2001, 2003 Unit 15. Basic System Configuration 15-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
'LVFXVV6\VWHP0DQDJHPHQWWRROV
,QVWDOODQGGHLQVWDOODGGLWLRQDOVRIWZDUH
&RQILJXUHDSULQWHU
&RQILJXUHDVRXQGFDUG
&RQILJXUHDQHWZRUNDGDSWHU

Figure 15-1. Objectives LX023.0

Notes:

15-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
:K\6\VWHP&RQILJXUDWLRQ

0RVWV\VWHPFRQILJXUDWLRQLVGRQHGXULQJLQVWDOODWLRQ
0LJKWQHHGWRFKDQJHV\VWHPFRQILJXUDWLRQDIWHUZDUGV
7KLQJVQRWFRQILJXUHGGXULQJLQVWDOODWLRQ
&RQILJXUDWLRQIDLOHGGXULQJLQVWDOODWLRQ
(QYLURQPHQWFKDQJHGDIWHULQVWDOODWLRQ
7KUHHZD\VWRFKDQJHV\VWHPFRQILJXUDWLRQ
7HPSRUDU\XQWLOQH[WV\VWHPUHERRW
0DQXDOO\FKDQJLQJFRQILJILOHVE\KDQG
$XWRPDWHGXVLQJV\VWHPDGPLQLVWUDWLRQWRROV
7\SLFDOLWHPVWREHFRQILJXUHGRQDZRUNVWDWLRQ
$GGUHPRYHVRIWZDUH
3ULQWHUV
6RXQG&DUGV
1HWZRUN

Figure 15-2. Why System Configuration LX023.0

Notes:
In most distributions, a "workstation" install will take care of configuring most of your
system. In fact, in all but a few cases you can be productive right away once your system
has been installed.
There are however a few cases in which you need to do additional configuration to your
Linux workstation:
• Certain things were not be configured during the installation. This might be because the
distribution manufacturer left that component out altogether, or that you decided to skip
that part of the installation process.
• The attempted configuration of a certain thing failed. This typically happens to
soundcards: Trying to detect certain older types of sound cards may cause your system
to hang.
• After installation, the environment in which your workstation has to operate changes.
You might be getting a new printer, or be relocated to another network, for instance.

© Copyright IBM Corp. 2001, 2003 Unit 15. Basic System Configuration 15-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

All these factors may require you to do system configuration by hand. There is a number of
ways this can be done on a Linux system, and the following three terms are widely used in
this respect.
• Temporary system administration means changing a parameter without making the
change permanent. So the next time your system reboots, the old configuration which
was stored on disk is used again. This sort of administration is for instance used when
you need to connect your laptop to another network than the network you usually
connect to.
Temporary system administration usually comes down to entering a single command
which overrides the parameters that are stored on disk.
• Manual system administration generally refers to making the configuration change on
disk yourself. As we've already seen, virtually all configuration options of a Linux system
are stored in text files somehow. Editing these files by hand, using a text editor, is called
manual administration.
Manual administration is typically only done by experienced system administrators who
know the internal layout of all these configuration files, and who understand the
interactions between the various components of a Linux system.
Manual configuration typically requires you to restart the appropriate service afterwards
manually too.
• Automated configuration means that you use some sort of system administration tool
with a menu-driven interface that makes the desired change for you. The advantage of
this method is that you don't need to know the internal layout of the configuration files,
that the chance of making errors is smaller, and that the restart of the appropriate
service is taken care of too. This makes automated configuration the ideal method for a
beginning user.
There are disadvantages too to automated configuration. One is that an experienced
system administrator can usually make the desired change faster by doing a manual
configuration change than by using a system administration tool. And the other, bigger
disadvantage is that the changes you can make are limited by the capabilities of the
tool. Typical system administration tools are not written by the programmers of the
service to be configured, but by someone else. And that someone else typically does
not support all configuration options that the programmer has built into the service.
A Linux system is highly configurable and supports a lot of services and hardware. In this
unit, we're only going to look at four of the most common system administration tasks that
you will encounter on a typical workstation:
• Adding and removing software
• Configuring printers
• Configuring sound cards
• Configuring network adapters

15-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
6\VWHP&RQILJXUDWLRQ7RROV

9DULRXVWRROVKDYHEHHQGHYHORSHGWRHDVHV\VWHP
DGPLQLVWUDWLRQ
$SSOLFDWLRQVSHFLILF 6DPED6:$7
'LVWULEXWLRQVSHFLILF UHGKDWFRQILJ 6X6(\DVW
'HVNWRS(QYLURQPHQWVSHFLILF JPHQXNFRQWURO
*HQHULF/LQX[81,; ZHEPLQ
7KHSHUIHFWWRRO
GRHVQRWH[LVW \HW" 

Figure 15-3. System Configuration Tools LX023.0

Notes:
One of the main disadvantages of Linux as compared to commercial UNIXes as AIX, for
instance, is that there is no single, large manufacturer behind it who can force all
developers to work according to a single standard. This is particularly visible when it comes
to system configuration tools. Where for instance AIX comes with one tool, SMIT, with
which you can manage the entire system, there is no Linux distribution who can do that.
Nevertheless, there is a need for system administration tools. Various people have worked
on developing these, but all these tools had a specific, limited purpose.
There are for instance tools that are developed by the authors of an application, to allow
management of that particular application. Other tools are developed by distribution
manufacturers to allow basic configuration of that particular distribution. There are tools
that attempt to be generic Linux configuration tools, and there's even some tools that
attempt to be generic UNIX configuration tools.
The perfect tool however does not exist. Now what "perfect" is, is in the eyes of the
beholder, but all of the tools that present themselves as generic still suffer one major
deficiency (as of now): They currently do not motivate the author of a program to also write

© Copyright IBM Corp. 2001, 2003 Unit 15. Basic System Configuration 15-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

the configuration menus for that program, for that particular system configuration tool. It is
virtually always the author (or a team of people working for the author) of the system
configuration tool who writes the configuration menus for a particular application. This
means that the system configuration tool will always lag behind, increases the chance of
errors, and limits the features that are supported by the configuration tool.
A "perfect" administration tool should preferably work like the man command: It should
have a published interface (file format or whatever) that everybody can produce, and be
available on every Linux (or UNIX) distribution. Only then would this motivate and allow the
authors of an application to also write the configuration menus for that application, just like
they are currently already doing for manual pages.
That perfect tool is not yet available. Instead, every distribution comes with its own
distribution specific tools, and some applications have their own tools as well. This means
that you will have to figure out from the information about your distribution which tools are
available for you, and you also need to figure out which tool you prefer, if multiple tools
perform the same function. This unit attempts to be a guide in that, but it can never be
complete, unfortunately.

15-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
$GGLQJ5HPRYLQJ6RIWZDUHXVLQJ530

8VHUSPWRLQVWDOORUXSJUDGHVRIWZDUHSDFNDJHV
&RPPRQRSWLRQV
L LQVWDOOLQJQHZSDFNDJHV
8 XSJUDGLQJH[LVWLQJSDFNDJHV
H UHPRYLQJSDFNDJHV
USPLKYP\SURJLUSP
P\SURJ

USP8KYP\SURJLUSP
P\SURJ

USPHP\SURJ

7KHKRSWLRQVVKRZVDSURJUHVVEDU

Figure 15-4. Adding/Removing Software using RPM LX023.0

Notes:
Most distributions in the market today distribute their software in "RPM" format1. RPM,
which stands for "RPM Package Manager2", is a file format which is extremely suitable for
software distribution, because it combines the following things in one file:
• Name of the software
• Version number(s)
• Copyright License
• Authors
• Build information
• Dependency information
• The files that make up the software package, grouped into programs, configuration files
and other files.
1
In fact, the Linux Standards Base (LSB), which aims at developing a set of standards that every distribution has to adhere to, has
specified RPM to be the package distribution format.
2 RPM used to stand for Red Hat Package Manager. But to encourage the use of RPM by other distributions, Red Hat has released it

under the GPL and has renamed it to RPM Package Manager. And yes, that’s a self-referencing acronym, just like GNU.

© Copyright IBM Corp. 2001, 2003 Unit 15. Basic System Configuration 15-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

• Pre- and post-installation scripts


• Pre- and post deinstallation scripts
• Cryptographic checksums (so the integrity of the individual files and the whole package
can be verified.)
Furthermore, all these components are automatically compressed.
When an PRM package (a file which generally ends with ".rpm") is installed, the information
about it goes into a database on disk (usually /var/lib/rpm). This makes it possible to
retrieve all information about all installed packages without having to read the original RPM
files.
Virtually everything you want to do with an RPM package or with the RPM database is
done with the rpm command. It is really powerful, but we will only cover the most common
things:
Installing additional software is done with the rpm -i command, followed by the file
name(s) of the package(s) to install.
Removing software is done with the rpm -e command, followed by the package name.
Updating software is done with the rpm -U command, followed by the package filename.

15-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
4XHU\LQJWKH530'DWDEDVH

2SWLRQV
O OLVWDOOILOHV
S TXHULHVQHZSDFNDJHVEHIRUHLQVWDOOLQJ

USPTP\SURJ
P\SURJ

USPTOP\SURJ
XVUELQP\SURJ
HWFP\SURJUF
XVUVKDUHPDQPDQP\SURJJ]

USPTOS\RXUSURJLUSP
XVUELQIRR
HWFIRRUF
XVUVKDUHPDQPDQIRRJ]

Figure 15-5. Querying the RPM Database LX023.0

Notes:
Querying already installed packages is done with the rpm -q command, followed by the
package name. If no further options are given, only the package name shows up. Adding
the -i option will give you all information about a package, while adding the -l option will
give you all the files that are part of this package. To query all packages, use the -a option
and do not give a package name.
Querying not yet installed packages is done the same as querying already installed
packages, with one exception: you need to specify the -p option and the package filename
instead of the package name.
Note that there is a difference between the package filename and the package name. A
package filename typically consists of the package name, the version number and the .rpm
extension like this: <packagename>-<version>.rpm. Also note that some distributions
(e.g. SuSE) do not include the version number in the package filename.

© Copyright IBM Corp. 2001, 2003 Unit 15. Basic System Configuration 15-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

$GGLQJ5HPRYLQJ6RIWZDUHIURPDWDUJ])LOH

WDUJ] WJ] GHIDXOWGLVWULEXWLRQIRUPDWIRUVRXUFHFRGH


WDU WDSHDUFKLYHUVWRUHVDGLUHFWRU\WUHHLQDVLQJOH
ILOH
J] *18=LSFRPSUHVVLRQSURJUDP
7RXQSDFNDWDUJ]RUWJ]DUFKLYH
FGXVUVUF
WDU][YIDUFKLYHYHUVLRQWDUJ]
FGDUFKLYHQDPH!
5HDG,167$//RU5($'0(ILOHIRULQVWDOODWLRQ
LQVWUXFWLRQV
6KRXOGEHLQVWDOOHGXQGHUXVUORFDO

Figure 15-6. Adding/Removing Software from a .tar.gz File LX023.0

Notes:
The default distribution format for source code in the Linux community (and to a large
extent, the UNIX community as well) is not .rpm, but .tar.gz. This extension means that:
1. All files have been combined into one large archive file using the tar command.
2. The resulting single file has been compressed using the gzip command.
For brevity and compatibility with MS-DOS, .tar.gz files sometimes use the extension .tgz.
If you want to make use of these files, you need to uncompress and unpack them first.
Fortunately, GNU tar (the tar command that is available on most Linux distributions) can do
all of this in one run. The default location to perform this operation is /usr/src. The archive
itself will usually create its own subdirectory (/usr/src/<archive-version>) and will store all
its files in there.
The next step is then to cd into the directory and view the documentation that the author
wrote to figure out the next steps. This is usually stored in a file called README or
INSTALL. If you only received the source code, you need to compile the software too,
which usually involves running a configuration program (./configure or make config), a

15-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty compilation program (typically make) and an installation program (make install or
./install).
Deinstallation of programs that came to you in .tar.gz form is usually virtually impossible.
Most often it requires you to delete all installed files by hand.

© Copyright IBM Corp. 2001, 2003 Unit 15. Basic System Configuration 15-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

3ULQWHU&RQILJXUDWLRQ

2Q5HG+DWDQG6X6(WKHSULQWHUVXEV\VWHPLV&836
&RPPRQ8QL[3ULQWLQJ6\VWHP

&RQILJXUDWLRQGRQHWKURXJKOSDGPLQRUZLWKD
EURZVHU KWWSKRVWQDPH  UHFRPPHQGHG

Figure 15-7. Printer Configuration LX023.0

Notes:
Printer configuration is, technically speaking, one of the most complex tasks of system
administration. The reason lies not in the configuration files itself, but in the fact that there
are so many file formats that your printer subsystem may need to handle, while your printer
typically only supports one or two. This requires the setup of elaborate filters, which detect
the file format of the file to be printed, and convert it into a format suitable for your printer.
Furthermore, printers themselves have evolved a lot in recent history: from daisy wheel
printers which only supported a single character set in a single font, to high-volume, double
sided color laser printers that support various color models.
These developments have lead to a number of printer subsystems, each progressively
more complex and powerful. The printer subsystem currently in use on Red Hat and SuSE
is CUPS (“Common UNIX Printing System”). Other distributions may use other printing
subsystems, such as BSD, LPRng or PPS.
CUPS is highly configurable. As with most subsystems, it can be configured by editing a
series of configuration files, but this is not recommended. Instead, you should use lpadmin
to configure CUPS, or point your browser to http://<hostname>:631. This gives you an

15-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty HTTP-interface to the cupsd daemon and is by far the easiest method of configuring
CUPS.
Once configured, you can submit print jobs to CUPS by using the lp command (derived
from and compatible with AT&T’s System V printing subsystem) or the lpr command
(derived from and compatible with BSD’s printing subsystem). Graphical applications will
typically be compatible with kdeprint, which means that they will call kdeprint and
interface with it to get the job printed. This gives you a seamless print interface from that
application.
Other useful commands are:
• lpstat and lpq: These commands show you the jobs queued to be printed.
• lpcancel and lprm: These commands allow you to cancel a print job.

© Copyright IBM Corp. 2001, 2003 Unit 15. Basic System Configuration 15-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

6RXQG&DUG&RQILJXUDWLRQ

&RQILJXUDWLRQXVXDOO\GRQHZLWKGHGLFDWHGWRRO
5HG+DWUHGKDWFRQILJVRXQGFDUG
6X6(\DVWRUDOVDFRQI

DQGPRGLILHV\RXU
VQGFRQILJ HWFPRGXOHVFRQI

DOVDFRQI FKHFNV\RXU
KDUGZDUH

HWFPRGXOHVFRQI

6RXQG&DUGVXSSRUWUHTXLUHVFRUUHFWORDGLQJRI
NHUQHOPRGXOHV
Figure 15-8. Sound Card Configuration LX023.0

Notes:
Sound card support is performed by the Linux kernel itself, in the form of kernel modules3.
The file which holds the information about the modules to be loaded to support various
hardware components is /etc/modules.conf4. This file itself is not that hard to configure (it's
usually only a few lines after all), but it is hard to obtain the correct parameters (a typical
soundcard can be configured in a dozen ways, depending on whether MIDE needs to be
supported, or wavetables, and so forth). Because of this, a dedicated tool is usually used.
On a Red Hat system, use redhat-config-soundcard. On a SuSE system, use yast2.
Once your sound card has been configured, there's a lot of multimedia programs that can
use your sound card. The visual lists a few of these.

3
Pieces of code that can be loaded into the kernel while the system is running to provide support for one specific hardware component.
4
This file used to be called /etc/conf.modules.

15-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
1HWZRUN&RQILJXUDWLRQ

1HHGFRUUHFWQHWZRUNPRGXOHWREHORDGHGLQWRNHUQHO
HWFPRGXOHVFRQI
1HHGWRVHWFRUUHFW,3DGGUHVVHVHWF
*HQHUDOO\GRQHZLWKLIFRQILJFRPPDQG
)RU'+&3XVHGKFSFGSXPSRUGKFOLHQW
&RQILJXUDWLRQGRQHWKURXJKVFULSWVZKLFKDUHGLIIHUHQWLQ
HDFKGLVWULEXWLRQ
5HG+DWHWFV\VFRQILJQHWZRUNVFULSWVLIFIJHWK
6X6(HWFV\VFRQILJQHWZRUNLIFIJHWK
8VHGLVWULEXWLRQVSHFLILFWRROWRFRQILJXUH
5HG+DWUHGKDWFRQILJQHWZRUN
6X6(\DVW

Figure 15-9. Network Configuration LX023.0

Notes:
To configure a network, two things need to be done:
• The correct module needs to be loaded into the kernel. This is done by configuring the
/etc/modules.conf file correctly.
• The IP address needs to be configured. This is done with the ifconfig command. This
command does not read a configuration file, but rather expects the IP addresses to be
listed as parameters on the command line.
Because ifconfig does not read a standard configuration file, every distribution has to
come up with its own way of storing the IP addresses and other parameters that need to be
configured. Red Hat for instance stores them in /etc/sysconfig/network-scripts/ifcfg-eth0,
while SuSE stores them in /etc/sysconfig/network/ifcfg-eth0. In both cases, these files are
read by the startup scripts, who in turn execute the corresponding ifconfig command.
If you are using DHCP, then you don't need to configure all these parameters locally.
Instead, you need to start a DHCP client which requests all parameters from a DHCP

© Copyright IBM Corp. 2001, 2003 Unit 15. Basic System Configuration 15-15
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

server on the network. There are several DHCP clients for Linux. The one most often used
today is dhclient.
For automated configuration of your network in Red Hat Linux, start
redhat-config-network. For SuSE, use yast.

15-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&KHFNSRLQW
7):KHQ\RXFRQILJXUH\RXUV\VWHPDVD'+&3
FOLHQW\RXGRQ
WQHHGWRFRQILJXUH,3DGGUHVVHV
DQGVRIRUWK\RXUVHOYHV

7KHFRUUHFWFRPPDQGWRLQVWDOODQDGGLWLRQDO530
ZRXOGEH
DUSPL[SX]]OHVUSP
EUSPH[SX]]OHVLUSP
FUSPTLS[SX]]OHVUSP
GUSPL[SX]]OHVLUSP

:KDWLVWKHSURSHUVHULHVRIFRPPDQGVWRLQVWDOOD
WDUJ]ILOH"


Figure 15-10. Checkpoint LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 15. Basic System Configuration 15-17
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

8QLW6XPPDU\

6\VWHPFRQILJXUDWLRQLVQHFHVVDU\LIWKHLQVWDOODWLRQ
SURJUDPGLGRUFRXOGQRWFRQILJXUH\RXUV\VWHPRULI\RXU
HQYLURQPHQWFKDQJHGDIWHULQVWDOODWLRQ
6\VWHPDGPLQLVWUDWLRQFDQEHWHPSRUDU\PDQXDORU
DXWRPDWLF
6\VWHPDGPLQLVWUDWLRQLVEHLQJPDGHHDV\E\V\VWHP
DGPLQLVWUDWLRQWRROV
7KHSHUIHFWV\VWHPDGPLQLVWUDWLRQWRROGRHVQRW\HWH[LVW
<RXKDYHWRILQGRXWZKLFKWRROVDUHDYDLODEOHRQ\RXU
GLVWULEXWLRQDQGZKLFKWRROZRUNVIRU\RX
&RPPRQWKLQJVWRGRRQDZRUNVWDWLRQDUHDGGLQJDQG
UHPRYLQJVRIWZDUHFRQILJXULQJSULQWHUVFRQILJXULQJ
VRXQGFDUGVDQGFRQILJXULQJQHWZRUNLQWHUIDFHV

Figure 15-11. Unit Summary LX023.0

Notes:

15-18 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 16. Connecting to the Internet

What This Unit Is About


This unit gives an overview of the methods that can be used in Linux to
connect to the internet. It also covers basic security settings of a Linux
workstation.

What You Should Be Able to Do


After completing this unit, you should be able to:
• Connect to the internet using a regular modem and an ISDN
adapter
• Describe how to connect to the internet when using a broadband
connection (cable or xDSL)
• Describe the security issues involved in connecting to the internet
• Apply reasonable security measures

How You Will Check Your Progress


Accountability:
• Checkpoint questions
• Exercises

© Copyright IBM Corp. 2001, 2003 Unit 16. Connecting to the Internet 16-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
&RQQHFWWRWKHLQWHUQHWXVLQJDUHJXODUPRGHPDQGDQ
,6'1DGDSWHU
'HVFULEHKRZWRFRQQHFWWRWKHLQWHUQHWZKHQXVLQJD
EURDGEDQGFRQQHFWLRQ FDEOHRU['6/
'HVFULEHWKHVHFXULW\LVVXHVLQYROYHGLQFRQQHFWLQJWRWKH
LQWHUQHW
$SSO\UHDVRQDEOHVHFXULW\PHDVXUHV

Figure 16-1. Objectives LX023.0

Notes:

16-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&RQQHFWLQJWRWKH,QWHUQHW

&RQQHFWLQJWRWKHLQWHUQHW (VWDEOLVKLQJDFKDQQHOZKLFK
DOORZV\RXWRVHQG,3SDFNHWVWR\RXU,63DQGYLFHYHUVD
)RXUPRVWFRPPRQFRQQHFWLRQW\SHV
5HJXODUPRGHPFRQQHFWLRQ
,6'1FRQQHFWLRQ
&DEOHPRGHPFRQQHFWLRQ
['6/FRQQHFWLRQ
&RQQHFWLRQW\SHVGLIIHULQ
&RVW RQHWLPHIL[HGDQGYDULDEOH
%DQGZLGWK/DWHQF\
$YDLODELOLW\
$GGLWLRQDOIHDWXUHVVXFKDVIL[HG,3DGGUHVVHV

Figure 16-2. Connecting to the Internet LX023.0

Notes:
Most users will want to "connect their Linux workstation to the internet" somehow. At least,
that's what the common saying is. Technically speaking, this means that they want to
establish a channel that allows them to send IP packets to their Internet Service Provider
(ISP) and vice versa. And since the ISP’s network is part of the internet, this in fact leads to
an "internet connection"
Establishing that channel can be done in a variety of ways, but four seem to be the most
popular today.
• Regular modem connections require nothing more than a regular telephone line and a
modem. Modems are standard in just about every system you can get, and regular
telephone lines are available throughout the world. This makes it the most common
method of connecting to the internet.
The disadvantage of modem connections is that they're rather slow compared to the
other techniques (Up to about 40 Kbps1, and that in most areas around the world you
need to pay the telephone company (telco) a certain amount of money per second that
1
Kilobits (1024 bits) per second, so about 5 Kilobytes (1024 bytes) per second.

© Copyright IBM Corp. 2001, 2003 Unit 16. Connecting to the Internet 16-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

you're connected. (In the US, with most subscriptions, local calls are free or only cost a
fixed amount per call, no matter how long the call lasts.)
• ISDN (Integrated Services Digital Network) is a 100% digital telephone network. It is
mainly popular in Europe. It offers higher-bandwidth connections (64 Kbps) than a
regular telephone line. But you are still charged per second.
• Cable modem connections use the coaxial cable that delivers the signals to your TV
and VCR to provide two-way communications between you and the cable TV company.
This is possible because the coaxial cable used for cable TV has a number of frequency
ranges which cannot be used for TV or radio, but can be used for data transport.
• xDSL is the newest technique of them all, but it has made rapid progress. The idea of
xDSL, just as with cable modems, is to use the unused frequency ranges of your
telephone connection.
There are other, less common connection methods available as well, including wireless
solutions and satellite connections. These are less common however and fall outside the
scope of this course.
All four of these methods differ in a number of ways from each other:
• The cost of each solution is different, with regards to one-time (installation, equipment
to purchase), fixed (monthly charges) and variable (per second charges) costs.
• The bandwidth (amount of bits per second) and the latency (time one bit takes to reach
the other side) is different.
• The availability of each solution is different. Regular telephone service is available
around the world, even in hotels, while cable modems and ADSL is only available
where the cable TV operator or telco installed special equipment.

16-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
0RGHP&RQQHFWLRQV

8VHDQDQDORJWHOHSKRQHOLQHWRHVWDEOLVKDGLJLWDOGDWD
FRQQHFWLRQ 02GXODWLRQ'(0RGXODWLRQ
333LVXVHGIRU,3SDFNHWHQFDSVXODWLRQEHWZHHQ\RXU
3&DQGWKH,63VURXWHU

/LQX[ZRUNVWDWLRQ ,63URXWHU

333FRQQHFWLRQ
,QWHUQHW

3ODLQ2OG
(& $$ &' 2+ 5' 7' 75 05
SRZHU
7HOHSKRQH (& $$ &' 2+ 5' 7' 75 05
SRZHU

%XLOWLQRU 6\VWHP ,63PRGHP


H[WHUQDO
PRGHP

Figure 16-3. Modem Connections LX023.0

Notes:
A regular modem connection is the most common way of connecting to the internet. It
requires a modem (MOdulator/DEModulator) at each end, who convert the digital signal to
an analog signal, and back again.
Once the modems have finished handshaking with each other (the hiss at the start of the
call), you've got a byte-by-byte serial connection. In order to send any IP packets over this
connection, you need to encapsulate them. This is done using the PPP protocol.

© Copyright IBM Corp. 2001, 2003 Unit 16. Connecting to the Internet 16-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

0RGHP&RQQHFWLRQVLQ/LQX[

([WHUQDOPRGHPVKDYHGHYLFHQDPHVGHYWW\6Q
&20 WW\6&20 WW\6
,QWHUQDOPRGHPVXVXDOO\HPXODWHDVHULDOSRUWQRWKLQJ
VSHFLDO
:LQPRGHPVUHTXLUHDVRIWZDUHGULYHUZKLFKLV
XVXDOO\RQO\DYDLODEOHXQGHU:LQGRZV ZLWKDIHZ
H[FHSWLRQV
7RVHWXSFRQQHFWLRQQHHGWRLQYRNHSSSG
%HVWGRQHXVLQJDJUDSKLFDOIURQWHQGVXFKDVNSSS

Figure 16-4. Modem Connections in Linux LX023.0

Notes:
In Linux, modems are identified using their device name. For the modem connected to the
first serial port (COM1), the device name is /dev/ttyS02, COM2 is /dev/ttyS1, and so forth.
If you have an internal modem, then it usually emulates a serial port (usually COM3 or
COM4) with a modem attached, and you can use them as if it was an external modem.
Note however that cheap desktop PCs today are sometimes equipped with a so-called
"winmodem". This is cheap modem hardware without its own processor, which requires a
software driver (running on the main CPU) to work. Since most manufacturers of
winmodems have not (yet) released the specifications of these modems, they are not
supported in Linux. To the best knowledge of the author, two companies have released
information and consequently are supported: Lucent (Lucent Winmodem) and IBM
(MWave modem).

2
Note the capital S. A lowercase s means something entirely different here.

16-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Connecting to the internet with a regular modem requires pppd, the PPP daemon that
takes care of setting up (with the help of a program called chat) and maintaining the
connection. Configuring pppd manually is a fairly difficult task, and that's why different
dialer programs like kppp have been developed. They allow you to configure your ISP
account and modem using a graphical interface. A nice feature of kppp in particular is that
it can show a graphical representation of the amount of traffic as well.

© Copyright IBM Corp. 2001, 2003 Unit 16. Connecting to the Internet 16-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

,6'13ULQFLSOHV

,6'1 ,QWHJUDWHG6HUYLFHV'LJLWDO1HWZRUN
3URYLGHVDGLJLWDOQHWZRUN
3RSXODULQ(XURSH
0RVWSRSXODUYDULDQWIRUKRPHXVHLV,6'1
FKDQQHOV.ESVHDFK
2QH,6'1FRQQHFWLRQFDQKDYHXSWRHLJKW0XOWLSOH
6XEVFULEHU1XPEHUV 061
/LQX[ZRUNVWDWLRQ ,63URXWHU

333FRQQHFWLRQ
,QWHUQHW

,6'1
(& $$ &' 2+ 5' 7' 75 05
SRZHU
7HOHSKRQH (& $$ &' 2+ 5' 7' 75 05
SRZHU

%XLOWLQRU 6\VWHP ,63,6'1DGDSWHU


H[WHUQDO
,6'1DGDSWHU

Figure 16-5. ISDN Principles LX023.0

Notes:
ISDN (Integrated Services Digital Network) provides a 100% digital network, which can be
used for voice (telephone), fax and data transmission. It is fairly popular in Europe, but has
not really caught on in the US.
ISDN basically extends the telephone companies (telco) network to your doorstep. In its
most basic variant (which is also the most popular for home use), ISDN-23, this gives you
two outside lines and a maximum of eight telephone numbers (called Multiple Subscriber
Numbers or MSNs4). Each outside line or "channel" is capable of transporting 64 Kbps,
bidirectional. Channels can be used individually (placing two phone calls simultaneously or
surfing the 'net while placing a telephone call), or can be bundled into one, 128 Kbps
"bonded" channel.
Apart from this, ISDN works just like a telephone network: You need to set up a connection
to your ISP using the ISP’s telephone number, and need to run PPP over that serial
connection.
3 ISDN-2 is also called Basic Rate Interface (BRI). The ISDN variant for small companies is ISDN-30, which is also called Primary Rate

Interface (PRI). As the name suggests, this gives you 30 outside lines to use.
4
In German-speaking countries, the abbreviation EAZ is used instead, which stands for Endgerate Auswahl Ziffer.

16-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
,6'1LQ/LQX[

/LQX[LPSOHPHQWVSVHXGRWW\
VZKLFKDFFHSWUHJXODU
PRGHPFRPPDQGVWRVHWXS,6'1FRQQHFWLRQV
GHYWW\,WKURXJKGHYWW\,
&DQEHXVHGMXVWOLNHDPRGHPLQ\RXULQWHUQHWGLDOHU
1HHGDVSHFLDO$7FRPPDQGWRFRQILJXUH061
$7 (
$SSOLFDWLRQVFDQDOVRDFFHVVWKH,6'1DGDSWHUGLUHFWO\
5HTXLUHVDQ,6'1FDSDEOHGLDOHUVXFKDV
LVGQFRQILJ
6XSSRUWVFKDQQHOEXQGOLQJ
$XWRPDWLFDOO\FRQILJXUHV061
0RUHGRFXPHQWDWLRQ
XVUVUFOLQX['RFXPHQWDWLRQ

Figure 16-6. ISDN in Linux LX023.0

Notes:
When you want to use ISDN in Linux, there's basically two methods.
The first method is to use the so-called pseudo-ttys, which the kernel implements. These
pseudo-ttys (called /dev/ttyI0 through /dev/ttyI635) accept regular AT commands as an
analog modem would, and can therefore be used as a regular modem in your internet
dialer. There is one thing you need to do though: as part of your modem initialization you
need to configure the correct MSN number. This is done with the AT&E command, followed
by the MSN number. The easiest method to do this is to go to your modem commands
screen of your internet dialer, and replace the dial string ATDT by the string
AT&E0123456789DT, where 0123456789 is your MSN number.
The second method is by using an internet dialer which is ISDN capable such as
isdn-config. These dialers are aware of the ISDN standards and allow you to configure
your MSN the proper way. In most cases, these dialers are also required if you want to do
channel bundling.

5
tee-tee-why-capital ai-zero, not tee-tee-why-el-zero!

© Copyright IBM Corp. 2001, 2003 Unit 16. Connecting to the Internet 16-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

More documentation can be found in the Linux kernel documentation directory,


/usr/src/linux/Documentation.

16-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&DEOH0RGHPV3ULQFLSOHV

&DEOHPRGHPVXVHDYDLODEOHEXWXQXVHGIUHTXHQF\
UDQJHVLQWKHFDEOH79QHWZRUN
7\SLFDOEDQGZLGWK0ESVVKDUHG
&RQQHFWLQJUHTXLUHVDFDEOHPRGHP

,QWHUQHW

/LQX[ZRUNVWDWLRQ
ZLWKEXLOWLQ ,63URXWHU
HWKHUQHWDGDSWHU '+&3VHUYHU

&DEOH &DEOH
PRGHP PRGHP
(& $$ &' 2+ 5' 7' 75 05
&DEOH79 (& $$ &' 2+ 5' 7' 75 05

QHWZRUN
SRZHU SRZHU

Figure 16-7. Cable Modem Principles LX023.0

Notes:
Cable modems use a number of available, but so far unused frequency bands in the cable
TV network for data communication. The total bandwidth of these ranges is about 30 Mbps,
depending on where you live.
Connecting to such a cable network requires a cable modem, which is essentially a bridge
between baseband ethernet and broadband cable TV cable.
Because of this bridging functionality, you basically need nothing more than an ethernet
adapter in your system. This ethernet adapter gets its IP address from a DHCP server in
the ISP’s network, and you're done. There is no tunneling or PPP involved. This makes
cable modems the easiest method of connecting to the internet.
One drawback of cable modems is that the 30 Mbps bandwidth is the total bandwidth
available for your block. That means that if you are the only subscriber, you can use the full
amount (if your cable TV provider allows that), but as soon as your neighbor decides to
subscribe too (based on your optimistic stories perhaps), your bandwidth halves.

© Copyright IBM Corp. 2001, 2003 Unit 16. Connecting to the Internet 16-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Another disadvantage with most cable modem solutions is that your cable TV provider
automatically becomes your ISP. In most areas you cannot choose your cable TV provider,
so you cannot switch ISPs either. (It might be that your cable TV provider contracted this
work out to a "real" ISP, but the principle stays the same.)

16-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
['6/3ULQFLSOHV

*HQHULFQDPHIRUXWLOL]LQJDGGLWLRQDOEDQGZLGWKLQORFDO
ORRSRIWHOHSKRQHQHWZRUN
9DULRXVLPSOHPHQWDWLRQV$'6/+'6/6'6/
%DQGZLGWKLVGHSHQGHQWRQLPSOHPHQWDWLRQSKRQHOLQH
TXDOLW\DQGGLVWDQFH
&RQQHFWLQJUHTXLUHVDVSOLWWHURUILOWHUVDQGDQ['6/
PRGHP
3ODLQ2OG
7HOHSKRQH
ORFDOORRS 6\VWHP
/LQX[ZRUNVWDWLRQ
ZLWKEXLOWLQ ['6/
HWKHUQHWDGDSWHU VSOLWWHU ['6/
VSOLWWHU
['6/ ['6/ 7HOFR,63
PRGHP PRGHP ,3
QHWZRUN
(& $$ &' 2+ 5' 7' 75 05 (& $$ &' 2+ 5' 7' 75 05
SRZHU SRZHU

Figure 16-8. xDSL Principles (1) LX023.0

Notes:
xDSL is the generic name for a range of techniques (ADSL, HDSL, SDSL, ...) that allow
you to use additional bandwidth in the "local loop", which is the technical term for the
telephone cable which runs from your house to the nearest telcos "Point of Presence".
These techniques all allow you to use your existing telephone cable as a data carrier, in
addition to allowing you to place regular telephone calls over it6. In order for these two
signals to be transported over the same cable, xDSL splitters are used, which split the
signal into the low-frequency part (up to 4 KHz) and send it to your telephone, or into the
regular telephone network, and into a high-frequency part, which goes to your and the
telco’s xDSL modem.
You connect your Linux workstation to your xDSL modem via ethernet, and the telco
connects its xDSL modem to its network. This allows IP communications.

6 This is possible because a telephone call only uses the frequency range up to 4 KHz, while the cable itself is able to transport much

higher frequencies.

© Copyright IBM Corp. 2001, 2003 Unit 16. Connecting to the Internet 16-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

&DEOHDQG['6/LQ/LQX[

0RVWFDEOHDQG['6/PRGHPVFRQQHFWWR\RXU/LQX[3&
YLDDVPDOO(WKHUQHWQHWZRUNDQGEULGJHURXWHWUDIILFLQWR
WKH,63VQHWZRUN
2WKHUFRQQHFWLRQW\SHVDUHSRVVLEOHWRREXWOHVV
FRPPRQ86%VHULDOZLUHOHVV QRWFRYHUHGKHUH
&RQILJXUH\RXUHWKHUQHWDGDSWHUDVGLUHFWHGE\WKH,63
6WDWLF,3DGGUHVV
'+&3

Figure 16-9. Cable Modems in Linux LX023.0

Notes:
As said, connecting a cable or xDSL modem is nothing more than configuring an ethernet
adapter as DHCP client. This could even be done when installing the system.
A few ISPs do not use ethernet, but use a modem that is connected to your Linux
workstation via a serial cable, USB or wireless. How these modems need to be connected
is outside the scope of this course.

16-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
,QWHUQHW6HFXULW\

%HLQJFRQQHFWHGWRWKHLQWHUQHWLVDVHFXULW\ULVN
(VSHFLDOO\ZLWKDQDOZD\VRQFRQQHFWLRQ FDEOH['6/
(YHU\ZRUNVWDWLRQQHHGVEDVLFVHFXULW\PHDVXUHV
*RRGSDVVZRUGV
1RXQQHHGHGVHUYLFHVUXQQLQJ
/DWHVWYHUVLRQVRIDOOVHUYLFHVWKDWDUHUXQQLQJ
7RGHWHUPLQHQHWZRUNVHUYLFHVWKDWDUHUXQQLQJ
QHWVWDWDQXWS

7RGLVDEOHXQQHHGHGVHUYLFHV
FKNFRQILJ6(59,&(!RII

1HYHUVWDUW\RXUEURZVHUDVURRW
1HYHUORJLQWR\RXUV\VWHPDVURRW XQOHVVQHHGHG 
Figure 16-10. Internet Security LX023.0

Notes:
When connected to the internet, especially when you are connected via a high-bandwidth,
always-on connection with a UNIX like operating system, you are a target for hackers. In
fact, typical hackers routinely scan IP ranges that are known to be assigned to cable
modems or xDSL connections to see if anything interesting is connected.
People have reported 20 or more port scans per day on a typical cable modem or xDSL
connected workstation. In one report, a Red Hat 6.2 system was broken into less than 20
minutes after it was connected!
The objective of these attacks is virtually always to take over control of your workstation,
and to use it to attack other sites. There are numerous war stories about 14-year old kids
who controlled 400 workstations or more.
It is obvious therefore that some sort of security is needed. Linux is considered a fairly
secure operating system, but it is made by people, and people make mistakes. For
example, a simple programming error in the wu-ftp daemon resulted in the break-in of
hundreds of Red Hat Linux 6.2 servers.

© Copyright IBM Corp. 2001, 2003 Unit 16. Connecting to the Internet 16-15
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

The majority of these attacks can easily be prevented though: Most of the Red Hat systems
attacked were not designed as ftp server, and should not have been running the wu-ftpd
daemon in the first place!
It's a little-known fact that hackers can only break in to your system through an open port,
which means: a running network service. From this leads the following observation: if your
workstation does not run any server programs, it can't be broken into7.
On a Linux workstation, there is no reason to run any network service at all (we're not
talking about servers here, obviously). That makes securing a Linux workstation really
simple.
Securing a Linux workstation is basically a two-step process:
First, determine the network services that are running. This is done with the netstat -anut
command. This shows all ports that the system is currently listening on (meaning that a
service is running on that port), and all open connections. For each and every service, you
need to determine what it is, what it does, and whether it is a security risk.
If it is not entirely clear what service is using a certain port, you can add the -p option to the
netstat command, which also shows the PID and process name. Alternatively, you can run
the fuser -n tcp <portnumber> or fuser -n udp <portnumber> command, which will give
you the PID of the process that opened the port. You then need to use ps to find out the
process name.
Second, stop all services that you don't need, and make sure that they're not started again
when you reboot your system. How this is done depends on the distribution involved, but
most distributions use one or more of the following tools:
• ksysv
• ntsysv
• chkconfig
Here is a list of services that are commonly installed on a workstation and their
descriptions:
acpid: Advanced power management daemon for laptops. Can safely
be disabled on a regular workstation, but should be left running
on a laptop.
alsasound: Sound daemon for ALSA (Advanced Linux Sound Architecture).
Can be left running if you want to play sound. Does not open
any network ports.
anacron: Ensures that scheduled jobs are executed even when the
system was down. Do not disable this service.

7 Unless a flaw in the Linux kernel is discovered, or unless you download malicious code (a virus, for example) yourself, either through

the web or by downloading your mail.

16-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty apmd: Older power management daemon for laptops. Can safely be
disabled on a regular workstation, but should be left running on
a laptop.
atd: Daemon used to schedule jobs at some time in the future. Do
not disable this service.
autofs: Service that automatically mounts filesystems when they are
accessed instead of at reboot. Can safely be disabled on a
workstation.
chargen: Network service that generates characters via TCP (port 19).
Should be disabled.
chargen-udp: Network service that generates characters via UDP (port 19).
Should be disabled.
crond: Main scheduling daemon in Linux. Should not be disabled.
daytime: Network service that displays the current day and time via TCP
(port 13). Should be disabled.
daytime-udp: Network service that displays the current day and time via UDP
(port 13). Should be disabled.
echo: Network service that echoes all characters back that are sent to
it via TCP (port 7). Used to test network functions. Should be
disabled.
echo-udp: Network service that echoes all characters back that are sent to
it via UDP (port 7). Used to test network functions. Should be
disabled.
gpm: Daemon that allows you to use your mouse in a text console
(Alt-F1 through Alt-F6). Can be disabled if you don’t use it, but
does not open any network ports.
identd: Network service that allows others to verify your identity (TCP
port 113). Should be disabled in general, but is sometimes
required, particularly if you are using IRC (Internet Relay Chat).
ipchains: Service that starts the ipchains firewall scripts. Enable this only
if you use ipchains rules. (The Red Hat install program
(Anaconda) can configure ipchains rules for you.)
iptables: Service that starts the iptables firewall scripts. Enable this only
if you use iptables rules. iptables and ipchains are mutually
exclusive: only enable one of these, but not both.
isdn: Service that loads ISDN kernel modules and configures ISDN
devices. Only enable this if you have an ISDN adapter.

© Copyright IBM Corp. 2001, 2003 Unit 16. Connecting to the Internet 16-17
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

keytable: Service that loads the correct keyboard mapping file at startup.
Only required if you have a non-US keyboard.
kotalk: KDE network service (UDP port 517) that allows you to talk to
other users on this or other systems. Disable if you don’t use
talk or a variant to communicate with others.
ktalk: KDE network service (UDP port 518) that allows you to talk to
other users on this or other systems. Disable if you don’t use
talk or a variant to communicate with others.
kudzu: Red Hat service responsible for detecting new hardware added
to the system. Can be disabled if you don’t add new hardware
to your system, or configure your hardware manually after
adding it to the system.
lpd: Printer spool daemon. Should not be disabled unless you don’t
print on this system.
netfs: Service that performs network mounts (via NFS or SMB). Can
be disabled if you don’t define remote filesystems or shares in
/etc/fstab.
network: Service that configures low-level networking. Should not be
disabled.
nfs: Network daemon (RPC service; see portmap) that exports
filesystems so that others can access it. Should be disabled
unless you want to share your filesystems with others via NFS.
nfslock: Network daemon (RPC service; see portmap) that needs to run
both on an NFS client and server to support the NFS protocol.
Generally not needed on a workstation, unless you are an NFS
client or server.
ntpd: Network daemon (UDP port 123) that synchronizes clocks on
different systems. Can be disabled unless you use the NTP
protocol to synchronize your clock with another system.
portmap: Network daemon (TCP and UDP port 111) that is needed for all
RPC-based services, such as NFS and NIS. Do not enable
portmap unless you need one of the services nfs, nfslock,
ypbind, or ypserv.
postfix: Network daemon (TCP port 25) which handles incoming and
outgoing e-mail. Should be enabled to receive mail from for
instance the crond subsystem, but should generally be
configured to listen to the loopback interface only.
radvd: Network daemon that advertised routes on IPv6. Do not enable
this service unless you’re on an IPv6 network.

16-18 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty random: Service that saves the random state when the system halts,
and restores it when the system boots. Should be enabled.
rawdevices: Service that assigns raw devices to block devices. Only needed
if you run programs that utilize this, such as Oracle.
rhnsd: Red Hat Network Service Daemon: Server that periodically
connects to the Red Hat Network Servers to check for updates.
Only enable this if you’ve got a subscription to the Red Hat
Network and want to use this daemon to keep your system up
to date.
rsync: Network daemon (TCP and UDP port 873) which offers Remote
Synchronization: A file transfer protocol which only transfers
changes in files. Only enable this if you use rsync.
sendmail: Network daemon (TCP port 25) which handles incoming and
outgoing e-mail. Should be enabled to receive mail from for
instance the crond subsystem, but should generally be
configured to listen to the loopback interface only.
services: Network daemon (TCP port 9099) that lists xinetd services.
Should be disabled.
sgi_fam: Network daemon (RPC service; see portmap) that is used to
monitor file changes. Can be disabled.
snmpd and snmptrapd: Network daemons (TCP and UDP ports 161 and 162) that allow
remote management of this system via the SNMP protocol.
Disable unless your systems need to be remotely managed.
sshd Secure Shell Daemon. Used to login remotely to your system,
to transfer files and to execute commands. If you don’t login to
your system from a remote location, disable this service.
Otherwise, leave it running but make sure you install patches
straight away.
This is a prime target for hackers, mostly because almost every
server runs it so that the administrator can do remote
administration.
syslog: Service that allows logging of events to /var/log/messages and
a few other files. Should be enabled at all times.
time and time-udp: Network daemon (TCP and UDP port 37) that give the current
time when you connect to these ports. Should be disabled.
wine: Service that is needed to run the wine program. Enable this
service if you run Windows programs via wine.
xdm X Display Manager. Allows you to login to your system in
graphical mode (runlevel 5) but also allows remote logins, if

© Copyright IBM Corp. 2001, 2003 Unit 16. Connecting to the Internet 16-19
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

configured incorrectly. If you want to login in graphical mode,


then this service should be running, but make sure it only
listens to the loopback interface. This can be seen with the
command netstat -a.
xfs: Network service (TCP port 7100) that performs font
management for X. Depending on your configuration, you may
need it to run X.
xinetd: Super daemon that manages a large number of ports on behalf
of other programs, and starts the corresponding program only
when the port is actually being accessed. Should only be
enabled if you want to run xinetd server services, such as
chargen, daytime, echo, ftp, time, sgi_fam, talk, telnet and
rsync.
If you are convinced that you need certain network services running, then you must make
sure that you are always running the latest version. If available, subscribe to your
distributions "security" mailing list, so that you are the first to know about any problems.
You might also want to configure your system to use ipchains or iptables and other
firewall techniques. This requires an in-depth knowledge of the TCP/IP protocol suite
however, and that is outside the scope of this course8.

8
The "Linux Network Administration II: Network Security and Firewalls" course (course code LX24) covers this in great detail.

16-20 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&KHFNSRLQW

7)/LQX[EDVHGV\VWHPVDUHPRUHVHFXUHWKDQ
0LFURVRIWEDVHGV\VWHPV<RXWKHUHIRUHGRQ
W
KDYHWRZRUU\DERXWVHFXULW\ZKHQFRQQHFWLQJ
WRWKHLQWHUQHW

:KLFKRIWKHIROORZLQJFRQQHFWLRQPHWKRGVJHQHUDOO\
GRHV127LQYROYH333"
D5HJXODUPRGHPV
E,6'1FRQQHFWLRQV
F&DEOHRU['6/

:KDWLVWKHGHYLFHQDPHRIVHULDOSRUW&20"


Figure 16-11. Checkpoint LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 16. Connecting to the Internet 16-21
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

8QLW6XPPDU\

7KHUHDUHIRXUZD\VRIFRQQHFWLQJWRWKHLQWHUQHW
5HJXODUPRGHP
,6'1FRQQHFWLRQV
&DEOHPRGHPV
['6/
5HJXODUPRGHPVDQG,6'1FRQQHFWLRQVDUHEHVW
FRQILJXUHGXVLQJNSSSRURWKHUJUDSKLFDOGLDOHUV
&DEOHDQG['6/FRQQHFWLRQVDUHW\SLFDOO\FRQILJXUHGDV
UHJXODUHWKHUQHWFDUGV
7KHEHVWQHWZRUNVHFXULW\RQD/LQX[ZRUNVWDWLRQLVQRWWR
UXQDQ\QHWZRUNVHUYLFHVDWDOO

Figure 16-12. Unit Summary LX023.0

Notes:

16-22 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 17. Integrating Linux in a Windows


Environment

What This Unit Is About


This unit will give you an overview of the different possibilities to
integrate Linux in a Windows environment.

What You Should Be Able to Do


After completing this unit, you should be able to:
• Access files on Windows filesystems
• Run Windows programs
• Access Windows servers

How You Will Check Your Progress


Accountability:
• Checkpoint questions
• Machine exercises

© Copyright IBM Corp. 2001, 2003 Unit 17. Integrating Linux in a Windows Environment 17-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2EMHFWLYHV

$IWHUFRPSOHWLQJWKLVXQLW\RXVKRXOGEHDEOHWR
$FFHVVILOHVRQ:LQGRZVILOHV\VWHPV
5XQ:LQGRZVSURJUDPV
$FFHVV:LQGRZVVHUYHUV
5HDG:LQGRZVGRFXPHQWIRUPDWV

Figure 17-1. Objectives LX023.0

Notes:

17-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
$FFHVVLQJ)LOHVRQ:LQGRZV)LOHV\VWHPV

/LQX[8QLILHG
)LOHV\VWHP 

9LUWXDOGLUHFWRU\WUHH XVURSWHWFKRPH

$OOSK\VLFDO
ILOHV\VWHPVDUH
PRXQWHG   

ELQOLEVKDUH;5 NGHJQRPHHWFOQ WX[WX[WX[WX[

:LQGRZV'ULYH/HWWHUV &

IRUHDFKVHSDUDWH ?

ILOHV\VWHP ?ZLQQW?SURJUDPILOHV

' ( )

? ? ?

?RWWR?SGI?GRF?LEP ?NGH?JDPHV?WPS?OQ ?GLU?GLU?GLU?GLU

Figure 17-2. Accessing Files on Windows Filesystems LX023.0

Notes:
In most cases where people integrate Linux in a Windows environment, dual-boot PC's are
used. In this case, data residing on a certain partition will have to be read both by Windows
and by Linux. Since Windows can't handle Linux partitions, this data will be stored on a
Windows filesystem.
Depending on the Windows version used, and the size of the filesystem, various
filesystems may be used:
fat-12 This filesystem is used on Windows floppy disks.
fat-16 This filesystem is used on MS-DOS formatted hard disks.
fat-32 This filesystem is used on Windows-95 formatted hard disks.
vfat This filesystem is virtually identical to fat-32, but supports long filenames.
NTFS This filesystem is used by Windows NT. It is more efficient than all
FAT-based filesystems, and supports Access Control Lists (ACLs).

© Copyright IBM Corp. 2001, 2003 Unit 17. Integrating Linux in a Windows Environment 17-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

NTFS is the only Windows filesystem that (at least, at the time of this
writing) is not fully supported by Linux. Linux supports reading from NTFS,
but so far not writing. Work is underway to enable this as well, though.
Windows partitions are, under Windows, referred to with a drive letter, followed by a colon.
Drives A: and B: are floppy disks, and drive letters C: and up are hard disk partitions. Under
Windows 95 and up, drive letters are assigned in dictionary order by Windows, starting with
the primary partitions on all IDE and SCSI disks, followed by all logical partitions on all IDE
and SCSI disks. Windows NT allows you to assign drive letters to partitions yourself.
Linux partitions are not accessed by drive letters, but are mounted into one big, hierarchical
filesystem. The content of the floppy disk can therefore be found under /mnt/floppy, for
instance.
In order to access Windows filesystems under Linux, there are basically two options:
• Mounting the partition into the Linux filesystem.
• Use the mtools to access the filesystems by drive letters.

17-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
0RXQWLQJ:LQGRZV)LOHV\VWHPV

7RPRXQWWKHILUVWSULPDU\SDUWLWLRQRQ\RXUILUVW,'(KDUG
GLVNRQWKHPRXQWSRLQWPQWZLQ
PRXQWGHYKGDPQWZLQ
RU
PRXQWWYIDWGHYKGDPQWZLQ

$OOILOHVRQ\RXU&GLVNDUHQRZDFFHVVLEOHLQPQWZLQ
0DNHSHUPDQHQWE\DGGLQJWKLVWRHWFIVWDE

GHYKGDH[WGHIDXOWV
GHYKGDERRWH[WGHIDXOWV
GHYKGDVZDSVZDSGHIDXOWV
GHYKGDPQWZLQYIDWGHIDXOWV

Figure 17-3. Mounting Windows Filesystems LX023.0

Notes:
Since the Linux kernel supports virtually all Windows filesystems, it can simply mount the
filesystem into the Linux virtual filesystem structure. This is done with the mount
command.
If you want the mount to be permanent, you should add an entry for it to the /etc/fstab file.
Note: Not all distributions include read-only support for the NTFS filesystem. This
particularly applies to Red Hat. On such systems, NTFS filesystems cannot be mounted
unless a new kernel is compiled with NTFS support enabled. Kernel compiles are outside
the scope of this course. If you have a dual-boot system with Windows NT, 2000 or XP,
create a separate partition, formatted as FAT, which holds the files that need to be
accessible both from Windows NT/2000/XP and Linux.

© Copyright IBM Corp. 2001, 2003 Unit 17. Integrating Linux in a Windows Environment 17-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

$FFHVVLQJ:LQGRZV)LOHV\VWHPV'LUHFWO\

PWRROVLVDFROOHFWLRQRIWRROVWKDWFDQUHDGZULWH
:LQGRZVILOHV\VWHPVGLUHFWO\XVLQJGULYHOHWWHUV
PFRS\FDXWRH[HFEDWURRWDXWRH[HFEDW
PIRUPDWD
PGLUD

'HYLFHVPXVWQRWEHPRXQWHG
'ULYHOHWWHUVDUHPDSSHGWRSK\VLFDOGHYLFHVLQ
HWFPWRROVFRQI

GULYHDILOH GHYIGH[FOXVLYHPPIRUPDWBRQO\
GULYHFILOH GHYKGD

Figure 17-4. Accessing Windows Filesystems Directly LX023.0

Notes:
The mtools is a collection of programs that can read/write Windows filesystems directly,
without mounting them, using drive letters. All commands have the same name (with an
"m" prepended) and the same syntax as the corresponding MS-DOS/Windows command.
The commands included in the mtools are:
mattrib Change MS-DOS file attribute flags
mbadblocks Tests a floppy disk, and marks the bad blocks in the FAT
mcat Dump raw disk image
mcd Change MS-DOS directory
mcopy Copy MS-DOS files to/from UNIX
mdel Delete an MS-DOS file
mdeltree Delete an MS-DOS directory tree
mdir Display an MS-DOS directory

17-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty mdu Display the amount of space occupied by an MS-DOS directory


mformat Add an MS-DOS filesystem to a low-level formatted floppy disk
minfo Print the parameters of an MS-DOS filesystem
mlabel Make an MS-DOS volume label
mmd Make an MS-DOS subdirectory
mmount Mount an MS-DOS disk
mmove Move or rename an MS-DOS file or subdirectory
mpartition Partition an MS-DOS hard disk
mrd Remove an MS-DOS subdirectory
mren Rename an existing MS-DOS file
mtoolstest Tests and displays the mtools configuration
mtype Display contents of an MS-DOS file
mzip Change protection mode and eject disk on Zip/Jazz drive
All commands use the /etc/mtools.conf file to determine the drive letter assignation.
Note that in order to avoid inconsistencies, drives accessed by the mtools may not be
mounted!

© Copyright IBM Corp. 2001, 2003 Unit 17. Integrating Linux in a Windows Environment 17-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

5XQQLQJ:LQGRZV3URJUDPV

7RUXQD:LQGRZVSURJUDPWKHXQGHUO\LQJ:LQGRZV26
QHHGVWREHHPXODWHG
&DQEHGRQHDWWZROHYHOV
(PXODWHD3&DQGLQVWDOO:LQGRZVRQLW
(PXODWH:LQGRZVLWVHOI
1RWHWKDW\RXQHHGDOLFHQVHIRU:LQGRZVLI\RXXVHDQ\
:LQGRZVVRIWZDUH LQFOXGLQJVLQJOH'//V

Figure 17-5. Running Windows Programs LX023.0

Notes:
Every Windows program that you want to run under Linux, expects the underlying
operating system to be Windows. So you will have to somehow emulate this operating
system. This can be done in roughly two ways:
• By emulating a PC and installing Windows on this emulated PC.
• By emulating Windows itself.
Depending on your needs, one or both solutions can be used.
One word of caution. If you want to run Windows programs under Linux, you may need
various components (most often DLLs) from the Windows environment. If you use these
components, make sure that you have a license to use these!

17-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
3&(PXODWRUV

(PXODWHD3&RQZKLFK\RXLQVWDOO:LQGRZV
'RQHHGD:LQGRZVOLFHQVH
%RFKV KWWSERFKVVRXQGIRUJHQHW
(PXODWHVDFRPSOHWH3&LQVRIWZDUH
&DQUXQXQGHUDQ\326,;FRPSDWLEOH26
&DQUXQRQDQ\DUFKLWHFWXUH
2SHQ6RXUFH
%LJSHUIRUPDQFHORVV
90:DUH KWWSZZZYPZDUHFRP
(PXODWHVDFRPSOHWH3&LQVRIWZDUH
2QO\UXQVRQ/LQX[,QWHORU:LQGRZV17,QWHO
&RPPHUFLDO3URGXFW
$ERXWSHUIRUPDQFHORVV

Figure 17-6. PC Emulators LX023.0

Notes:
A PC emulator is a piece of software that emulates a complete PC, including a CPU,
memory, BIOS, hard disks and various other devices in software. On this emulated PC you
can install basically any PC operating system you want. The disadvantage of such a
solution is that there is a performance loss when comparing performance to running the
same OS on a native PC. How large this loss is, is dependent on a large number of factors.
Various PC emulators exist, and we will cover two of them here.
Bochs is an open source PC emulator that works completely in software: Every CPU
instruction is completely handled by the Bochs software. This makes it possible to run
Bochs under any POSIX compatible operating system. (Every UNIX is by definition POSIX
compliant.) This is an obvious advantage. The disadvantage is that there is an extreme
performance loss. Using Bocks in a production situation is therefore only recommended for
really fast workstations with really low performance requirements regarding the Windows
application.
VMWare is a commercial PC emulator that makes use of special features of the Pentium
processor. These features allow VMWare to let the CPU itself execute most CPU

© Copyright IBM Corp. 2001, 2003 Unit 17. Integrating Linux in a Windows Environment 17-9
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

instructions, instead of emulating these CPU instructions in software. VMWare is therefore


much faster than Bochs. In fact, people have reported a performance loss of only 30%,
compared to running the guest OS natively on the hardware. If you have a reasonably fast
workstation (anything over a Pentium running at 300 MHz will do), and not very high
performance requirements, then this is a fairly reasonable solution. The disadvantage of
VMWare is that it only runs on Linux and Windows NT on the Intel platform.

17-10 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
90:DUH6FUHHQVKRW

Figure 17-7. VMWare Screenshot LX023.0

Notes:
The visual shows VMWare in action. When started, it opens a window, and in this window
emulates a complete PC. When the virtual power button is pressed, the BIOS takes control
and tests the memory. It then proceeds to boot the operating system from the virtual hard
disk.

© Copyright IBM Corp. 2001, 2003 Unit 17. Integrating Linux in a Windows Environment 17-11
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

:LQGRZV(PXODWRUV

ZLQOLQ KWWSZZZQHWUDYHUVHFRP
&RPPHUFLDOSURGXFW
(PXODWHV:LQGRZVNHUQHO
1HHGV:LQGRZV'//V
1HHGV:LQGRZVOLFHQVH
:,1(:,1GRZV(PXODWRU KWWSZZZZLQHKTFRP
2SHQ6RXUFHSURGXFW
'RHVQRWQHHGD:LQGRZVOLFHQVHLIRQO\:,1(RU
WKLUGSDUW\'//VDUHXVHG
&DQXVH:LQGRZV'//V EHZDUHRIOLFHQVH
7RVHHLI\RXUDSSOLFDWLRQLVVXSSRUWHGJRWRZHEVLWH
&URVV2YHU2IILFH KWWSZZZFRGHZHDYHUVFRP 
FRPPHUFLDOH[WHQVLRQWR:,1(

Figure 17-8. Windows Emulators LX023.0

Notes:
While PC emulators allow you to install virtually any PC operating system, but with a
performance loss, Windows emulators only emulate the Windows operating system, but
with virtually no performance loss whatsoever. In fact, people have even reported
performance increases!
Two Windows emulators are well known: win4lin and WINE.
win4lin is a commercial product from Netraverse. It emulates the Windows kernel, but
needs the Windows DLLs from the Windows CD. You therefore need a Windows license in
addition to a win4lin license to use this. Once installed, it runs virtually any Windows
application without a problem, and without a performance loss. win4lin only runs on Linux.
The WINE project is aimed at creating a complete open source Windows Emulator, which
eventually should allow you to run any Windows application without a Windows license. At
the time of this writing, about 95% of the Windows APIs have been implemented, which
allows you to use most of the Windows software currently on the market. The WINE
website features a large database where people can report their rate of success in running

17-12 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty a particular application. WINE runs on any Intel-based UNIX, including Linux, FreeBSD and
Solaris.
With native WINE, you need to install the application involved on a Windows system first,
and then copy it over to Linux, or use it from its own Windows partition (in a dual-boot
situation). CrossOver Office is a commercial extension to WINE, developed by
CodeWeavers (http://www.codeweavers.com). It allows you to actually install the Windows
application under Linux directly.

© Copyright IBM Corp. 2001, 2003 Unit 17. Integrating Linux in a Windows Environment 17-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

ZLQOLQ6FUHHQVKRW

Figure 17-9. win4lin Screenshot LX023.0

Notes:
The visual shows win4lin in action. win4lin emulates the Windows kernel, on top of which
all regular Windows programs can run, including your taskbar, the configuration panel and
so forth.

17-14 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
:,1(6FUHHQVKRW

Figure 17-10. WINE Screenshot LX023.0

Notes:
The visual shows WINE in action. An application running under WINE works just like any
other application under Linux. Note that in the top right corner of the application the
Minimize, Maximize and Close buttons have been messed up. This is an example of a
minor bug in WINE, which is harmless in most cases. After minimizing and maximizing the
application, the buttons are normal again.

© Copyright IBM Corp. 2001, 2003 Unit 17. Integrating Linux in a Windows Environment 17-15
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

$FFHVVLQJ:LQGRZV6HUYHUV

6DPED KWWSZZZVDPEDRUJ
2SHQ6RXUFHSURGXFW
5XQVRQDQ\81,;
8VHGWRUHSODFHD:LQGRZVVHUYHU QRWFRYHUHGKHUH
$OVRLQFOXGHVDQXPEHURIFOLHQWWRROVVPEFOLHQW
VPEPRXQWVPESULQW
VPEFOLHQWDOORZV\RXWRUHWULHYHLQIRUPDWLRQDERXWD
:LQGRZVVHUYHUDQGWRDFFHVVILOHVIWSVW\OH
VPEPRXQWDOORZV\RXWRPRXQW:LQGRZVVKDUHVRYHU
WKHQHWZRUN
VPESULQWDOORZV\RXWRSULQWGRFXPHQWVWRD
:LQGRZVDWWDFKHGSULQWHU

Figure 17-11. Accessing Windows Servers LX023.0

Notes:
In a Windows environment, your data will frequently reside on a Windows server, or you will
need to access printers that are connected to Windows servers.
In order to be able to do this, you need to act like a Windows client to the server. This can
be done using the client tools from the Samba product.
Samba is an open source product which is used to replace Windows servers. It can run on
any UNIX. The server side of Samba is not covered in this course1.
Samba includes a number of client tools as well, which were originally used to test the
server side of Samba, but have grown to be an excellent solution when you want to
integrate Linux in a Windows environment.

1
There is a separate, two day course about Samba available from IBM under course code LX26.

17-16 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Three tools are important in this respect:


• smbclient allows you to retrieve information about a Windows server, and to access
files on that server using an ftp-like interface.
• smbmount allows you to mount a Windows share and access it as if it were local files.
• smbprint allows you to print files on a Windows-attached printer.

© Copyright IBM Corp. 2001, 2003 Unit 17. Integrating Linux in a Windows Environment 17-17
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

VPEFOLHQW([DPSOHV

 VPEFOLHQW/ZLQVHUYHU1
VPEFOLHQW/ZLQVHUYHU8XVHU
VPEFOLHQW/ZLQVHUYHU8XVHUSDVVZRUG
VPEFOLHQWZLQVHUYHUVKDUH8XVHUSZ
VPE!JHWILOH
VPE!SXWILOH
VPE!TXLW

2SWLRQV
/ OLVWVWKHVKDUHVRQWKHVHUYHU
1 JXHVWDFFHVV
8 TXDOLILHGDFFHVV

Figure 17-12. smbclient Examples LX023.0

Notes:
The smbclient tool allows you to do various things as a Windows client. The first thing is to
retrieve information about a Window server. This is done with the -L <servername> option.
The -N option allows you to set up anonymous connections, and the -U <username> or
-U <username>%<password> allows you to retrieve information as a specific user.
Note: if you use the <username>%<password> notation, then you need to realize that
everybody on the system can read your password with a simple ps command!
You can also access your files using smbclient. This is done by specifying the share as
//winserver/share2. When the connection has been made, we can then access the files on
the share with the ftp-style commands get, put and so forth.

2 Note that we are using forward slashes here, because the backslash has a special meaning for the shell. We can use backslashes too,

but we need to escape them from the shell. The full command will then be smbclient \\\\winserver\\share -U user%pw.

17-18 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
VPEPRXQW([DPSOHV

7RPRXQWDVKDUHDVDQILOHV\VWHP
VPEPRXQWZLQVHUYHUVKDUHPQWZLQ
RU
PRXQWWVPEIVZLQVHUYHUVKDUHPQWZLQ
PRXQWWVPEIVRXVHUQDPH WX[?
!SDVVZRUG VHFUHWZLQVHUYHUVKDUHPQWZLQ

0DNHSHUPDQHQWE\DGGLQJWKLVWRHWFIVWDE

GHYKGDH[WGHIDXOWV
GHYKGDERRWH[WGHIDXOWV
GHYKGDVZDSVZDSGHIDXOWV
ZLQVHUYHUVKDUHPQWZLQVPEIVGHIDXOWVXVHUQDPH XVHUSDVVZRUG

Figure 17-13. smbmount Examples LX023.0

Notes:
The Linux kernel has support for the "smbfs" built-in. We can therefore mount a Windows
share as any other filesystem. This is done with the smbmount command. The -o option
allows you to specify the username and password to be used.
If you want to make this permanent, you can add the share to your /etc/fstab file. It will then
automatically be mounted when your system boots.
Note again that if you put the password on the command line or in the /etc/fstab file, then
everybody on the system is able to see the password, through a ps command or by
viewing the contents of /etc/fstab!

© Copyright IBM Corp. 2001, 2003 Unit 17. Integrating Linux in a Windows Environment 17-19
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

VPESULQW

VPESULQWLVXVXDOO\QRWFDOOHGGLUHFWO\EXWLQWHJUDWHGLQWR
SULQWHUVSRROPHFKDQLVP
&RQILJXUHXVLQJWKHUHJXODUSULQWHUFRQILJXUDWLRQ
WRROV
6HOHFW60%3ULQWHU
&RQILJXUHVHUYHUQDPHSULQWHUQDPHSULQWHUW\SH
XVHUQDPHDQGSDVVZRUG
$IWHUFRQILJXUDWLRQWKHQHZSULQWHUFDQEHXVHGDVD
QRUPDOSULQWHU

Figure 17-14. smbprint LX023.0

Notes:
smbprint is used to print files on a Windows-attached printer. It is usually not called from
the command line, but integrated in the printer subsystem, so that all files for this printer
can be printed to a local queue. smbprint then forwards these files to the remote server.
Configuration of this setup is done through the regular printer configuration tools.
When configured, you can use the printer like any other printer.

17-20 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
5HDGLQJ:LQGRZV'RFXPHQW)RUPDWV

0RVWQDWLYHRIILFHSURJUDPVIRU/LQX[UHDGDQGVDYH
:LQGRZVGRFXPHQWIRUPDWV
6WDU2IILFH2SHQ2IILFH
NRIILFH
$EL:RUG

ILOHP\WH[WGRF
P\WH[WGRF0LFURVRIW2IILFH'RFXPHQW
VZULWHUP\WH[WGRF

1RWHWKDWQRWDOOGRFXPHQWIHDWXUHVPD\EHVXSSRUWHG

Figure 17-15. Reading Windows Document Formats LX023.0

Notes:
Most native office applications for Linux, such as StarOffice/OpenOffice, koffice and
AbiWord can read, and in most cases also write documents in Microsoft Windows native
formats.
Note however that not all document features may be supported. As an example, if you try
to open a Powerpoint presentation that has a video clip in it, in kpresenter, then the
presentation will be read correctly, but the video clip will not play. This is simply because
kpresenter as of yet does not have the ability to play video clips.

© Copyright IBM Corp. 2001, 2003 Unit 17. Integrating Linux in a Windows Environment 17-21
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

2WKHU8VHIXO3URJUDPV

UGHVNWRS&RQQHFWWRD:LQGRZV7HUPLQDO6HUYHU
GRVXQL[DQGXQL[GRV&RQYHUW:LQGRZVWH[WILOHV
&5/) WR81,;WH[WILOHV /)
F\JZLQ KWWSZZZF\JZLQFRP 6HULHVRI/LQX[WRROV
UXQQLQJXQGHU:LQGRZV

Figure 17-16. Other Useful Programs LX023.0

Notes:
There are a few other programs that may be useful if you try to integrate your Linux
workstation in a Windows environment:
rdesktop is a program that runs under Linux and allows you to connect to a Windows
Terminal Server. This essentially allows you to run applications on the Windows server,
with the output displayed in the rdesktop window on your Linux workstation.
dos2unix and unix2dos are little programs that convert text files in Windows format (using
the CR/LF end-of-line standard) to UNIX format (using the single LF end-of-line standard)
and vice versa.
cygwin is a library that implements the UNIX API, combined with a set of Linux tools, that
run under Windows. This means that all the tools that you learned how to use in this
course, including vi, are now available under Windows as well.

17-22 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty
&KHFNSRLQW

7)7RPDNHDPRXQWRID:LQGRZVILOHV\VWHP
SHUPDQHQW\RXQHHGWRDGGLWWRHWFIVWDE

<RXZDQWWRUXQDWKLUGSDUW\SURJUDPXQGHU/LQX[WKDW
ZDVZULWWHQWRUXQXQGHU:LQGRZV:KLFKVROXWLRQ
GRHVJHQHUDOO\QRWUHTXLUH\RXWRKDYHD:LQGRZV
OLFHQVH"
D%RFKV
E:,1(
F90:DUH
G:LQ/LQ

:KDWFRPPDQGDOORZV\RXWRPRXQWDVKDUHIURPD
:LQGRZVVHUYHU"
Figure 17-17. Checkpoint LX023.0

Notes:

© Copyright IBM Corp. 2001, 2003 Unit 17. Integrating Linux in a Windows Environment 17-23
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

8QLW6XPPDU\

7RDFFHVVILOHVRQ:LQGRZVILOHV\VWHPVHLWKHUPRXQW
WKHVHILOHV\VWHPVRUXVHWKHPWRROV
7RUXQ:LQGRZVSURJUDPVXVHD3&HPXODWRUVXFKDV
%RFKVRU90:DUHRUXVHD:LQGRZVHPXODWRUVXFKDV
ZLQOLQRU:,1(
&URVV2YHU2IILFHDOORZV\RXWRLQVWDOO:LQGRZV
SURJUDPVGLUHFWO\XQGHU/LQX[
7RDFFHVV:LQGRZVVHUYHUV\RXFDQXVHWKHFOLHQW
SURJUDPVIURPWKH6DPEDSURGXFWVPEFOLHQW
VPEPRXQWDQGVPESULQW
7RUHDG:LQGRZVGRFXPHQWIRUPDWV\RXFDQXVHDOPRVW
DQ\QDWLYH/LQX[RIILFHSURJUDP6WDU2IILFH2SHQ2IILFH
NRIILFH$EL:RUGDQGRWKHUV
6HYHUDORWKHUXVHIXOSURJUDPVH[LVWLQFOXGLQJUGHVNWRS
Figure 17-18. Unit Summary LX023.0

Notes:

17-24 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Appendix A. Checkpoint Solutions


Unit 1. Introduction to Linux
1. False
2. b
3. Tux.

Unit 2. Installing Linux


1. True
2. b
3. A currently installed and configured operating system, such as
Windows.

Unit 3. Using the System


1. False
2. a, b and d are all illegal commands
3. By entering the key combination Alt-Fn, or, when in X, Ctrl-Alt-Fn.

Unit 4. Working with Files and Directories


1. False
2. b
3. cp /home/tux1/mydoc /tmp/tempdoc

Unit 5. File and Directory Permissions


1. yes
2. yes
3. yes
4. no
5. yes
6. yes

© Copyright IBM Corp. 2001, 2003 Appendix A. Checkpoint Solutions A-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Unit 6. Linux Documentation


1. False
2. a
3.
a. User commands
b. System calls
c. Libc calls
d. Devices
e. File formats and protocols
f. Games
g. Conventions, macro packages and so forth
h. System administration
i. Linux kernel

Unit 7. A Tour through Linux


1. False
2. b
3. ln/etc

Unit 8. Editing Files


1. False
2. b
3. An editor that displays a file in hexadecimal format and thus allows
you to make changes to files with nonprintable characters, such as
binary files.

Unit 9. Working with Processes


1. False
2. d
3. A daemon is a never-ending background process that controls a
system resource or performs a network service.

A-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

Uempty Unit 10. Shell Basics


1. False
2. b
3. By starting bash with the name of the script as parameter.
By making the script executable and running it like a normal
program.
By executing the script in the current shell with the . (dot)
command.

Unit 11. Linux Utilities


1. False
2. b
3. Generate a long, recursive list, starting from /.
Pick only those lines that end with txt or tab.
Sort this list numerically and in reverse order on the fifth column
(which contains the size of the file).
Discard lines one through three.
Display only the first five lines.

Unit 12. Shell Scripting


1. The script will set a variable TERMTYPE to the value of the TERM
variable.
In the if statement the TERMTYPE variable is tested to see if it is
not empty.
If the test is true (TERMTYPE is not empty), than a second check
will be carried out to ensure that /home/tux1/custom_script is an
ordinary file.
If it is, it will be executed.
If it is not an ordinary file, then the message No custom script
available! will be displayed.
If the first test is not true (TERMTYPE is empty), the message You
don't have a TERM variable set! will be displayed.
2. expr $1 \* $2
- OR -

© Copyright IBM Corp. 2001, 2003 Appendix A. Checkpoint Solutions A-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

echo $(( $1 * $2 ))

Unit 13. The Linux Gui


1. False
2. a
3. With the startx command, or by switching the system to runlevel 5.

Unit 14. Customizing the User Environment


1. $HOME/.bash_profile because this overwrites the defaults set in
/etc/profile. If the settings can not be exported to subshells, the
$HOME/.bashrc file can be used.
2. PATH Define the directories to look for commands
PS1 Your primary shell prompt

Unit 15. Basic System Configuration


1. True
2. d
3. cd /usr/src
tar -zxvf archive-version.tar.gz
cd <archivename>
Read INSTALL or README file for further installation instructions.

Unit 16. Connecting to the Internet


1. False
2. c
3. /dev/ttyS1

Unit 17. Integrating Linux in a Windows Environment


1. True
2. b
3. smbmount

A-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

AP Appendix B. Certification Information


As mentioned in this course, Linux is not a product which is owned by a single company.
Instead, it is developed by a loose team of volunteers on the Internet. As such, there is no
"natural" body responsible for Linux certification. At this moment, at least four organizations
have tried to fill this void and have come up with their own Linux certification program. IBM
supports three of these organizations:
• The Linux Professional Institute (http://www.lpi.org) is an organization run by
volunteers with the sole purpose of implementing a vendor-neutral certification program
for Linux. They are sponsored by a number of Linux-related companies, among which
IBM. The certification tests are delivered by VUE (Virtual University Enterprises)
(http://www.vue.com). LPI aims to implement three levels of certification, of which the
first two levels are currently ready.
UnitedLinux (the consortium of Linux distributors SuSE, SCO, TurboLinux and
Conectiva, http://www.unitedlinux.com) has announced a UnitedLinux certification,
which will be an extension of the LPI certification.
• CompTIA (http://www.comptia.org) is the organization that has, in the past, already
developed a number of certifications that are aimed mostly at helpdesk personnel and
hardware engineers. Recently CompTIA introduced the Linux+ exam, which is aimed
at Linux Professionals with 6 months of experience with Linux. CompTIA tests are also
delivered by VUE, and by Prometric (http://www.prometric.com).
• Red Hat (http://www.redhat.com) is the distributor of Red Hat Linux, one of the leading
commercial Linux distributions. As part of their service organization they have
developed their own education leading to the Red Hat Certified Technician and Red
Hat Certified Engineer exams. In contrast to the other Linux exams, the RHCT and
RHCE exams are performance based, which means that the examinee takes place
behind an actual Red Hat Linux system and needs to demonstrate his/her skills on this
system. The practical components of the RHCT exam takes about 2.5 hours, while the
practical components of the RHCE exam take about five hours.
For all three certification programs, the support of IBM extends to the following:
1. Involvement and/or active support in developing the certification program, the exam
objectives and test questions.
2. Where appropriate: sponsoring the certification program.
3. Developing courseware and teaching courses to prepare students for certification, and
where possible certifying this course material for the exams involved.
4. Exam delivery.

© Copyright IBM Corp. 2001, 2003 Appendix B. Certification Information B-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

IBM IT Education Services Courseware


IBM IT Education Services started developing courseware for Linux at the end of 1998,
when no certification programs for Linux existed. The Linux curriculum was heavily
modeled after the AIX curriculum, but has changed since to reflect the different ways Linux
and AIX are being used today. IBM's Linux course material is not tied to any particular
distribution, and is also not tied to any particular certification.
The total curriculum consists of more than fifteen courses that cover the Linux Operating
System, and an even larger number of courses that cover IBM middleware that runs on
Linux (such as DB2, MQ Series, Lotus Domino and so forth) and IBM hardware. For the
purpose of certification though, only seven courses are important:
The LX02 (Linux Power User) is the entry course in the IBM/Linux curriculum. Its aim is to
teach a Linux novice to install and configure Linux so that he/she is able to run Linux on
his/her personal workstation or home system in an environment that is mostly based on
MS-Windows.
The LX03 (Linux System Administration I: Implementation) is the main system
administration course. Its aim is to teach a Linux user the techniques and practices used in
installing, configuring, running and maintaining a Linux-based server.
The LX07 (Linux Network Administration I: TCP/IP and TCP/IP Services) is the main
network administration course. Its aim is to teach a Linux system administrator how to
configure TCP/IP and various TCP/IP services that run on Linux.
The LX22 (Linux Perl Programming) is the course that covers Perl programming.
The LX23 (Linux Bash Programming) is the course that covers Bash shell programming
and the various programs that are typically used in shell programs, such as grep, awk and
sed.
The LX24 (Linux Network Administration II: Network Security and Firewalls) covers
the configuration of a full-function firewall under Linux. As such, it also covers a number of
security aspects of Linux that are not particularly related to firewalls, but apply to any
networked system.
The LX25 (Linux as a Web server - Apache) is the course which covers Apache, the most
commonly used web server on Linux and other UNIX platforms.
The LX26 (Linux integration with Windows - Samba) is the course which covers Samba,
the product which emulates a networked Windows NT server to the network.
All these courses are available from IBM IT Education Services and selected business
partners (pricing and availability may differ from country to country). For information on
pricing and scheduling, contact your local IBM IT Education Services representative.
IBM IT Education Services has developed these courses so that they can be taken in a
logical order. Furthermore, the organization of topics into courses is such that at the end of
a course, a student is able to fully grasp a topic, and is able to apply this successfully on his
Linux system(s).

B-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

AP From Education to Certification


IBM’s arrangements of topics into IBM’s Linux courses is not always consistent with the
requirements of the supported certifications. This leads to a problem when determining
which courses are needed for which certification. A certain test might require "installation
and basic configuration" of a product. This is covered by a certain IBM/Linux course, but
that very same course also covers "advanced configuration", which might be the subject of
an entirely different test.
As an example, IBM has one, two-day course about Samba (the LX26), which fully covers
the whole Samba product and its possibilities. Samba knowledge is tested by the LPI in two
places though: Test 102 (topic 1.13, objective 4) requires the examinee to "install and
configure Samba using the included GUI tools or direct edit of the /etc/smb.conf file" (which
is covered in the first two units of the LX26), while test 201 (topic 2.9, objective 1) requires
that "the candidate should be able to set up a Samba server for various clients, including
setting up a login script and setting up and nmbd WINS server" (which is the end objective
of the LX26).
This problem is too fundamental to solve by simply changing or rearranging the course
material, apart from the fact that we think that it is not desirable to specifically write courses
for certification. One of the purposes of this attachment is therefore to identify the areas
where IBM's course material does not match with certification objectives.

© Copyright IBM Corp. 2001, 2003 Appendix B. Certification Information B-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Education/Certification Matrix

The following table lists the required and recommended courses for each of the supported
certification programs:
CompTIA LPI Red Hat
Course
Linux+ Test 101 Test 102 Test 201 Test 202 RHCT RHCE
LX02 Required Required Required Required Required Required Required
LX03 Required Required Required Required Required Required Required
LX07 Required Required Required Required
LX22 Recomm.
LX23 Recomm. Recomm.
LX24 Required Recomm.
LX25 Recomm. Required Recomm.
LX26 Recomm. Required Recomm.
Remarks to the table:
1. Required means: the subjects covered in this course are essential knowledge to pass
the exam.
Recommended means that a small portion of the exam (less than 5%) is covered in the
course listed. It is possible to pass the exam without this knowledge. Students do so
however at their own risk and should compare their knowledge with the exam
objectives.
2. CompTIA Linux+ also requires intimate knowledge of PC hardware in general (Domain
7) which accounts for 19% of the exam. This includes knowledge of the BIOS, IRQs, I/O
ports, DMA, ATA devices, SCSI devices, IEEE 1394 devices, PCMCIA devices, ISA
devices, PCI devices, APM and the ability to configure and replace them, were
applicable. This part of the exam is not related to Linux and thus not covered in any of
IBM’s Linux courses. CompTIAs own education (and other education) that leads to
CompTIA A+ certification may be used to obtain this knowledge.
3. ProCert (http://www.procert.com) has certified these courses as appropriate course
material for preparing for LPI certification tests. This certification is only valid if all
courses, including the courses that are listed here as “recommended” are taken before
attempting an LPI certification test.
4. IBM IT Education Services is a Red Hat Authorized Training Partner and as such
allowed to teach the Red Hat courses RH033, RH133 and RH253. These courses can
be used as an alternative to LX02, LX03 and LX07, respectively, to prepare for
RHCT/RHCE certification. They cannot be used for other certifications though, and
these courses are not scheduled in all countries.

B-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0
Student Notebook

IX Index
Symbols /etc/X11/XF86Config-4 13-9
! 3-26 /home 7-10
- 12-25 /lib 7-4
" 10-27 /media 7-11
# 3-10, 12-24 /mnt 7-11
#! 12-7 /opt 7-19
$ 3-10, 11-18 /proc 7-12
$# 12-9 /root 7-13
$$ 9-3, 9-6, 10-24 /sbin 7-4
$(( )) 12-25 /tmp 7-14
$() 10-19 /usr 7-15
$* 12-9 /usr/local 7-16
$? 10-26, 12-15 /var 7-17
$@ 12-9 < 10-9
$1 12-9 << 12-11
$2 12-9 == 12-15
$BASH_ENV 14-4 > 10-10
$HOME 10-25 >> 10-10
$HOME/.bash_login 14-3 ? 10-6
$HOME/.bash_profile 14-3 \ 10-27
$HOME/.bashrc 14-4 \b 10-28
$HOME/.profile 14-3 \n 10-28
$LANG 10-25 \t 10-28
$PATH 7-4, 10-24, 12-4, 12-5 ^ 11-18
$PS1 10-24 { 10-20
$PS2 10-25 | 10-14
$PWD 10-25 || 12-13, 12-17
$variable 10-22 } 10-20
% 12-25 ‘ 10-19
&& 12-13, 12-17
&> 10-13 Numerics
' 10-27 2> 10-11
( 10-20, 12-25 2>> 10-11
) 10-20, 12-25 80386 1-5
* 10-6, 12-25
+ 12-25
. 11-18, 12-6 A
.tar.gz files 15-10 AbiWord 17-21
.tgz files 15-10 acpid 16-16
/ 12-25 alias 4-23, 10-29
/bin 7-4 alsasound 16-16
/boot 7-5 anacron 16-16
/dev 7-7 apmd 16-17
/dev/null 4-4, 10-11 apropos 6-6
/etc 7-9 arithmetic 12-25
/etc/bashrc 14-5 atd 16-17
/etc/fstab 7-23, 17-5 autofs 16-17
/etc/inittab 13-14 awk 10-16, 12-7
/etc/modules.conf 15-14, 15-15
/etc/profile 14-3
/etc/skel 7-9 B
/etc/X11/XF86Config 13-9 backticks 10-19

© Copyright IBM Corp. 2001, 2003 Index X-1


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

bash 1-4, 10-3 csh 9-6, 12-7


bg 9-12, 9-13 CUPS 15-12
BIOS 7-5 cupsd 15-13
Block special devices 7-7 cut 11-12
Bochs 17-9 -d option 11-13
boot disk 2-26 -f option 11-13
Boot Loader 2-17 CVS. See Concurrent Versioning System
boot loader 2-17 cygwin 17-22
bootable media 2-10
BootMagic 2-17
Bourne Again Shell 10-3 D
Broadcast Address 2-19 daemon 9-22
BSD 15-12 date 3-16
BSD license 1-9 daytime 16-17
Default gateway 2-19
Default router 2-19
C Desktop Environment 13-10
Cable modem 16-4, 16-11 devices 7-7
cal 3-17 dhclient 15-16
cat 4-20, 10-17 DHCP 2-19, 15-15
cd 4-9 Directories 4-4
Character special devices 7-7 directories 4-4
chargen 16-17 Disk Druid 2-7, 2-15
chat 16-7 display manager 13-15
chkconfig 16-16 display managers 9-5
chmod 5-9, 12-5 DNS server 2-19
clear 3-20 documentation 6-15
Command grouping 10-20 dollar sign 3-10
command prompt 3-10 dos2unix 17-22
Command substitution 10-19 drive letters 7-3
commands
--help option 6-12
Common UNIX Printing System 15-12 E
compress 11-29 echo 3-20, 9-3, 9-6, 16-17
CompTIA B-1 egrep 11-21
Concurrent Versioning System 1-10 else 12-13, 12-18
Conditional execution 12-13 emacs 1-4, 8-3
configuration Ethernet 2-19
automated 15-4 ex 8-7
firewall 2-24 exit 3-29
manual 15-4 expand 10-16
modem 2-24 export 10-23
network 15-15 expr 12-27
printer 2-24, 15-12 extended partition 2-5
sound 15-14
sound card 2-24
temporary 15-4
F
fdisk 2-7, 2-15
time zone 2-24
fg 9-12, 9-13
tools 15-5
fgrep 11-21
console 3-4
fi 12-13, 12-18
core dump 9-15
file 8-3, 11-28
cp 4-16
binary 4-4
-i option 4-17
descriptors 10-8
-R option 4-17
editing 8-3
crond 16-17
hidden 4-5
CrossOver Office 17-13

X-2 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

internal structure 4-3 hash sign 3-10


naming 4-5 head 11-24
special 4-4 hexdump 4-22
text 4-4 history 3-25
filters 10-15 Hostname 2-19
find 11-3 HOWTOs 6-13
-a option 11-9 Hurd 1-4
-exec option 11-6
-mtime option 11-8
-newer option 11-8 I
-o option 11-9 IDE 2-6
-ok option 11-7 identd 16-17
-perm option 11-8 if 12-13, 12-18
-print option 11-5 ifconfig 15-15
-size option 11-8 info 6-8
-type option 11-8 init 9-4, 9-16
finger 3-19 Initial RAM Disk 2-17
fmt 10-17 initrd. See Initial RAM Disk
for 12-21, 12-22 installation class 2-14
Free Software Foundation 1-3 installation program 2-12
fsck 7-18 Internet Service Provider 16-3
FSF. See Free Software Foundation IP address 2-19
fuser 16-16 ipchains 16-17, 16-20
iptables 16-17, 16-20
ISDN 16-4, 16-8
G isdn 16-17
gcc 1-4 isdn-config 16-9
gdb 9-15
gdm 9-5, 13-15, 13-16
General Public License 1-8 J
GIMP 13-12 Job Control 9-12
glibc 1-4 job number 9-9
GNOME 13-13 jobs 9-12
GNU Object Modeling Environment 13-13 join 11-31
GNU. See GNU’s Not Unix
GNU’s Not Unix 1-3
GPL. See General Public License
K
K Desktop Environment 13-11
gpm 3-27, 16-17
KDE 13-11
graphical file managers 4-25
kdeprint 15-13
Graphical User Interface 2-22
kdm 9-5, 13-15, 13-16
grep 10-15, 10-17, 11-15, 11-17
kedit 8-3, 8-5
-c option 11-20
Kerberos 2-20
-i option 11-20
kernel 7-5
-l option 11-20
keyboard layout 2-13
-n option 11-20
keytable 16-18
-v option 10-19, 11-17, 11-20
kill 9-12, 9-13, 9-14
-w option 11-20
signals 9-14
GRUB 2-16, 2-18, 2-26, 7-5
killall 9-14, 9-15
GUI. See Graphical User Interface
koffice 17-21
gunzip 11-29
Konqueror 13-12
gzip 11-29, 15-10
kotalk 16-18
-v option 11-29
kpm 9-21
kppp 16-7
H kpresenter 17-21
Hardware-HOWTO 2-3 ksysv 16-16

© Copyright IBM Corp. 2001, 2003 Index X-3


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

ktalk 16-18 sections 6-7


kudzu 16-18 Massachusetts Institute of Technology 1-3, 13-3
Master Boot Record 2-5
master boot record 2-17
L MBR. See Master Boot Record
language 2-13 MD5 encryption 2-20
LBA 7-5 Memory Management Unit 1-5
LDAP 2-20 mesg 3-22
less 4-21 Metro-X 13-7
let 12-25 Minix 1-5
Libraries 7-4 minor number 7-7
LILO 2-16, 2-18, 2-26, 7-5 MIT. See Massachusetts Institute of Technology
Linus Torvalds 1-5 mkdir 4-10
Linux File System Hierarchy Standard 7-3 -p option 4-12
Linux Professional Institute B-1 mknod 2-6, 7-8
locate 11-11 mkpasswd 3-14
lockfiles 7-17 MMU. See Memory Management Unit
Locking 3-28 modem 16-3
logfiles 7-17 more 4-21
logging on 3-3 mount 7-20, 17-5
logging out 3-29 mountpoint 7-20
logical partitions 2-5 mouse type 2-13
login 9-5 MSN 16-9
login name 9-5 mtools 17-4, 17-6
login shell 9-5 multi-tasking 3-3
logout 3-29 multi-user 3-3
lost+found directory 7-18 mv 4-18
lp 15-13 -i option 4-19
lpadmin 15-12
lpcancel 15-13
lpd 9-22, 16-18 N
LPI. See Linux Professional Institute NDA. See Non-Disclosure Agreement
lpq 15-13 netfs 16-18
lpr 15-13 netscape 9-15
lprm 15-13 netstat 16-16
LPRng 15-12 network 16-18
lpstat 15-13 adapter 2-19
ls 4-5, 4-13, 10-19 configuration 2-19
-a option 4-13 Network Address 2-19
-d option 5-5 nfs 16-18
-l option 5-5 nfslock 16-18
LX02 B-2 nice 9-19
LX03 B-2 -n option 9-19
LX07 B-2 NIS 2-20
LX22 B-2 nl 10-17
LX23 10-17, B-2 nohup 9-12, 9-16
LX24 16-20, B-2 Non-Disclosure Agreement 1-3
LX25 B-2 ntpd 16-18
LX26 B-2 ntsysv 16-16

M O
major number 7-7 od 4-22
makewhatis 6-6 OpenOffice 7-19, 17-21
man 6-3, 15-6
-k option 6-6

X-4 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

P pstree 9-8
pty 7-8
package groups 2-21
parted 2-7 pwd 4-8
partition
/boot 2-16 Q
/home 2-16 Quoting metacharacters 10-27
/opt 2-16
/tmp 2-15
/usr 2-15 R
/usr/local 2-16 radvd 16-18
/var 2-16 random 16-19
root 2-15 rawdevices 16-19
Partition Table 2-5 rawrite 2-10
partitioning 2-5 rdesktop 17-22
PartitionMagic 2-7, 2-9 read 12-24
partitions 2-3 Red Hat B-1
passwd 3-14 Red Hat Certified Engineer B-1
password 3-3, 9-5 Red Hat Certified Technician B-1
paste 11-31 Red Hat Package Manager 15-7
path name 4-6 redhat-config-network 15-16
absolute 4-6 redhat-config-soundcard 15-14
relative 4-6 redhat-config-xfree86 13-9
pdksh 12-7 redirection
perl 12-7 combined 10-13
permissions 5-3 input 10-9
changing 5-9 output 10-10
directory 5-6 pipes 10-14
file 5-6 Regular Expressions 11-18
levels 5-4 renice 9-20
octal notation 5-11 return code 10-26
required 5-8 RHCE. See Red Hat Certified Engineer
symbolic notation 5-9 RHCT. See Red Hat Certified Technician
types 5-6 rhnsd 16-19
umask 5-13 Richard Stallman 1-3
PID. See Process ID rm 4-23, 10-19
portmap 16-18 -f option 4-23
postfix 16-18 -i option 4-23
PPP 16-5 -r option 4-23
pppd 16-7 rmdir 4-11
PPS 15-12 -p option 4-12
pr 10-17 root 2-20, 3-3
primary partitions 2-5 RPM 15-7
process 9-3 rpm 15-8
background 9-9 -a option 15-9
controlling 9-9 -e option 15-8
foreground 9-9 -i option 15-8, 15-9
parent/child relationship 9-6 -l option 15-9
priorities 9-17 -p option 15-9
starting and stopping 9-4 -q option 15-9
Process ID 9-3, 9-9, 9-13 -U option 15-8
process table 9-3 rsync 16-19
ps 9-7, 9-15 runlevel 13-14
-a option 9-7
-u option 9-7
-x option 9-7

© Copyright IBM Corp. 2001, 2003 Index X-5


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

S T
Samba 17-16, B-3 tac 10-17
sax 13-9 tail 11-24
sax2 13-9 -f option 11-24
SCSI 2-6 talk 3-21
sed 10-16 tar 15-10
sendmail 16-19 tee 10-18
serial terminal 3-4 telnet 3-4
services 16-19 terminal emulator 3-9
sgi_fam 16-19 test 12-13, 12-14, 12-15
sh 10-3 then 12-13, 12-18
shadow passwords 2-20 time 16-19
shell 9-3, 10-3 tkrat 9-15
aliases 10-29 Token Ring 2-19
metacharacters 10-5 top 9-21
reserved words 10-5 touch 4-14
scripting 12-3 tr 10-17
variables 10-21 type 11-26
shell scripts
invocation 12-4
shift 12-9, 12-22 U
signals 9-14 umask 5-13
hangup 9-14 umount 7-22
interrupt 9-15 unalias 10-29
kill 9-15 unexpand 10-16
quit 9-15 unified filesystem 7-3
sleep 12-20 UnitedLinux B-1
smbclient 17-17, 17-18 UNIX 1-3, 3-3
smbmount 17-17, 17-19 unix2dos 17-22
smbprint 17-17, 17-20 updatedb 11-11
snmpd 16-19 upgrade 2-14
sort 11-22 user accounts 2-20
-d option 11-23 user authentication 3-3
-n option 11-23 User Private Groups 5-13
-r option 11-23 username 3-3
-t option 11-22
source 12-6
split 4-24
V
vi 8-3, 8-5, 17-22
spool files 7-17
cheat sheet 8-22
ssh 3-4
command mode 8-7, 8-10
sshd 16-19
cursor movement 8-9
standard error 10-8
edit mode 8-7, 8-11
standard input 10-8
ex mode 8-7, 8-15
standard output 10-8
exiting 8-21
StarOffice 17-21
modes 8-7
startx 13-14
options 8-19
stderr 10-8
searching 8-14
stdin 10-8
vim 8-6
stdout 10-8
virtual terminal 7-8
strings 4-22
virtual terminals 3-5
Subnetmask 2-19
vlock 3-28
superuser 2-20
VMWare 17-9
swap space 2-15
syslog 16-19

X-6 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

W
wall 3-20
wc 10-14
-l option 10-15
whereis 11-26
which 11-26
while 12-20, 12-22
who 3-18
who am i 3-18
whoami 3-18
wildcard expansion 10-6
win4lin 17-12, 17-14
window manager 9-5, 13-5
Windows for Workgroups 1-5
WINE 17-12, 17-15
wine 9-15, 16-19
winmodem 16-6
write 3-20

X
X 2-22, 13-3
X clients 13-5
X server 13-5
X Window System 2-22, 13-3
X11 13-3
xargs 12-11
X-Consortium 13-3
xdm 9-5, 13-15, 16-19
xDSL 16-4, 16-13
xf86config 13-9
XFree86 13-3
xfs 16-20
Xi Graphics 13-7
xinetd 16-20
xlock 3-28

Y
YaST 2-7
yast 15-16
yast2 15-14

Z
zcat 11-29

© Copyright IBM Corp. 2001, 2003 Index X-7


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

X-8 Linux Power User © Copyright IBM Corp. 2001, 2003


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
V2.0

backpg
Back page
®

You might also like