Vous êtes sur la page 1sur 578

@Xi29

ower User ~ I R IS
E
QU(%wgbtiib~ ttnso~dM
¿&& b 3 i / i i ~
iudent ~ o t e b & .( .
ERC 4.0
- - - . - - . . i r h S bris tan!
.ritd ro

Material Educativo

4e =,
;gaje
, '
'Q'
.
l
---
- -- --
I 1 I D -

1 1-I
1 1 1 111
--m w
--m 7

Linux
Power User
(Course Code QLX02)

Student Notebook
ERC 4.0

IBM Certified Course Material


Student Notebook

Trademarks
IBM8 is a registered trademark of lnternational Business Machines Corporation.
The following are trademarks of lnternational Business Machines Corporation in the United
States, or other countries, or both:

Microsoft, Windows and Windows NT are trademarks of Microsoft Corporation in the


United States, other countries, or both.
lntel and Pentium are trademarks of lntel Corporation in the United States, other countries,
or both.
UNlX 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.

September 2005 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 itern rnay 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.

O Copyright lnternational Business Machines Corporation 2001,2005. 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.
Student Notebook

Contents
Trademarks .......................................................xi
Course Description ................................................xiii
...

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

Certification lnformation ........................................... xvii

Unit 1. lntroduction to Linux ........................................1.1


Unit Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-2
A Short History of Linux (1 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-3
A Short History of Linux (2 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
What's So Special About Linux? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-8
Effects of the License Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-10
Línux Has Become a Way of Life . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12
LinuxToday . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-13
Linux Hardware Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-14
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-16
Unít Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-17

.
Unit 2 lnstalling Linux .............................................2.1
UnitObjectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .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
.
lnstalling Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-10
lnstallation Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-12
Select Language. Keyboard. Mouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-13
InstallClass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-14
Disk Partitioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-15
Configure a Boot Loader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-17
Configure Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-19
Configure Root and User Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-20
SelectPackageGroups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21
ConfigureX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-22
Other (Optional) lnstallation Screens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-24
InstallingPackages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-25
CreateBootDisk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-26
Post-install Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-27
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-28
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-29

O Copyright IBM Corp.2001. 2005 Contents iii


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

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


Unit 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
LinuxCommands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .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
ThedateCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16 .
ThecalCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17 .
Who Is on the System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3.18 .
Finding lnformation about Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.19 .
The clear, echo, write, and wall Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3.20
Talk with Another User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.21
ThemesgCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22
KeyboardTips(1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23 .
KeyboardTips(2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-24 .
Command History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.25
Retrieving commands with "!" . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.26 .
ConsoleMouseTips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-27 .
Locking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28 .
LoggingOut . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-29 .
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30 .
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.31 .

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


Unit Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4.2 .
AFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
.
FileTypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-4
LinuxFilenames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-5 .
LinuxPathnames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-6 .
Example Directory Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.7 .
WhereAmI? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .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 .
ThetouchCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-14 .
Copying Files (1 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4.16 .
Copying Files (2 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.17 .
Moving and Renaming Files (1 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.18 .
Moving and Renaming Files (2 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4.19 .
iv Linux Power User O Copyright IBM Corp. 2001. 2005
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

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
.
FileManagers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-25
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-26
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-27

Unit 5. File and Directory Permissions ................................5.1


UnitObjectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-2
UsersandGroups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-3
Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4.
Viewing Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-5
Permissions Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-6
Required Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-8
Changing Permissions (1 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-9
Changing Permissions (2 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-11
umask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-13
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-14
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15

Unit 6. Linux Documentation ........................................6.1


UnitObjectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-2
ThemanCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-3
man Example (1 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-5
man Example (2 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-6
mansections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-7
TheinfoCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-8
info Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-10
The --help Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-12
HOWTO Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-13
HOWTOExample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-14
Other Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-15
lnternet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-16
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-17
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-18

Unit 7. A Tour through Linux ........................................7.1


UnitObjectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-2
Directory Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-3
/bin . Ilib. and /sbin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-4

.
O Copyright IBM Corp 2001. 2005 Contents v
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM .
Student Notebook

/root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-12
.
/tmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-13
.
/usr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14
..
/var . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-16
/lost+found . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-17
Other Directories in / . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.18
Virtual. Unified Filesystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.19 .
Typical Filesystem Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7.21
ThemountCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-22
TheumountCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-23 .
The /etc/fstab File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7.24 .
Mounting and Unmounting Removable Media . . . . . . . . . . . . . . . . . . . . . . . . . . . .7.26
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-28
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7.29 .

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


Unit Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8.2 .
Editing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-3
Thevitexteditor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5
viModes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-7 ..
Startingvi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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-17
CutandPaste . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-18 .
CopyandPaste . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-19
vioptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-20
Exitingvi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-22 .
viCheatSheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-23
OtherEditors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-24
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-25
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-26 .

.
Unit 9 Shell Basics ............................................... 9-1
Unit Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9.2
TheShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-3
ShellFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-4
Metacharacters and Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-5
Basic Wildcard Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-6
Advanced Wildcard Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-8
File Descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-9
Input Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-10
Output Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-11

vi Linux Power User O Copyright IBM Corp.2001. 2005


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

Error Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-12


Combined Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-14
Pipes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-15
Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-16
Common Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-17
SplitOutput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-19
Command Substitution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-20
CommandGrouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-21
Shell Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-22
Referencing Shell Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-23
Exporting Shell Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-24
Standard Shell Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-25
Return Codes from Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-27
Quoting Metacharacters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-28
Quoting Non-Metacharacters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-29
Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-30
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-31
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9-32

Unit 10. Working with Processes ................................... . 10.1


Unit Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
WhatIsaProcess? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 0-3 ..
Starting and Stopping a Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-4
Login Process Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-5
Parents and Children . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-6
Monitoring Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-7
Viewing Process Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-8
Controlling Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-9
Starting Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-10
Job Control in the Bash Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-12
Job Control Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-13
Kill Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-14
Running Long Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-16
Managing Process Priorities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-17
Thenicecommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-19
The renice Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-20
lntegrated Process Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-21
Daemons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .0-22 ..
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 0-23 ..
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10-24

Unit 11. Linux Utilities ........................................... . 11.1


Unit Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-2
ThefindCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-3 .
Sample Directory Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-4
Usingfind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-5
.
Executing Commands with find . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-6
lnteractive Command Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7

.
O Copyright IBM Corp 2001. 2005 Contents vii
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM .
Student Notebook

Additional find Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11.8


findExamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-10
IocateCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-11
ThecutCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-12 .
cut Example (1 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11.13
cut Example (2 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11.14
ThegrepCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-15
grep Sample Data Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 . 1.16
Basicgrep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-17
grep with Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 1.18
Regular Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11.19
grepoptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-20
Othergreps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-21
.
ThesortCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11-22 .
sortExamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .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


Unit Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..12.2
What 1s a Shell Script? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..12.3
lnvoking Shell Scripts (1 of 3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12.4
lnvoking Shell Scripts (2 of 3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12.5
lnvoking Shell Scripts (3 of 3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12.6
lnvoking 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 (1 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12.14
The test Command (2 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12.15
The && and 11 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12.17
TheifCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-18
Command Repetition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..12.19
The while Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12.20
The for Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 . 2.21
Shifting Shell Script Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..12.22
User Interaction: The read Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12.24
Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . -12-25
.
TheexprCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-27 .
Command Search Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 . 2.28
Checkpoint (1 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12.29
Checkpoint (2 of 2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12.30

viii Linux Power User O Copyright IBM Corp. 2001. 2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12-31

Unit 13. The Linux GUI ........................................... .13.1


Unit Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13-2
The Linux Graphical User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-3
ClientIServer Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13-4
XComponents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .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

nit 14. Customizing the User Environment .......................... . 14.1


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

Unit 15. Basic System Configuration ................................ . 15.1


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

.
Unit 16 Connecting to the lnternet ................................. . 16.1
Unit Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16-2
Connecting to the lnternet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16-3
Modem Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16-5
Modem Connections in Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-6
ISDN Principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16-8
ISDN in Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-9

O Copyright IBM Corp.2001. 2005 Contents ix


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

Cable Modem Principies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 6.11


xDSL Principies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16.13
Cable Modems in Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 6.14
lnternet Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16.15
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16-24
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16.25

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


Unit Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 . 7.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
WlNE Screenshot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..17.15
Accessing Windows Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..17.16
smbclient Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17.18
smbmount Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17.19
smbprint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7.20
.
Reading Windows Document Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 7.21
Other Useful Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..17.22
Checkpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7.23 ..
Unit Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17.24

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


Appendix B. Certification lnformation .................................. B-1

lndex ........................................................... X.1

x Linux Power User O Copyright IBM Corp. 2001. 2005


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

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:
IBM8 is a registered trademark of lnternational Business Machines Corporation.
The following are trademarks of lnternational Business Machines Corporation in the United
States, or other countries, or both:

Microsoft, Windows and Windows NT are trademarks of Microsoft Corporation in the


United States, other countries, or both.
lntel and Pentium are trademarks of lntel Corporation in the United States, other countries,
or both.
UNlX 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.

O Copyright IBM Corp. 2001,2005 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 O Copyright IBM Corp. 2001,2005


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
lntegrating Linux in a Windows environment

xiv Linux Power User O Copyright IBM Corp. 2001,2005


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

Agenda
Day 1
Unit 1 - lntroduction to Linux
Unit 2 - lnstalling Linux
Exercise 2 - lnstalling 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 - Shell Basics
Exercise 9 - Shell Basics
Unit 10 - Working with Processes
Exercise 10 - Working with Processes
Unit 11 - Linux Utilities
Exercise 11 - Linux Utilities

Day 4
Unit 12 - Shell Scripting

O Copyright IBM Corp. 2001,2005 Agenda xv


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission 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 lnternet
Exercise 16 - Securing a Linux Workstation
Unit 17 - lntegrating Linux in a Windows Environment
Exercise 17 - lntegrating Linux in a Windows Environment
Exercise 18 - End-of-Course Challenge Exercise (optional)

xvi Linux Power User O Copyright IBM Corp. 2001,2005


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

Certification lnformation
Several professional certifications currently exist for Linux. This
course, combined with other Linux courses, will prepare you for al1 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 lnstitute 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."

O Copyright IBM Corp. 2001,2005 Certification lnformation 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 O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Unit 1. lntroduction 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

O Copyright IBM Corp. 2001,2005 Unit l . lntroduction to Linux 1-1


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

Unit Objectives
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

O Copyright IBM Corpomtion 2005

Figure 1-1. Unit Objectives LX024.0

Notes:

1-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

A Short History of Linux (1 of 2)


1984: Richard Stallman starts GNU
project
- GNU's Not UNlX
- http://www.gnu.org
Purpose: Free UNlX
- "Free as in Free Speech, not Free
Beer"
First step: re-implementation of UNlX
Utilities
- C compiler, C library
- emacs
- bash
To fund the GNU project, the Free
Software Foundation is founded
- http://www.fsf.org

O Copyright IBM Corporation 2005

Figure 1-2. A Short History of Linux (1 of 2) LX024.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 UNlX 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.

O Copyright IBM Corp. 2001,2005 Unit 1. lntroduction 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
UNlX operating system. Although hundreds of little tools were written, four tools stand out:
The GNU C compiler (gcc), which was essential for compiling al1 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 UNlX system, since the shell interprets and executes the
commands you type.
Later on, the GNU project also started development on a UNIX-like kernel', 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.

'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 O Copyright IBM Corp. 2001,2005


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

A Short History of Linux (2 of 2)


1991: Linus Torvalds writes first
version of Linux kernel
- lnitially a research project about the
386 protected mode
- Linus' UNlX -> Linux
- Combined with the GNU and other
tools forms a complete UNlX
system
1992: First distributions emerge
- Linux kernel
- GNU and other tools
- Installation procedure
The rest is history

O Copyright IBM Corporation 2005

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

Notes:
In 1991, a student at the University at Helsinki, Linus Torvalds, started a small research
project into the workings of the lntel 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 lntel
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) al1 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.

O Copyright IBM Corp. 2001,2005 Unit 1. lntroduction 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 lnternet (which by then was still largely a university
network) for others to use:
Frm: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds)
Newsgroups: comp.os.minix
Subject: What would you like to see most in minix?
Surranary: small poll for my new operating system
Message-ID: <199iAug25.2057O8.954l@klaava.Helsinki.FI>
Date: 25 Aug 91 20:57:08 Qvm
Organization: University of Helsinki

Hello everybdy out there using minix -


I1mdoing 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. I1dlike 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). 1've currently ported bash (l.08) and gcc (l.40),and
things seem to work. This implies that 1'11 get something practical within a
few months, and I'd like to h o w what features most people would want. Any
suggestions are welcane, but 1 wonltpromise 1'11 implernent them : - )
Linus ( torvalds@kruuna .helsinki .fi)
PS. Yes - it's free of any minix code, and it has a mlti-threaded £s.
It is NOT protable (uses 386 task switching etc), and it probably never
will support anything other than AT-harddisks,as thatls
al1 1 have :- ( .
Other people on the lnternet 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 al1 the other tools you need to make a complete operating system were al1
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 O Copyright IBM Corp. 2001,2005


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

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.

O Copyright IBM Corp. 2001,2005 Unit 1. lntroduction to Linux 1-7


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

What's So Special About Linux?


Most software (including the Linux kernel) is GPL1ed(GNU General
Public License)
- http:/lwww.gnu.org/copyleft/gpl.html
Linux is called "copyleft" (instead of "copyright")
- You can copy the software %

-7
-
- (*
- You get the source code
-You can alter the source code and recompile it
- You can distribute the altered source and binaries
- You can charge money for al1 this
You cannot change the license
- So al1 your customers have the same rights as you
- So you really cannot make money from selling the software alone
Other Open Source licenses (for example, BSD) are also used

O Copyright IBM Corporation 2005

Figure 1-4. What's So Special About Linux? LX024.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 al1 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 andlor 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 al1 software "free", so that everybody can adapt the software to its own

1-8 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

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 can 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 can distribute the sources and the binaries.
The user can charge money for al1 of this.
Basically the only restriction that the GPL imposes on al1 users is that the license statement
may not be changed. This means that al1 your customers have the same rights to the
software as you do. And as a practica1 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.

O Copyright IBM Corp. 2001,2005 Unit 1. lntroduction to Linux 1-9


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

Effects of the License Model


Everybody has access to the source
- Volunteer software development on the Internet, with central
coordination
- Linus Torvalds coordinates kernel development
- Others coordinate other pieces of the OS
Peer reviews possible
- Security
- Performance
License cannot change
- So your changes (and name) will stay in forever

O Copyright IBM Corporation 2005

Figure 1-5. Effects of the License Model LX024.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 O Copyright IBM Corp. 2001,2005


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

As an example, the sourceforge.net Web site hosts thousands of projects who al1 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.

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

O Copyright IBM Corp. 2001,2005 Unit 1. lntroduction to Linux 1-11


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Linux Has Become a Wav of Life


Culture Humor
Celebrities - User-friendly
- Linus Torvalds - Segfault
- Richard Stallman Mascot
- Eric Raymond - Tux

O Copyright IBM Corporation 2005

Figure 1-6. Linux Has Become a Way of Life LX024.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.
As part of that identity, early in 1996, people felt the need for a logo for Linux. After having
discussed various designs over the Internet, Linus stepped in and said that he would like to
see a penguin as logo for Linux. Simply "because he liked penguins". Several authors then
started drawing penguins to use as the Linux logo, and by popular acclaim the penguin
drawn by Larry Ewing was chosen as the official logo. However, the penguin should be
seen more as a mascot than as a logo, and people are free to create their own
penguin-based logos (or adapt Larry Ewings picture) for their own purposes.
The penguin was eventually named Tux, which officially stands for [Tlorvalds [U]NI[X]. A
real Tux exists as well: A number of UK Linux fans, lead by Alan Cox, and the Linux World
magazine have sponsored a live penguin at the Bristol Zoo as a birthday present for Linus.
For a complete overview of the history of Tux, including links to other sites, see
http://www.sjbaker.org/tux.

1-12 Linux Power User O Copyright IBM Corp. 2001,2005


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

Linux Today
Linux covers the whole spectrum of computing
-Embedded devices
- Laptops
- Desktop systems Supercomputers

- Development systems
- Small and large servers
- Megaclusters/supercomputers
Linux is used throughout the world Laptops, Desktops,
Departmentservers
- ... and in space
Linux is used by home users
- ... and by some of the largest companies in the world
- IBM
- Boeing
- NASA

O Copyright IBM Corporation 2005

Figure 1-7. Linux Today LX024.0

Notes:
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.
Linux is used throughout the world, and in space: Various experiments on board of NASAs
space lab and in the lnternational 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.

See http://www.top500.org.

O Copyright IBM Corp. 2001,2005 Unit 1. lntroduction 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 Hardware Support

xSeries ¡Series pSeries zSeries


(1 ntel) (PowerPC) (PowerPC) (Mainframe)

...also supported: Compaq Alpha, ARM, Hitachi SuperH, Hewlett


Packard, DEC VAX, MIPS...

O Copyright IBM Corporation 2005

Figure 1-8. Linux Hardware Support LX024.0

Notes:
Almost al1 operating systems that are currently available are written for one specific
hardware architecture. Originally, that was the case for Linux as well. Linus Torvalds only
had an Intel-based PC. This changed in 1994 when Digital Equipment Corporation (DEC,
later bought by Compaq, which subsequently merged with HP) gave a DEC Alpha to Linus
Torvalds, no questions asked. A few months later, Linux ran on the Dec Alpha.
This was an incredible feat, since it meant that Linus had separated the
architecture-dependent code in Linux (such as initialization code for the processor) from
the architecture-independent code (such as high-level memory management and
scheduling). And that, in turn, meant that ports to other architectures were possible as well.
People took on the effort of porting Linux to other architectures, and fed back the
architecture-dependent code to Linus. This means that Linux now runs natively on a very
large number of platforms:
# 1s /usr/src/linux/arch
alpha cric ia64 mips parisc ppc64 s390x sparc x86-64
arm i386 m68k mips64 ppc s390 sh sparc64

1-14 Linux Power User O Copyright IBM Corp. 2001,2005


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

The list above is just the list of architectures that are supported in the mainline kernel.
Patches exist for other architectures as well, but have not al1 been made part of the
mainline kernel.
IBM has done extensive work on porting Linux to lBMs architectures as well, and as a
result, Linux now runs natively on al1 IBMs @server platforms: xSeries (lntel-32, lntel-64
and AMD-64), ¡Series (PowerPC, formerly known as AS/400), pSeries (PowerPC, formerly
known as RSl6000) and zSeries (formerly known as Sl390).

O Copyright IBM Corp. 2001,2005 Unit 1. lntroduction to Linux 1-15


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

Checkpoint

TIF 1. Linus Torvalds wrote the Linux Operating System


al1 by himself.

2. Which of the following statements is NOT true about


software licensed under the GNU GPL?
a. You have the right to obtain and review the source code
b. You cannot charge any money for the software
c. You cannot change the license statement
d. You can modify the source code and subsequently
recompile it

3. Who is the mascot of Linux?

O Copyright IBM Corporation 2005

Figure 1-9. Checkpoint

Notes:

1-16 Linux Power User O Copyright IBM Corp. 2001,2005


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

Unit Summary
The Linux kernel, combined with the GNU and other tools, form a
complete UNIX-like operating system
A distribution adds an installation procedure and a convenient
format for distribution
Most software in a Linux distribution is licensed under Open Source
licenses such as the GNU GPL
Linux has been ported to more than ten hardware architectures and
supports virtually al1 PC hardware
Linux is used in a variety of small and large applications

O Copyright IBM Corporation 2005

Figure 1-1 0. Unit Summary LX024.0

Notes:

O Copyright IBM Corp. 2001,2005 Unit 1. lntroduction 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 O Copyright IBM Corp. 2001,2005


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

Unit 2. lnstalling Linux


What This Unit Is About
This unit shows the students 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

O Copyright IBM Corp. 2001,2005 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

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

O Copyright IBM Corporation 2005

Figure 2-1. Unit Objectives LX024.0

Notes:

2-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

Preparing a System for lnstallation


Know your hardware
- CPU, memory, keyboard, mouse
- Hard disks, CD-ROM players
- Graphical adapters, monitor capabilities
- Network adapters, IP addresses
- Printers
Is al1 your hardware supported?
- Linux Hardware-HOWTO
- Distributors Hardware Compatibility List
- Hardware manufacturer
- If unsure, just try it!
Make space for Linux partitions

O Copyright IBM Corporation 2005

Figure 2-2. Preparing a Systern for lnstallation LX024.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 al1 the characteristics and
configuration options of that hardware.
Furthermore, you need to verify that al1 your hardware is supported by Linux. Since not al1
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.

O Copyright IBM Corp. 2001,2005 Unit 2. lnstalling Linux 2-3


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Notebook

Know Your Hardware


Obtain information from
- Manuals
- Windows Control Panel

O Copynght IBM Corporation 2005

Figure 2-3.Know Your Hardware LX024.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 need to
consult your monitor manual for that.

2-4 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Studenf Notebook

Partitioning Theory
Partitioning is necessary on Intel-based computers
Maximum of four primary partitions
One primary partition may be an extended partition
An extended partition can hold an unlimited amount of logical
partitions (but the OS may pose a limit anyway)

hda: The first sector of the disk contains the MBR and
Partition Table

hdal: First primary partition holds a Windows 95 filesystem


hda2: Second primary partition is an extended partition and
holds three logical partitions
hda5: First logical partition holds a Linux filesystem that will
be mounted as 1
hda6: Second logical partition holds a Linux filesystem that
will be mounted as lhome
hda7: Third logical partition holds a Linux swap space

O Copyright IBM Corporation 2005

Figure 2-4. Partitioning Theory LX024.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 thingsl:
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 partitions3. (Linux limits the number of logical
' Actually, three: the first sector also contains a two-byte magic number to verify that this is a valid master boot record sector.
he pariition table itself is 64 bytes. To fully describe a pariition, you need 16 bytes per pariition, hence the limit of four partitions that
can be described in the pariition table.

O Copyright IBM Corp. 2001,2005 Unit 2. lnstalling Linux 2-5


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

partitions to 59 on IDE disks and 11 on SCSI disks4.) Every logical partition can hold a
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 Idevlhda, the second Idevlhdb, and so on. The first primary
partition on the first IDE drive is called Idevlhdal , the first logical partition is called
ldevlhda5. Most Linux distributions define devices up to ldevlhdal6, so if you want to
create more than 12 logical partitions, you need to create some extra Idev entries yourself
using the mknod command. The details on this are covered in subsequent courses.
SCSl disks are a little different in this respect. The first difference is that SCSl disks use
Idevlsda instead of Idevlhda. The second difference is that SCSI disks can only hold
eleven logical partitions. This has to do with the SCSl ID numbering, which reserves 16 IDs
for al1 block devices on the disk, where Idevlsda is also considered a block device.
Together with four primary partitions, this leaves a maximum number of eleven logical
partitions.

If logical partitions are used, then these logical partitions are described in the extended partition itself, using a linked list. Linked lists
have no inherent lirnitation in the nurnber of entries they can contain.
This is because Linux only reserves 64 rninor nurnbers for an IDE disk, and 16 minor nurnbers for a SCSl disk. The disk itself uses one
minor nurnber, and each primary partition requires a rninor nurnber. That leaves 59 rninor nurnbers for logical partitions on IDE disks, and
11 on SCSl disks.

2-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

Partitioning Tools
PartitionMagic
- Commercial program from PowerQuest
- Runs under MS-DOS and Windows
- Can create/resize/move/delete partitions
GNU parted
- Can create/resize/move/delete partitions
- QTParted is a graphical frontend for parted
fdisk
-Virtually every PC OS (Windows, OSl2, Linux) comes with a tool
"fdisk" to create partitions for that OS
Disk Druid, YaST and others
- Partitioning programs integrated in install program

O Copyright IBM Corporation 2005

Figure 2-5.Partitioning Tools LX024.0

Notes:
Various tools are available for partitioning your hard disk.
The most luxurious tool for partitioning is PartitionMagic, á. commercial program from
PowerQuest. It runs under MS-DOS and Windows, and allows you to create, resize, move
and delete partitions for virtually al1 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 interna1 structure of the filesystem that is stored in that partition.
parted is the GNU answer to PartitionMagic. It runs under Linux and provides nearly al1
functions that PartitionMagic offers: It can create, move, resize and delete most partition
types. The only partition type that parted currently does not like is NTFS. For this, you
might want to use a stand-alone tool ntfsresize. It is expected that the NTFS resizing
capability will be added to parted soon.
parted and ntfsresize both do not have an attractive user interface. For this, you might
want to use QTParted. That tool is not included in al1 distributions though, since it is
currently still in beta test. Its Web site is http://qtparted.sourceforge.net.

O Copyright IBM Corp. 2001,2005 Unit 2. lnstalling Linux 2-7


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

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
part of a SUSE installation. These programs typically can create partitions for Linux, but not
for other operating systems.

2-8 Linux Power User O Copyright IBM Corp. 2001,2005


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

PartitionMagic

O Copyright IBM Corporation 2005

Figure 2-6. PartitionMagic LX024.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.

O Copyright IBM Corp. 2001,2005 Unit 2. lnstalling Linux 2-9


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

lnstalling Linux
Boot system from bootable media
- All modern PCs can boot from CD-ROM directly
Must be enabled in BlOS
- Otherwise, boot from floppy
Some distributions require additional disks
-Al1 disk images are usually stored on the CD-ROM
After booting, install from:
- Local CD-ROMIDVD
- Local Hard Disk
- Network

O Copyright IBM Corporation 2005

Figure 2-7. lnstalling Linux LX024.0

Notes:
lnstalling 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
BlOS 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 contain support for less commonly used devices, for instance for
PCMCIA (PC Card) support.
Not al1 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 need to
make them yourself. The raw diskette images are therefore always stored somewhere on
the distribution CD-ROM or are downloadable from the lnternet as well. They are easily
recognizable: they 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 O Copyright IBM Corp. 2001,2005


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

C:\> d:
D :\> cd images
D:\IMAGES> dir

BOOT IMG 1,474,560 19-04-99 17:24 BOOT.IMG


FJomNET IMG 1,474,560 19-04-99 17:25 BOOTNET.IMG
PmlCIA 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 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.)

O Copyright IBM Corp. 2001,2005 Unit 2. lnstalling Linux 2-11


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

lnstallation Steps
All installation programs need to perform essentially the same
steps:
1. Choose language, keyboard type, mouse type
2. Create partitions
3. Set up a boot loader
4. Configure network
5. Configure users and authentication
6. Select package groups
7. Configure X
8. lnstall Packages
9. Create Boot Disk
Order of steps may vary from distribution to distribution
Other steps may also be included
For example, firewall, printers, sound

O Copyright IBM Corporation 2005

Figure 2-8.lnstallation Steps LX024.0

Notes:
After the system is booted, the installation program takes over, and asks you a number of
questions regarding the Linux configuration. It then installs Linux and configures it
according to the options you specified.
Obviously, every distribution has 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-1 2 Linux Power User O Copyright IBM Corp. 2001,2005


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

Select Language, Keyboard, Mouse


Select the language to be used during installation process
- Different distributions support different languages
Select the keyboard layout
- Different countries use different keyboard layouts
- Dead (compose) keys allow you to input accented or
special characters such as é, c, 13 and so forth.
Select your mouse
- A mouse can be connected using a PSl2, USB or serial
connector
- If your mouse has only two buttons, you can emulate the
third (middle) button by clicking both buttons
simultaneously

O Copyright IBM Corporation 2005

Figure 2-9. Select Language, Keyboard, Mouse LX024.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.

O Copyright IBM Corp. 2001,2005 Unit 2. lnstalling Linux 2-13


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

lnstall Class
Most distributions have default installation "classes" for typical users

- Workstation

- Laptop

- Server

A "custom" class allows you to make al1 decisions yourself


- Packages to be installed
- Various configuration options
O Copyright IBM Corporation 2005

Figure 2-10. lnstall Class LX024.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
are installed and various configuration options. If a distribution uses these classes, then it
always supports a "custom" class too, which allows you to make al1 decisions yourself.
Note that some distributions also make assumptions regarding partitioning, depending on
the class chosen. As an example, a Red Hat "Workstation" install removes al1 existing
Linux partitions, and a Red Hat "Server" install removes 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 al1 installed software to the latest level.

2-14 Linux Power User O Copyright IBM Corp. 2001,2005


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

Disk Partitioning
Linux installation requires you to create Linux partitions
At a minimum, create:

' J C~~~Z~M
750 MB min.

Recommended:

1 Iboot 1
May needlwant to create other partitions:

S J r o a C lvar JC l t m p J J borneJ

O Copyright IBM Corporation 2005

Figure 2-11. Disk Partitioning LX024.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 holds the filesystem which
in turn holds al1 your data. The absolute minimum depends on your distribution (a really
minimalist Linux install is usually 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 (Iusr, Itmp and so forth). In that case,
your root partition doesn't have to be this large.
The second partition does not hold a filesystem but is used as swap space. This is
virtual memory which is used when your system exhausts its real memory. The opinions

O Copyright IBM Corp. 2001,2005 Unit 2. lnstalling Linux 2-15


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof 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 M B ~ .
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 holds a filesystem that is mounted
at the /boot mountpoint") of about 16 to 32 ~ e ~ a b ~ tThis e s partition
~. holds everything that
is needed by the Linux boot process. The most important program here is the Linux kernel
itself, but you also need to have some components of LlLO or GRUB 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 al1 newly created Linux partitions.

When your system starts using the swap space, it generally means that you do not have enough real memory to run al1 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.
Red Hat requires your iboot partition to be at least 100 Megabytes, so that you can insta11 severa1 kernel images.

2-16 Linux Power User O Copyright IBM Corp. 2001,2005


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

Configure a Boot Loader


A Boot Loader loads and starts the Linux kernel

Can boot other operating systems as well


-0S12, Windows, BeOS, ...
- Give each OS a unique label
Can be password protected
- Prevents users from passing boot parameters to Linux or booting
any OS
Should generally be configured in the MBR, unless another boot
loader is used
Common Boot Loaders:
- LILO: Linux Loader
- GRUB: GRand Unified Boot Loader

O Copyright IBM Corporation 2005

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

Notes:
One of the next screens allows 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.
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 is 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: LILO and GRUB.

--

O Copyright IBM Corp. 2001,2005 Unit 2. lnstalling Linux 2-17


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission 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 O Copyright IBM Corp. 2001,2005


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

Configure Network
Most distributions configure your network adapter as part of the
installation process
- Ethernet
- Token Ring
Need the following information:
- IP address
- Subnetmask
- Network address
- Broadcast address
- Hostname
- Default routerlgateway
- DNS server addresses
May also be configured to use DHCP

O Copyright IBM Corporat'on 2005

Figure 2-13. Configure Network LX024.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 routerlgateway
DNS server addresses
If your workstation resides on a network where a DHCP server is present, you can also
configure your system to use this DHCP server to obtain this information.

O Copyright IBM Corp. 2001,2005 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

Configure Root and User Accounts


rsot is the superuser of the system
- Can do anything
- Needs a strong password
- Do nol use your system as raot unless you need to!
Most distributions allow you to add user accounts during installation
too:
- Create a user account for every individual user that is going to
use the system
Hint: You should enable shadow passwords and MD5
encryption if available for additional security

O Copyright IBM Corporation 2005

Figure 2-14. Configure Root and User Accounts LX024.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 O Copyright IBM Corp. 2001,2005


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

Most distributions have grouped individual packages in package


groups
Only select the package groups you need on your workstation
Selecting individual software packages is usually still possible but
tedious
- A typical distribution has over 1000 packages

O Copyright IBM Corporation 2005

Figure 2-15. Select Package Groups LX024.0

Notes:
A typical distribution consists of over 1000 individual packages (software components) that
should or can be installed. To cave the user from having to make 1000 or more informed
decisions, these packages are often grouped into package groups. lnstead 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).

O Copyright IBM Corp. 2001,2005 Unit 2. lnstalling Linux 2-21


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

Configure X
X (X Window System) is the graphical user interface of Linux
Needs to be configured for your system
- Graphical adapter
- Monitor
Most adapters and monitors can be autodetected
- If not autodetected, select manually or use a generic adapter or
monitor
Usually customization allowed:
- Resolution, Refresh rate
- Color Depth
Test settings if possible
If nothing works, skip X configuration

O Copyright IBM Corporation 2005

Figure 2-16. Configure X LX024.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 is
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 O Copyright IBM Corp. 2001,2005


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

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

O Copyright IBM Corp. 2001,2005 Unit 2. lnstalling Linux 2-23


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

Other (Optional) lnstallation Screens


Some distributions offer additional installation screens:

- Printer configuration
- Firewall configuration
- Sound card configuration
- Modem configuration
- Time Zone configuration

Usually straightforward

O Copyright IBM Corporation 2005

Figure 2-17. Other (Optional) lnstallation Screens LX024.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 O Copyright IBM Corp. 2001,2005


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

lnstalling Packages
lnstalling packages may take 5 mins to several hours
- Most distributions provide a progress bar andlor total time
indication
- Some distributions provide some entertainment while installing
While installation is going on, various virtual terminals provide
information on the progress
- Switch between VTs using Ctrl-Alt-Fl , Ctrl-Alt-F2, and so forth
Feed additional CDs when asked for

O Copyright IBM Corporatimn 2005

Figure 2-18. lnstalling Packages LX024.0

Notes:
After al1 configuration choices have been made, the system starts 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 ¡t.

O Copyright IBM Corp. 2001,2005 Unit 2. lnstalling Linux 2-25


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

Create Boot Disk


After installation, most distributions allow you to create a custom
boot disk
Used to boot the system in case of LILOIGRUBlkernel problems
System specific to some degree

O Copyright IBM Corporation 2005

Figure 2-19. Create Boot Disk LX024.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 LlLO 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 O Copyright IBM Corp. 2001,2005


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

Post-install Configuration
After installation has finished, your system will reboot to activate the
newly installed kernel
- SUSE performs the reboot during installation
For almost al1 Linux distributions, this is the only reboot that is ever
required
After reboot, some post-installation configuration may happen
- Configure graphics
- Configure sound card
- lnstall documentation, updates, drivers
- Create user accounts
- Registration

O Copyright IBM Corporation 2005

Figure 2-20. Post-install Configuration LX024.0

Notes:
For most distributions, after the packages have been installed and configuration has been
done, the install is over. The only thing left to do is to reboot the system to activate the
newly installed kernel. SUSE is an exception to this: SUSE already activates the kernel (via
a reboot) during the installation.
The reason for this is simple: The installation program typically runs on top of a generic,
i386 compatible kernel. This installation program then determines your CPU type and
installs a kernel which is optimized for your CPU.
After the reboot, some post-installation configuration may happen, depending on the
distribution. Red Hat, for instance, attempts to register your system with RHN, the Red Hat
Network.

O Copyright IBM Corp. 2001,2005 Unit 2. lnstalling Linux 2-27


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

Checkpoint

TIF 1. Linux can coexist with Windows on the same


hard disk.

2. Which of the following steps is NOT essential in the


installation process:
a. Create partitions for Linux
b. Configure your printer
c. Select your keyboard type
d. Identify the packages to install

3. What is the best source of information about your


hardware?

O Copyright IBM Corporation 2005

Figure 2-21. Checkpoint LX024.0

Notes:

2-28 Linux Power User O Copyright IBM Corp. 2001,2005


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

Unit Summary
Preparing a system for installation
Booting the installation program
lnstalling Linux and basic configuration

O Copyright IBM Corporation 2005

Figure 2-22. Unit Summary LX024.0

Notes:

O Copyright IBM Corp. 2001,2005 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 O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in par1
without the prior written perrnission of IBM.
Student Notebook

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

O Copyright IBM Corp. 2001,2005 Unit 3. Using the Systern 3-1


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

Unit Objectives
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

Q Copyright IBM Corporation 2005

Figure 3-1. Unit Objectives LX024.0

Notes:

3-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

Linux is Multi-user and Multitasking


Linux is a multi-user, multitasking operating system
- Multiple users can run multiple tasks simultaneously, independent
of each other
Always need to "log in" before using the system
- ldentify yourself with username, password
Multiple ways to log in to the system
- Console: Directly attached keyboard, mouse, monitor
- Serial terminal
- Network connection

O Copyright IBM Corporation 2005

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

Linux, just like any UNlX 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 assigns 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 r o o t , 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 al1 at once:

O Copyright IBM Corp. 2001,2005 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 O Copyright IBM Corp. 2001,2005


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

Virtual Terminals
In most Linux distributions, the console emulates a number of
virtual terminals
Each virtual terminal can be seen as a separate, directly attached
console
-Different users can use different virtual terminals
Typical setup:
-VT 1 through 6: text mode logins
- VT 7: graphical mode login prompt (if enabled)
Switch between VTs with Alt-Fn (or Ctrl-Alt-Fn if in X)

O Copyright IBM Corporation 2005

Figure 3-3. Virtual Terrninals LX024.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 7'.

' How this is enabled is covered later.


O Copyright IBM Corp. 2001,2005 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.
Sfudent Notebook

Logging In (Text Mode VT)

O Copyright IBM Corporalion 2005

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

Notes:
The visual shows a text mode login session.

3-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

Logging In (Graphical Mode VT)

Note: Different distributions and desktop environments


will display different login prompts
O Copyright IBM Corporation 2005

Figure 3-5. Logging In (Graphical Mode VT) LX024.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.

O Copyright IBM Corp. 2001,2005 Unit 3. Using t h e System 3-7


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

Linux Commands
Everything on a Linux system can be done by typing commands
- (Even browsing the World Wide Web...)
The Graphical User Interface (X
needed for running a Linux
- But is sometimes more convenient
In order to be able to type commands in X, you need to start a
terminal emulator

O Copyright IBM Corporation 2005

Figure 3-6.Linux Comrnands LX024.0

Notes:
Every process that is running on a Linux system is started by a command, although for
most processes, you 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 lnterface (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 O Copyright IBM Corp. 2001,2005


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

Startinn a Terminal Emulator


To run a Linux command inside the X environment, open a "terminal
window" or "terminal emulator"
- Emulates a text console

Red Hat, Fedora:

GNOME:

SUSE:

O Copyright IBM Coiporation 2005

Figure 3-7. Starting a Terminal Emulator LX024.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.

O Copyright IBM Corp. 2001,2005 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

Command Prompt
The command prompt indicates that the system is ready to accept
commands
Can be configured yourself (will be covered later)
- Default depends on distribution
Examples:
[userahost d i r l $
dir$
$
#
The dollar ($) usually means: "logged in as regular user"
The hash (#) usually means: "logged in as root"

O Copyright IBM Corporation 2005

Figure 3-8.Command Prompt LX024.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 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.

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

3-10 Linux Power User O Copyright IBM Corp. 2001,2005


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

Linux Command Syntax


Linux commands have the following format:
$ command option ( S ) argument ( S )

O Copyright IBM Corporation 2005

Figure 3-9.Linux Command Syntax LX024.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
depends on the command.

O Copyright IBM Corp. 2001,2005 Unit 3. Using the Systern 3-11


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

Command Format Examples

RlGHT WRONG

1. Separation
$ mail - f personal
<~~'*TcQz~¿
~ip+i-< C*.3cricr+3
$ mail - f personal
$ who -u $ who-u

2. Order
$ mail - S test root $ mail test root -S
$ who -u $ - u who

3. Multiple options
$ who -m -u $ who -m-u
$ who -mu $ who -m u

O Copyright IBM Corporation 2005

Figure 3-10. Cornrnand Format Examples

Notes:

3-12 Linux Power User O Copyright IBM Corp. 2001,2005


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

Some Basic Linux Commands


passwd: Change your password
mkpasswd: Generate a random password
date, cal: Find out today's date and displays a calendar
who, finger: Find out who else is active on the system
clear: Clear the screen
echo: Write a message to your own screen
write: Write a message to other screens
wall: Write a message to al1 screens
talk: Talk to other users on the system
mesg: Switch onloff reception of write, wall and talk messages

O Copyright IBM Corporation 2005

Figure 3-11. Some Basic Linux Comrnands LX024.0

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

O Copyright IBM Corp. 2001,2005 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

Changing Your Password


The passwd command allows you to change your password

$ passwd
Changing password for tuxl
Old password:
New password:
Retype new password:

Passwords are important for security - choose a good password


- Minimum six characters
- Not a dictionary word, birthdate, license plate, ...
The mkpasswd command generates a random password

O Copyright IBM Corporation 2005

Figure 3-12. Changing Your Password LX024.0

Notes:
The user password is the primary mechanism for ensuring security on a Linux system. Al1
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 starts the passwd process that prompts 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 O Copyright IBM Corp. 2001,2005


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

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 learn
how to install additional packages later in this course.

O Copyright IBM Corp. 2001,2005 Unit 3. Using the Systern 3-15


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

The date Command


date shows the current date and time

$ date
Fri Jun 6 11:15:10 CET 2003

Q Copyright IBM Corporatlon 2005

Figure 3-13. The date Command LX024.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 al1 over the world might be using the same system at the same
time, but al1 want their times to be displayed as local time.

3-16 Linux Power User O Copyright IBM Corp. 2001,2005


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

The cal Command


cal shows a calendar
Synopsis : cal [Month] [Year]

$ cal 6 2003
June 2003
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
$

O Copyright IBM Corporation 2005

Figure 3-14. The cal Command LX024.0

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

O Copyright IBM Corp. 2001,2005 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

Who Is on the System


who shows who is logged onto the system

d.uor COLrec. 6 Id
$ who
root ttyl Mar 5 11:10
tuxl tty2 Mar 5 11:04

$ who am i
host!tuxl tty2 Mar 5 11:04

But:
$ whoami
tuxl

O Copyright IBM Corporation 2005

Figure 3-15. Who Is on the System LX024.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 O Copyright IBM Corp. 2001,2005


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

Finding lnformation about Users


The finger command shows info about other users
Synopsis : f inger [user] [Qhost]

$ finger
Login Name Tty Idle Login Time
tuxl Tux (1) 2 Mar 5 11:04
root root *1 7 Mar 5 11:lO

$ finger tuxl
Login: tuxl Name: Tux (1)
Directory: /home/tuxl Shell: /bin/bash
On since Fri Mar 5 11:04 (CET) on tty2
No mail.
No plan.

O Copyright IBM Corporation 2005

Figure 3-16. Finding lnformation about Users LX024.0

The finger command shows you additional information about a user, for instance yourself.
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 (ttyl) device.
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: through the finger service, an
intruder can easily obtain a list of al1 usernames on the system, and determine which
accounts have been inactive for a while. This makes breaking in easier, and breaking into
an inactive account is less likely to be noticed. How to install and enable the finger service
is covered later in this course.

O Copyright IBM Corp. 2001,2005 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

The clear, echo, write, and wall Commands


The ~Iearcommand clears your screen
$ clear
The echo command writes messages to your own screen
$ echo Who wants to go to lunch?
Who wants to go to lunch?
Use vvritt; to display a text message on a user's terminal
$ write tux2
Message
<ctrl -d>
Use wall to place a message on al1 logged in user's displays
$ wall
I'm back
<ctrl -d>

O Copyright LBM Corporation 2005

Figure 3-17. The clear, echo, write, and wall Commands LX024.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 al1 screens.

3-20 Linux Power User O Copyright IBM Corp. 2001,2005


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

Talk with Another User

If John wants to talk with Fred, John enters:


$ t a l k fred

If Fred also wants to talk with John, Fred enters:


$ t a l k john

JOHN FRED
O Copyright IBM Corporation 2005

Figure 3-18. Talk with Another User LX024.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.

O Copyright IBM Corp. 2001,2005 Unit 3. Using the System 3-21


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

The mesg Command


The rnesg command controls whether other users can send
messages to you with the write, wall or talk command or through
output redirection.

User tuxl al: ttyl :

$ mesg n

User t w 2 al tty2:

$ write tuxl ttyl


write: tuxl has disabled messages on ttyl

O Copyright IBM Corporation 2005

Figure 3-19. The mesg Comrnand LX024.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 O Copyright IBM Corp. 2001,2005


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

m!!!!!!!!!!!!.
Student Notebook

Keyboard Tips (1 of 2)
Corrects mistakes
Terminates the current
command and returns to the
shell
End of transmission
Temporarily stops output to the
screen
Resumes output
Erase last word
Erase the entire line
Command or filename
completion

O Copyright IBM Corporation 2005

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

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

O Copyright IBM Corp. 2001,2005 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

Keyboard Tips (2 of 2)
carrow up> Previous command
carrow down> Next command
carrow left> One character to the left
O carrow right> One character to the right
Look at the output of previous
commands
Look at the output of later
commands; eventually gets you
back to the command prompt
Search for a command in the
command history

O Copyright IBM Corporation 2005

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

Notes:
The Carrow up> and Carrow down> can be used to retrieve commands from history.
The carrow left> and carrow right> are used to move the cursor along the command line
to correct mistakes or make changes.
With the cshift page-up> sequence you can look at the output of previous executed
commands. The cshift page-down> brings 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 O Copyright IBM Corp. 2001,2005


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

Command History
Command history also can be viewed with history command

$ history 5
99 clear
999 wc .bash_profile
1000 wc .bash=profile
1001 wc .bash_profile
1000 history

O Copyright IBM Corporation 2005

Figure 3-22. Command History LX024.0

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

O Copyright IBM Corp. 2001,2005 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

Retrieving Commands with "!"


To retrieve commands, use !

$ wc .bash_profile
16 23 238
Redo previous:

$ 1-1
wc .bashjrof ile
16 23 238
01":
$ !!

Redo csmmand No. 999:


$ !999

O Copyright IBM Corporation 2005

Figure 3-23. Retrieving commands with "Y LX024.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. For more information see the manual page of bash.

3-26 Linux Power User O Copyright IBM Corp. 2001,2005


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

Console Mouse Tips


On most distributions, the mouse also works in text mode
Lefi mouse button
- Click: Mark start of selection
- Drag: Mark selection
Middle mouse button
- Click: Paste selection
Right mouse button
- Click: Mark end of selection

O Copyright IBM Corporalion 2005

Figure 3-24. Console Mouse Tips LX024.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 can see the mouse cursor as a
square block moving across the screen. When you click the left mouse button, you mark
the start of the selection, and when you click the right mouse button, you 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 shows up in
reverse video.
To paste your selection, click the middle mouse button3
Copy and paste using gpm works across different virtual terminals.

Remember, if your mouse only has two butions, you need to enable "emulate third button" while installing your system. This allows you
to emulate your middle mouse bution by clicking on the left and right bution simultaneously.

O Copyright IBM Corp. 2001,2005 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

Lockinq
When temporary leaving a system alone, always lock your terminal
- Other people might misuse your account
In a text mode terminal, use vlock (lock your terminal) or vlock -a
(lock the whole console)
In a graphical mode terminal, use the menu, the "padlock" icon or
xlock
- Most screensavers support automatic locking too
A locked terminal can only be unlocked with the users password

O Copyright IBM Corporation 2005

Figure 3-25. Locking LX024.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 al1 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. Most distributions,
unfortunately, do not install vlock by default.
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.

Occasionally you 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 O Copyright IBM Corp. 2001,2005


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

Logging Out
When finished working on a system, always log out
- Other people might misuse your account
In a text mode terminal, use logout, exit or Ctrl-D
In a graphical mode terminal, use appropriate menus

GNOME: KDE:

Q Copyright IBM Corporation 2005

Figure 3-26. Logging Out LX024.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 ~ t r l - ~ ~ .
To log out of a graphic mode session, use the appropriate menus or buttons.

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.

O Copyright IBM Corp. 2001,2005 Unit 3. Using the System 3-29


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Checkpoint

TIF 1. A Linux system always needs a Graphical


User Interface

2. Which of the following commands is not a legal


command in Linux?
a. Isldevlbin Pc
b. Is -alldev/bin )o
c. 1s -a -1 .
d. Is -a-lldev .q

3. How do you switch between virtual terminals?

O Copyright IBM Corporation 2005

Figure 3-27. Checkpoint LX024.0

Notes:

3-30 Linux Power User O Copyright IBM Corp. 2001,2005


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

Unit Summary
A Linux system is controlled by entering commands
A GUI is not necessary for controlling a Linux system
Linux commands can use multiple options and arguments and must
follow proper syntax rules.
There are many simple, yet powerful commands such as:
date
cal
who, who am i, whoami
f inger
echo
clear
Communicate with other Linux users using commands such as mail,
write, wall and talk.

O Copyright IBM Corporation 2005

Figure 3-28.Unit Summary LX024.0

Notes:

O Copyright IBM Corp. 2001,2005 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 O Copyright IBM Corp. 2001,2005


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

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

O Copyright IBM Corp. 2001,2005 Unit 4. Working with Files and Directories 4-1
Course rnaterials may not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Unit Objectives
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

O Copyright IBM Corporation 2005

Figure 4-1. Unit Objectives

Notes:

4-2 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

A File
A file is:

\n = newline character
- = space character

O Copyright IBM Corporation 2005

Figure 4-2. A File LX024.0

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

O Copyright IBM Corp. 2001,2005 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

File Types

1E ordinary directory

ascii text hardware devices


100 walrus
for example:
executable 164 .profile
IdevIlpO (printer device)
238 myfile
475 .bashrc
I)i jpeg picture

html file logical devices


for example:
Idevlnull (null device)

Q Copyright IBM Corporation 2005

Figure 4-3. File Types LX024.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 al1 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 O Copyright IBM Corp. 2001,2005


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

Linux Filenames
Should be descriptive of the content
Should use only alphanumeric characters
UPPERCASE, lowercase, number, @, -
Should not include embedded blanks r 2 ~ ~ i or a
i Aonco
Should not contain shell metacharacters:
*?></;S,! []I\'"(){)
Should not begin with + or - sign
Are case-sensitive -e =. hvy 5ph5 S \OG Ti
,-,,,yv~cUic s , n T i o \ , z c u \ o i , Jc.

Filenames starting with a are hidden .


The maximum number of characters for a filename is 255

O Copyright IBM Corporation 2005

Figure 4-4. Linux Filenames LX024.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, .bashjrofile), the file is considered to be a hidden file and does not
show up when you enter the Is command, for example.

O Copyright IBM Corp. 2001,2005 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

'\
v C G C -0 '(\ Jc. \ &A I W I

Linux Pathnames

Full pathnames:
Start from 1 (the root directory)

Relative pathnames:
Start from the present working directory

Examples: (working directory is Ihomeltuxl)


IhomeltuxlIdoclmon~report (full)
doclmon-report (relative)
..ltux3lpgmslsuba (relative)
./test (a file in the current dir)
-/test (same as above)

O Copyright IBM Corporation 2005

Figure 4-5.Linux Pathnames LX024.0

Notes:
The path name is written as a string of names separated by slashes (not back slashes like
in DOS, OS12 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 (1). An
absolute path name or full path name always starts with a slash.

4-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

Example Directory Structure

I I

tuxl tux3
I I
I I I I
- .bash-profile
test doc c rP c Pgms
-- manuals
- test1 suba
- mon-report -a

O Copyright IBM Corporation 2005

Figure 4-6. Example Directory Structure LX024.0

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

O Copyright IBM Corp. 2001,2005 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

Where Am I?
The pwd command (print working directory) can be used to find out
what your current working directory is:

O Copyright IBM Corporation 2005

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

Notes:
The pwd command always returns 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 O Copyright IBM Corp. 2001,2005


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

Change Current Directory


With the cd (change directory) command:
$ cd dir-name

$ cd doc (relative)
$ cd /home/tuxl/doc (full)
$ cd -tuxl/doc ( home )

$ cd (Go to your home directory)


$ cd .. (Go one directory up)
$ cd - (Go to previous directory)
r d e rez-gi~so0 1 d \ c c c . C w : ~ ~
~ f i A e r" i d

O Copyright IBM Corporation 2005

Figure 4-8. Change Current Directory LX024.0

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

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

Create Directories
With the mkdir (make directory) command:
$ mkdir dir-name

$ mkdir /home/tuxl/doc (£1111pathname)

$ cd /home/tuxl
$ mkdir doc (relative pathname)

O Copyright IBM Corporation 2005

Figure 4-9. Create Directories LX024.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 O Copyright IBM Corp. 2001,2005


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

Removing Directories
With the rmdír (remove directory) command:
$ rmdir dir-name

$ pwd
/horne/tuxl
$ rmdir doc test
rmdir: doc: Directory not empty
$

directory rnust be empty!

O Copyright IBM Corporation 2005

Figure 4-10. Removing Directories LX024.0

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 Is, which is discussed on the next page, to make cure that you have
accomplished what you set out to do.
It is also practica1 to check if you are in the correct directory with pwd, before you try to
remove something.

O Copyright IBM Corp. 2001,2005 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

Working with Multiple Directories


Create and remove multiple directories simultaneously with the -p
flag

$ mkdir - p dirl/dir2/dir3
$ m d i r - p dirl/dir2/dir3

O Copyright IBM Corporation 2005


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

Notes:
The mkdir dirlldir2ldir3 command generates an error message if neither dirl nor dir2
exists. To overcome this problem, you could use the -p option with mkdir. If dirl and dir2
already exist, only dir3 is created.
The -p option with rmdir first removes dir3, then dir2 and finally the dirl 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 O Copyright IBM Corp. 2001,2005


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

List the Contents of Directories


With the Is command:
-1s [ dir/f ile 1

$ 1s /home
tuxl tux2 tux3

Important options:
- 1 long listing (more information)
- a lists al1 files (including hidden)
-t lists files sorted by change date
- R lists contents recursively

O Copyright IBM Corporation 2005

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

Notes:
The Is 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 is used.
By default, the Is command displays the information in alphabetic order. When the Is
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.

O Copyright IBM Corp. 2001,2005 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

The touch Command


The touch command creates an empty file, or updates the
modification time of an existing file.

$ 1s - 1
- m - m - r - -1 tuxl penguins 512 Feb 24 11:lO docs

$ touch docs
$ 1s - 1
- m - m - r - -1 tuxl penguins 512 Mar 5 15:37 docs

$ touch new
$ 1s - 1
- m - m - r - -1 tuxl penguins 512 Mar 5 15:37 docs
- m - m - r - 1 tuxl penguins O Mar 5 15:37 new

O Copyright IBM Corporation 2005

Figure 4-1 3. The touch Command LX024.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 Is -1) 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 O Copyright IBM Corp. 2001,2005


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

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.

O Copyright IBM Corp. 2001,2005 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

The cp command copies files:


cp source [S] [target]

Copying one file to another:


$ cp .bashrc bashrc.old

Copying multiple files into a target


directory:
$ cp doc/mon-report doc/walrus /tmp

O Copyright IBM Corporation 2005

Figure 4-14. Copying Files (1 of 2) LX024.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 O Copyright IBM Corp. 2001,2005


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

Copying Files (2 of 2)
cp can recursively copy directories with the -R flag

$ cp - R /home/tuxl/doc /tmp

To prevent cp from overwriting existing


files, use:
$ cp - R - i /home/tuxl/doc /tmp
cp: overwrite -/tmp/doc/walrus'?

O Copyright IBM Corporation 2005

Figure 4-15. Copying Files (2 of 2) LX024.0

Notes:
When using the cp command, if the file specified as the target file already exists, then the
copy operation writes 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 has the same name as the original file.
cp -R can be used to recursively copy al1 files, subdirectories, and the files in those
directories to a new directory.

O Copyright IBM Corp. 2001,2005 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

Moving and Renaming Files (1 of 2)


With the rnv command:
mv source[s] [target]

To move a file do another directory:


$ mv doc/walrus ../../tmp

To rename a file:
$ mv doc documents

Use the - i option to prevent mv from


overwriting existing files!

Figure 4-1 6. Moving and Renaming Files (1 of 2) LX024.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 O Copyright IBM Corp. 2001,2005


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

Moving and Renaming Files (2 of 2)


Moving and renaming files can be combined by mv:

To move a directory:
$ mv ./test /tmp

mv is recursive by default

O Copyright IBM Corporation 2005

Figure 4-1 7. Moving and Renaming Files (2 of 2) LX024.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
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 still have the same number of files as you did before.
Furthermore, al1 the attributes remain the same. The only things that change are the file
name andlor location.
If the source is a directory instead of a file, then mv attempts to move this whole directory
to the new location, with al1 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.

O Copyright IBM Corp. 2001,2005 Unit 4. Working with Files and Directories 4-19
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Listing File Contents


With the cat (concatenate) command:

$ cat filel file2 ...


$ cat walrus
I1The time has comew, the walrus said,
"To talk o£ many things:
Of shoes - and ships - and sealing wax -
Of cabbage - and kings -
And why the sea is boiling hot -
And whether pigs have wings."
$

O Copyright IBM Corporation 2005

Figure 4-18. Listing File Contents LX024.0

Notes:
If the output of the cat command is longer than a screen, the file scrolls 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 filel file2 > new-file

4-20 Linux Power User O Copyright IBM Corp. 2001,2005


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

Displaying Files Page by Page


With the more or less commands:

$ less walrus
"The time has come1I, the walrus said,
"To talk of many things:
O£ shoes - and ships - and sealing wax -
Of cabbage - and kings -
And why the sea is boiling hot -
And whether pigs have wings.Im

O Copyright IBM Corporation 2005

Figure 4-19. Displaying Files Page by Page LX024.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 1 (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 clears 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.)

O Copyright IBM Corp. 2001,2005 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

Displaying Binary Files


With the od command:

With the stríngs command:

$ strings /usr/bin/passwd
/lib/ld.so.l

t gmon-start-
deregisterframe-info

/
$ e/~ = j r i % ~ p u c t u n /
C J ~ ~ L < - ~ -do/d
~ / P A
/?o f l p / y Q J O copyright IBM Corporation 2005

Figure 4-20. Displaying Binary Files LX024.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 al1 the strings
that occur in a binary file. (A string is a combination of at least four consecutive, contiguous,
printable ASCll 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 al1 distributions by default, however.

4-22 Linux Power User O Copyright IBM Corp. 2001,2005


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

Removing Files
With the rm command:

$ rm test/rob
$ 1s test/rob
1s: rob: No such file or directory

if unsure, use - i option


$ rm - i test/rob
m: remove test/robS?

To remove files and directories


recursively:
$ rm -ir test/

I
O Copyright IBM Corporation 2005

Figure 4-21. Rernoving Files LX024.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 user'. 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.

' Sorne distributionstherefore alias rm to rm -i. You learn how to use aliases later in this course.
O Copyright IBM Corp. 2001,2005 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

Splitting Files
You can split a file into a smaller files with the split command
split - b <Bytes> file [prefix]

$ 1s -1
r r 1 root roo t 4194304 Feb 21 13:31 l a r g e

$ s p l i t - b 1024k l a r g e l a r g e .
$ 1s -1
m - r - 1 root root 4194304 Feb 21 13:31 large
r r 1 root root 1048576 Feb 21 13:33 1arge.aa
- m - r -- r -- 1 root root 1048576 Feb 21 13:33 1arge.ab
- m - r -- r -- 1 root root 1048576 Feb 21 13:33 1arge.ac
r r 1 root root 1048576 Feb 21 13:33 1arge.ad

(1ibd~ oqktto

O Copyright IBM Corporation 2005

Figure 4-22. Splitiing Files LX024.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 O Copyright IBM Corp. 2001,2005


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

File Managers
Linux also offers different graphical file managers
- Nautilus (GNOME)
- Konqueror (KDE)

O Copyright IBM Corporation 2005

Figure 4-23. File Managers LX024.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 to perform file
operations.
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 automatically
uncompresses the file and opens the archive. You can then copy the files out of the
archive.

O Copyright IBM Corp. 2001,2005 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

Checkpoint

TIF 1. Linux imposes an interna1 structure on a regular


file (not a directory or special file). r /

2. Which of the following is not a legal filename?


a. -tuxl/mydocs.tar.gz
+b. Ihomeltuxl lmydoc(1)

- c.
d.
lvarltmpl.secret.doc
Ihomel..lhome/tuxllone+one

3. What command would you use to copy the file


Ihomeltuxllmydoc to ltmp, and rename it at the same
time to tempdoc?
Mu
O Copyright IBM Corporation 2005

Figure 4-24. Checkpoint LX024.0

Notes:

4-26 Linux Power User O Copyright IBM Corp. 2001,2005


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

Unit Summary
There are three types of files:
- Ordinary
- Directory
- Special
The Linux file system structure is a hierarchical tree.
Files are accessed using either full or relative path names. A full
pathname always begins with a l.
The following commands can be used with directories: pwd, cd,
mkdir, rmdir, touch and Is
The following commands can be used with files: cat, more, less,
cp, mv, rm, touch, od, split and strings

O Copyright IBM Corporation 2005

Figure 4-25. Unit Surnrnary LX024.0

Notes:

O Copyright IBM Corp. 2001,2005 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 O Copyright IBM Corp. 2001,2005


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

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

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

Unit Objectives
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

O Copyright IBM Corporation 2005

Figure 5-1. Unit Objectives

Notes:

5-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

Users and Groups

Group: penguins Group: people

Each file has an owner


1 1groupslpenguinslherring.txt 1 Each file is assigned to a group
O Copyright IBM Corporation 2005

Figure 5-2. Users and Groups LX024.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 al1 other users
on the system, or make sure that certain system files can only be read by users, and not
written to.

O Copyright IBM Corp. 2001,2005 Unit 5. File and Directory Permissions 5-3
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Permissions

File permissions are assigned to:

Km\tk\ .
1. the owner'Gf a ffe
2. the members of the group the file is assigned to
3. al1 other users

Permissions can only be changed by the owner and


root!

O Copyright IBM Corporation 2005

Figure 5-3. Permissions LX024.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 file'.
2. The permissions that apply to al1 members of the group that is associated with the file.
3. The permissions that apply to al1 other users on the system.
Permissions can only be changed by the owner, and root of course.

' The root user can change the owner of a file aiterwards. This is outside the scope of this course, but is be covered in the LX03.
5-4 Linux Power User O Copyright IBM Corp. 2001,2005
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Viewing Permissions

To show the permissions of a file, use the Is


command with the -1 option
$ 1s - 1
- m - r - - r - -1 tuxl penguins 101 Jun 5 10:03 filel
- r r 1 tux2 penguins 171 Jun 4 10:23 file2
drwxr-xr-x 2 tuxl penguins 512 Jun 7 11:13 mydir
m

1 1 1 1
File type owner size name
v 1 1
permissions grouP mtime
t (modification time)
link counter

O Copyright IBM Corporation 2005

Figure 5-4. Viewing Permissions LX024.0

Notes:
To view the permissions that are currently applied to a file, use the Is -1 command.
Note that, when viewing the permissions on a directory, you cannot use the command
Is -1 cdirectoryname>, since that command lists the contents of the directory, and not the
directory itself. Instead, use the command Is -Id <directoryname>.

r= FQCk !i
b: Uii. 4
A: e?'

O Copyright IBM Corp. 2001,2005 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

Permissions Notation

owner group other


regular files:
r file is readable
w file is writeable
x file is executable ( if in an executable format )

directories:
r contents of directory can be listed (1s)
w contents can be modified (addldelete files)
x change into directory is possible (cd)

O Copyright IBM Corporation 2005

Figure 5-5. Permissions Notation LX024.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 1s.
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 O Copyright IBM Corp. 2001,2005


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

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

O Copyright IBM Corp. 2001,2005 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

Required Permissions
Btesrwn,\c,
- slLa9-d
Command Source directory Source file Target directory

cd X N/A

1s x, r N/A

mkdir, rmdir XI w

cat, less X

x, w I sane!!!

O Copyright IBM Corporation 2005

Figure 5-6.Required Permissions LX024.0

Notes:
The visual shows the permissions that are required for certain common Linux commands.
Note that you do NOT need write permissions on a file for moving or removing that file. This
sounds strange at first, but is easily explained: the name of a file is actually stored in a
directory. So if you have write permissions on a directory, you can change the name of al1
files in that directory, or remove files from that directory.

5-8 Linux Power User O Copyright IBM Corp. 2001,2005


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

Changing Permissions (1 of 2)
To change the permission of a file use the chrnod command
Syntax: chmod <MODE> <FILE [S]>
Mode can be symbolic...
$ chmod go-rx /home/tuxl
$ 1s -Id /home/tuxl
drwx-- - - - 4 tuxl users
m 512 Jan 5 12:43 /home/tuxl

or octal:

$ chmod 700 /home/tuxl


$ 1s -Id /home/tuxl
---- 4 tuxl users 512 Jan 5 12:43 /home/tuxl

O Copyright IBM Corporation 2005

Figure 5-7.Changing Perrnissions (1 of 2) LX024.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:
chmd <who operator what> <filmame(s)>
<who> can be:
u for the owner (user) of the file
g for the group assigned to the file
o for al1 other users
a for al1 (owner+group+others)
<operator> can be:
+ to add permissions
- to delete permissions
O Copyright IBM Corp. 2001,2005 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 al1 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 O Copyright IBM Corp. 2001,2005


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

Changing Permissions (2 of 2)
Calculating numeric (octal) mode:

MIX r-x

T
+0+1=0/

4+2+1=\[

mode is 750

O Copyright IBM Corporation 2005

Figure 5-8.Changing Permissions (2 of 2) LX024.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 cense.
When applying these permissions, experienced Linux users don't have to think about them
anymore, but apply them blindly. These combinations are:
600 (N-------) 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.

O Copyright IBM Corp. 2001,2005 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: Itmp actually has an additional permission bit set called


the "sticky bit". Because of this bit, the permissions in reality are
4777, or rwxrwxrwt. This is covered in the LX03.

5-12 Linux Power User O Copyright IBM Corp. 2001,2005


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

umask
New files should not be created with 666! To avoid this problem a
permission mask exists.

regular files:
default permissions tw-rw-rw- 666

umask ( - ) ----W--W- 022

resulting permissions W-r--r-- 644

directories:
default permissions rwxrwxrwx 777

umask ( - ) ----W--w- 022

resulting permissions rwxr-xr-x 755

Syntax: umask 022


O Copyright IBM Corporation 2005

Figure 5-9.umask LX024.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 becomes 644 (rw-r--r--, 666-022)
and the default permissions for a directory becomes 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 al1 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.

O Copyright IBM Corp. 2001,2005 Unit 5. File and Directory Permissions 513
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Checkpoint

$ pwd
/groups/
$ 1s - 1
drwxrwxr-x 2 root penguins 512 Feb 25 10:03 penguins
$ 1s - 1 penguins
- ~ w - r - - r - -1 tuxl penguins 544 Feb 25 10:15 he1lo.c
- m - r - r -- 1 tuxl penguins 544 Feb 25 10:15 task.c
- r w - r - r -- 1 tuxl penguins 544 Feb 25 10:15 2ip.c

Can tux2 (who is also a member of the penguins group) successfully execute
the following commands?
1. cd Igroupslpenguins n/
2. mkdir Igroupslpenguinslmydiry
3. cp Igroupslpenguinsltask.~-1task.c
4. vi lgroupslpenguinslzip.~ \I
5. vi Igroupslpenguinslnewfile.~V
6. rm Igroupslpenguinslhello.~K
O Copyright IBM Corporation 2005

Figure 5-10. Checkpoint

Notes:

5-14 Linux Power User O Copyright IBM Corp. 2001,2005


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

Unit Summary
Permissions determine whether a user is able to do something with
a file or directory
Permissions can be set for the user, the group and al1 others
Three base permissions exist: read, write and execute
To view the permissions, use Is -1
Permissions can only be changed by the owner of the file or
directory, and by root
The umask determines the default permissions on a file

O Copyright IBM Corporation 2005

Figure 5-11. Unit Summary LX024.0

Notes:

O Copyright IBM Corp. 2001,2005 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 O Copyright IBM Corp. 2001,2005


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

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 lnternet for gathering information about
Linux

How You Will Check Your Progress


Accountability:
Checkpoint questions
Machine exercises

O Copyright IBM Corp. 2001,2005 Unit 6. Linux Documentation 6-1


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

Unit Objectives
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 importante of lnternet for gathering information about
Linux

O Copyright IBM Corporation 2005

Figure 6-1. Unit Objectives LX024.0

Notes:

6-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

The man Command


With the rnan command you can read the manual page of
commands.
Manual pages are stored in /usr/share/man
The manual page consists of:

Name The name of the command and a one-line


description
Synopsis The syntax of the command

Description Explanation of how the command works and


what it does
Files The files used by the command

Bugs Known bugs and errors

See also Other commands related to this one


O Copyright IBM Corporation 2005

Figure 6-2. The man Command LX024.0

Notes:
The man command shows the manual page of the commands andlor subroutines given as
an argument to the man command.
Most manual pages 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 behaviorlperformance of the
command in unusual circumstances

O Copyright IBM Corp. 2001,2005 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 te11 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 shows you other commands and key sequences to
view the output. The b key shows you the previous page of inforniation.
You can search for a pattern in a manual page with the 1 key.

6-4 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

man Example (1 of 2)

$ man finger
NAME
finger - user information lookup program

SYNOPSIS
f inger [ - lmspl [user ...1 [user@hostl

DESCRIPTION
The finger command displays information
about the system users.

Options are:
- S Finger displays the userls login name,

O Copyright IBM Corporation 2005

Figure 6-3.man Example (1 of 2) LX024.0

Notes:
This is only the first screen of the manual page of the finger command. You can now use
the less commands (spacebar, b, q and so forth) to browse the page.

O Copyright IBM Corp. 2001,2005 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

rnan Example (2 of 2)
The -k option of the man command or the aprspac command prints
out a description of al1 entries which match the given keyword

$ rnan - k p r i n t
a r c h (1) - p r i n t machine a r c h i t e c t u r e
d a t e (1) - p r i n t o r set t h e system d a t e and t i m e
logname (1) - p r i n t u s e r v s l o g i n name
IPC ( 8 ) - l i n e p r i n t e r c o n t r o l program
lpd (8) - l i n e p r i n t e r spooler daemon
I p r (1) - o££ l i n e p r i n t
I p m (1) - remove jobs from t h e l i n e p r i n t e r queue

O Copyright IBM Corporation 2005

Figure 6-4. rnan Example (2 of 2) LX024.0

Notes:
The rnan -k command shows the commands that have manual pages that contain any of
the given keywords in their title.
The apropos command can also be used and is equivalent to using the rnan -k command.
To allow the use of rnan -k and apropos the superuser (root) must have run the
lusrlsbinlmakewhatis command to create the Ivarlcachelmanlwhatisfile. Typically, a
distribution or an administrator sets up a cron job so that this is done each night. This is
covered in the LX03.

6-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

man Sections
Manual pages are divided in 9 sections:
l. User commands
2. System calls
3. Libc calls
4. Devices
5.File formats and protocols
6. Games
7.Conventions, macro packages and so forth
8. System administration
9. Kernel
Certain subjects appear in multiple sections
To select correct section, add section number:
man 1 passwd (about the passwd command)
man 5 passwd (about the passwd file)

Q Copyright IBM Corporation 2005

Figure 6-5. man Sections LX024.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 come 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.

O Copyright IBM Corp. 2001,2005 Unit 6. Linux Documentation 6-7


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

The info Command


Sometimes a replacement for manual pages
Widely used by the GNU project
lnformation for info is stored in /usr/share/info
Some info commands:

space next screen o£ text


del or bs previous screen o£ text

next node
previous node

q quit info

O Copyright IBM Corporation 2005

Figure 6-6. The info Command LX024.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 displays 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> P ~ ~ V ~page
OUS of text
n Next node

6-8 Linux Power User O Copyright IBM Corp. 2001,2005


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

Previous node
Go to up node
To top of node
To end of node

S Search for a string in the current node


? Go to the help
1 Leave the help and go back to the node
q Quit info
<tab> Jump to the next cross reference
Follow this cross reference (this brings 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 makes 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 asks you what menu
item you want to go to. Just entering an enter makes 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."

O Copyright IBM Corp. 2001,2005 Unit 6. Linux Docurnentation 6-9


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

info E x a m ~ l e

# i n f o pwd

File: coreutils.info, Node: pwd invocation, Next: stty invocation, Up: \


Working context

'pwdl: Print working directory


..............................
'pwdl prints the fully resolved name of the current director~.That
is, al1 components of the printed name will be the actual directory
names--nonewill be symbolic links

Because most shells have a built-in command by the same name, using
the unadorned command name in a script or interactively may get you
different functionality than that described here.

The only options are a lone '--helplor '--versionl. *Note Common


options::.

Welcome to Info version 4.2. Type C-h for help, m for menu item.
O Copyright IBM Corporation 2005

Figure 6-7. info Example LX024.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 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.
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 al1 the lines of the node.

6-10 Linux Power User O Copyright IBM Corp. 2001,2005


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

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.

O Copyright IBM Corp. 2001,2005 Unit 6. Linux Documentation 6-11


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

The --help Option


Another way of getting help about a command
Help is built in the command itself (if supported)

$ who --help
Usage: who [OPTION] ... [ FILE 1 ARGl ARG2 ]

-h, --heading print line o£ column headings


-m only hostname and user
associated with stdin
-9, --count al1 login names and number of
users logged in
- - help display this help and exit
--version output version information and exit

O Copynght IBM Corporation 2005

Figure 6-8.The --help Option LX024.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 shows 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 probably does not fit on your screen. To read the complete help, issue
who --help ( less, which shows the output by page.
Note that not al1 commands support the --help option.

6-12 Linux Power User O Copyright IBM Corp. 2001,2005


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

HOWTO Documents
e Documents which describe in detail a certain aspect of configuring
or using Linux.
Detailed information about how to perform a given task
- lnstall PCMCIA support
- Kernel compilation
- Dual boot with other operating systems
HOWTO documents are text files in lusrlshareldoclHOWTO
- Need to be installed manually
On the Internet:
- http://www.tldp.org/index.html

O Copyright IBM Corporatmn 2005

Figure 6-9. HOWTO Documents LX024.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-answerformat. 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.

O Copyright IBM Corp. 2001,2005 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

HOWTO Example

$ less /usr/share/doc/~O~~O/~Free86-HOWTO
The Linux XFree86 HOWTO
by Eric S. Raymond
v5.8, 16 August 1998

This document describes how to obtain, install, and


configure
version 3.3 of the XFree86 version of the X Window System
(XllR6) for Linux systems. It is a step-by-stepguide to
configuring XFree86 on your system.

Table of Contents

O Copyright IBM Corporation 2005

Figure 6-10. HOWTO Example LX024.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 O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Other Documentation
Certain programs also offer other kinds of documentation
- HTML
- PostScript
- Plain Text
Usually stored in /usr/share/doc/~programname>

O Copyright IBM Corporation 2005

Figure 6-11. Other Documentation LX024.0

Notes:
When a programmer creates a program, he or she usually includes the standard
documentation such as manual andlor info pages, and implements 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
/usrlshare/docl~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 Web site about their program, consisting of more than twenty HTML pages with
supporting graphics, example configuration files and so forth. So your mileage might vary
here.

O Copyright IBM Corp. 2001,2005 Unit 6. Linux Documentation 6-15


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

lnternet
All Linux documentation is available on the Internet.
e Google: http://www.google.com/linux
Other cites:
- http://www.tldp.org
- http://www.linux.org
- http://www.redhat.com
- http://www.suse.com tt t \~'u.c ~ m s u * - & $3 a
- http://www.xfree86.org
- http://www.kernel.org
- http://lwn.net
- and many more
Usenet news:
- comp.os.linux.*
- Country-specific groups

O Copyright IBM Corporation 2005

Figure 6-12. lnternet LX024.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 O Copyright IBM Corp. 2001,2005


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

Checkpoint

TIF 1. A HOWTO document is the best source of


documentation if you want up-to-date
information about a specific command. -i 5

2. The main Linux documentation Web site is:


a. http://www.tldp.org
b. http://www.linux.org
c. http://www.lwn.net
d. http://www.kernel.org

3. In which sections are manual pages divided?

O Copyright IBM Corporation 2005

Figure 6-13. Checkpoint

Notes:

O Copyright IBM Corp. 2001,2005 Unit 6. Linux Documentation 6-17


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

Unit Summarv
The man command can be used from the command line to view the
proper syntax of Linux commands.
For manual pages that are out-of-date, you can use the info
command to view the syntax.
Specific system administration tasks are described in the HOWTO
documents.
The lnternet is the place for the latest information about Linux.

O Copyright IBM Corporation 2005

Figure 6-14. Unit Summary LX024.0

Notes:

6-18 Linux Power User O Copyright IBM Corp. 2001,2005


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

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

O Copyright IBM Corp. 2001,2005 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

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

O Copyright IBM Corporation 2005

Figure 7-1. Unit Objectives LX024.0

7-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

Directory Structure
Al1 Linux directories are contained in one, virtual, "unified filesystem"
Physical devices are mounted on mount points
- Floppy disks
- Hard disk partitions
- CD-ROM drives
No drive letters like A:, C:, ...

O Copyright IBM Corporation 2005

Figure 7-2.Directory Structure LX024.0

Notes:
All Linux directories and files are contained in one virtual "unified filesystem". This means
that al1 physical devices with filesystems on them (floppy disks, hard disk partitions,
CD-ROM drives) are al1 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 UNlX filesystem, with some minor
modifications. In the next few graphics you can view the contents of the various directories.

O Copyright IBM Corp. 2001,2005 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

Ibin, Ilib, lsbin

dbin contains executables for every user


dsbin contains system administration executables
mllib contains libraries
l Should always be available
-At system boot
-In single user mode
-When booting from rescue disk
O Copyright IBM Corporation 2005

Figure 7-3./bin, /lib, and /sbin LX024.0

Notes:
Ibin, Ilib and Isbin 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 Ibin and Isbin is in the people who use them: Ibin is for everybody,
and Isbin are typically tools only needed by the system administrators. Therefore, you
cannot find Isbin in the search path ($PATH) of a normal user, but you can 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.

7-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

lboot

Contains kernel image and some other goodies

O Copyright IBM Corporation 2005

Figure 7-4. /boot LX024.0

Notes:
The lboot directory contains the kernel images, some other things related to these images
and the files needed for the bootloader (LILO or GRUB).

O Copyright IBM Corp. 2001,2005 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

ldev

*Contains special files that represent hardware devices


-Block special device, for example, a hard disk
-Character special device, for example, mouse and
keyboard
~Each device has a major and minor number
- Identification within the kernel

O Copyright IBM Corporation 2005

Figure 7-5. /dev LX024.0

Notes:
The ldev 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 directory' :
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.

' Note that two other types of special files exist too: Named Pipes and UNlX Sockets. These are generally not located in /dev, but in Itmp
or Ivar, since they are created on-the-fly by the programs that use them.

7-6 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials may not be reproduced in whole or in part
without the prior written perrnission 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.

O Copyright IBM Corp. 2001,2005 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

letc

&! í h ,blb
iq
l Contains &tem-wide configuration files
<OS? y clii

asome subsystems have multiple files and therefore use a


separate directory
-1etclXI 1 contains X Window System configuration
-1etcIskel contains default user configuration files
-1etclsysconfig contains system configuration

Q Copyright IBM Corporation 2005

Figure 7-6. /etc LX024.0

Notes:
letc 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.

7-8 Linux Power User O Copyright IBM Corp. 2001,2005


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

lhome

Home directories of users

O Copyright IBM Corporation 2005

Figure 7-7. Ihome LX024.0

Notes:
Ihome contains the home directories of the users. Within home, each user has its own
directory, identified by the username, for instance, /home/bill.

O Copyright IBM Corp. 2001,2005 Unit 7. A Tour through Linux 7-9


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

lmnt

Mount points for other filesystems


Note: SUSE uses /media instead of /mnt for floppy and
cdrom mountpoints

O Copyright IBM Corporation 2005

Figure 7-8.Imnt LX024.0

Notes:
lmnt is usually used as a placeholder for al1 the mount points you 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 OS12 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.

7-10 Linux Power User O Copyright IBM Corp. 2001,2005


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

lproc

.Virtual filesystem
Represents kernel and process information

O Copyright IBM Corporation 2005

Figure 7-9. /proc LX024.0

Notes:
lproc 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:
Iproclinterrupts contains al1 the interrupts (IRQs) the kernel knows of
Iprocldma contains al1 the DMA (Direct Memory Access) channels
lproclioports contains al1 the configured 110 (Input/Output) ports
Iproclnetlsockstat contains statistical information about network sockets
Iproclllenviron contains the environment of process 1
Iproclselflcwd contains the current working directory of the process that tried to access
this file

O Copyright IBM Corp. 2001,2005 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

lroot

Home directory of the root user

O Copyright IBM Corporation 2005

Figure 7-10. /root LX024.0

Notes:
lroot is the home directory of the root user.

7-12 Linux Power User O Copyright IBM Corp. 2001,2005


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

~Temporarystorage space for programs, users


l Usually automatic cleanup mechanism active

O Copyright IBM Corporation 2005

Figure 7-11. /tmp LX024.0

Notes:
Itmp 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
Itmp of files older than a few days.

O Copyright IBM Corp. 2001,2005 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

lusr

UNIX System Resources


.Contains al1 programs, libraries and so on which are not
essential for system boot and emergency operations
.lusr/local intended for programs not in the distribution
- Locally developed
- Locally compiled

O Copyright IBM Corporation 2005

Figure 7-12. Iusr LX024.0

Notes:
lusr is by far the largest directory on a freshly installed Linux system. It contains al1 the
programs that need to be available on the system, but need not be available at boot time or
in an emergency.
Some important subdirectories of lusr are:
Iusrlbin, Iusrlsbin, Iusrllib - The equivalents of Ibin, Isbin and Ilib
Iusrldict - Contains dictionary files
/usr/doc - Documentation
Iusrletc - Network-wide configuration files, if lusr is mounted over NFS
Iusrlgames - Your favorite place
/usr/info, /usr/man - lnfo and manual pages for commands
Iusrlsrc - Sources

7-14 Linux Power User O Copyright IBM Corp. 2001,2005


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

/usr/local - lntended 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 still exists. You only need to figure out the correct
$PATH settings afterwards.
If you are using /usr/local to create local programs, it is a good idea to make this a
separate filesystem. This makes it easier to make backups of your local programs, and
makes it safer to do upgrades.

O Copyright IBM Corp. 2001,2005 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

lvar

l Files of variable size


- Logfiles
- Lockfiles
l Directories with variable content
- Mail
- Scheduling
- Printing
~Temporarystorage space, longer than Itmp
O Copyr~ghtIBM Corporation 2005

Figure 7-13. Ivar LX024.0

Notes:
lvar 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 e-mail 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.

7-16 Linux Power User O Copyright IBM Corp. 2001,2005


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

l Exists in every filesystem


P l a c e where lost+found files are stored after a crash
recovery by fsck.

O Copyright IBM Corporation 2005

Figure 7-14. /lost+found LX024.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) checks the filesystem and place any
files it found not to have a name in lost+found. The system administrator then has to decide
who that file belonged to and find a way to "give it back to the rightful owner.

O Copyright IBM Corp. 2001,2005 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

Other Directories in 1

olopt: used for some software from externa1 providers


- Separate filesystem advisable
l Whatever you create yourself.

O Copyright IBM Corporation 2005

Figure 7-15. Other Directories in 1 LX024.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 lopt directory. Sometimes
commercial/3rd party software for Linux installs itself in this directory.
On a SUSE system, subsystems like GNOME, KDE and OpenOffice are installed in Iopt.

7-18 Linux Power User O Copyright IBM Corp. 2001,2005


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

Virtual, Unified Filesystem


Linux does not use drive letters (A:, C:, D:) to identify
driveslpartitions, but creates a virtual, unified filesystem
Different driverslpartitions are "mounted" on a "mountpoint"

ldevlhda2 is the
1 "root filesystem"

this directory

"mounted"on Iusr "mounted" on Ivar


O Copyright IBM Corporation 2005

Figure 7-16. Virtual, Unified Filesystem LX024.0

Notes:
Linux uses a virtual, unified filesystem model. This means that the filesystems that reside
on different disks and in different partitions are not accessed by a unique driveletter (like
Windows does), but are al1 "mounted" on top of each other in a huge, virtual filesystem.
This offers transparency to users, makes system administration easier, and makes it
possible to support far more than 26 different filesystems simultaneously.
The first filesystem is called the "root filesystem" and is mounted by the kernel itself, when
the kernel starts. In addition to regular directories and data, this filesystem also contains a
number of empty directories, which are used as mount points for other filesystems. As an
example, take a look at /dev/hda6 in the visual. It is a fully contained filesystem, with its
own directories and files. One of the directories is called "log". When this filesystem is
mounted on the "var" directory in the root filesystem, the "log" directory now becomes
available in our virtual filesystem hierarchy as "/var/log".
But you also could have mounted ldevlhda6 on, let's say, the mount point (empty directory)
"variable" in the root filesystem (/dev/hda2). Then. al1 of a sudden, the "log" directory would
have become available as "/variable/log".

O Copyright IBM Corp. 2001,2005 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

There are several reasons for creating multiple filesystems, and then mounting these on
top of each other:
It makes it easier to do partial and incremental backups
It allows you to set different disk space quota per filesystem
It allows you to split your data over multiple disks and makes migration of data between
disks easier
It allows you to apply different security settings (such as read-only) to different
filesystems
It allows you to mount certain filesystems over the network
Therefore, on important servers, you typically see multiple (sometimes even hundreds) of
filesystems, al1 mounted on top of each other.
There are only a few directories in the root filesystem which cannot be a separate
filesystem :

All other directories are candidates to become a separate filesystem. To determine which
scheme is useful, you need to attend the System Administration class.

7-20 Linux Power User O Copyright IBM Corp. 2001,2005


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

Typical Filesystem Layout

Typical Workstation: Typical Server:

O Copyright IBM Corporation2005

Figure 7-17. Typical Filesystem Layout LX024.0

Notes:
The filesystem layout typically reflects the expected usage of the system.
A typical dual-boot workstation has al1 its Linux-specific data in one big root filesystem. All
Windows-specific data is in one big NTFS formatted Windows filesystem, and al1 data that
needs to be shared across both platforms sits in a separate, FAT-formatted filesystem
which can be accessed by both.
A typical server is not dual-boot, but runs Linux exclusively. It has separate filesystems for
each of the main directories. These filesystems can then be backed up individually, can
have different quota applied, and so forth.

O Copyright IBM Corp. 2001,2005 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

The mount Command


The mount command mounts a filesystem
- Makes it part of the unified filesystem structure
mount [-t type] [ - o optsl device mountpnt

1 # mount /dev/hda5 /usr


I

Qin llib I s b i n d
O Copyright IBM Corporation 2005

Figure 7-18. The mount Command LX024.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 want to mount the /dev/hda5 partition on the /usr mountpoint.
The command to use then becomes:

7-22 Linux Power User O Copyright IBM Corp. 2001,2005


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

The umount Command


The umount command unmounts a filesystem
- Takes it out of the unified filesystem structure
- Filesystem should not be busy
umount {devicelmountpnt)

# umount /dev/hda5
- OR -
# umount /usr

O Copyright IBM Corporation 2005

Figure 7-19. The umount Command LX024.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.

O Copyright IBM Corp. 2001,2005 Unit 7. A Tour through Linux 7-23


Course materials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Notebook

The letclfstab File -

letclfstab lists al1 known filesystems on the system


Syntax:
device mountpoint type options dump fsck
Filesystems with the noauto option are not mounted automatically
but can be used as templates for mount

# cat /etc/£stab
/dev/hdal /mnt/win95 vfat de£aults O O
/dev/hda2 / ext3 de£aults 1 1.
/dev/hda5 /usr ext3 de£aults 1 2
/dev/hda6 /var ext3 de£aults 1 2
/dev/cdrom /media/cdrom iso9660 noauto,owner,ro O O
/dev/fdo /media/£loppy auto noauto, owner O O
none /proc proc defaults O O
none /dev/pts devpts gid=5,mode=620 O O

Note: Some distributions use filesystem labels instead of device names!


O Copyright IBM Corporation 2005

Figure 7-20. The Ietclfstab File LX024.0

Notes:
The Ietclfstab file lists al1 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 lirie
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.
Red Hat, Fedora and a few other distributions use a modified mount command which also allows you to specify the label of an
ext2lext3 filesystern here. When such a label is encountered here, al1 ext2lext3 filesystems on al1 disks are searched for a filesystern with
that particular label. That filesystern is then mounted at the mountpoint specified.
The advantage of this is that you don't have to change your Ietclfstab file after adding or removing disks andlor partitions.
An Ietclfstab line which uses the labels instead of device names will look like this:
LABEL=/ / ext3 defaults 1 1

7-24 Linux Power User O Copyright IBM Corp. 2001,2005


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 ImnVcdrom and 1mnt/floppy3.

As rnentioned before, SUSE uses Imedidfloppy and Imedidcdrorn instead of Irnntífloppy and Imntícdrorn.

O Copyright IBM Corp. 2001,2005 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

Mountina and Unmountina Removable Media


Most distributions configure Ietclfstab so that the console user is
allowed to mount removable media (floppy, cd) on a predetermined
mountpoint and with predetermined options (for security)
Always unmount media before ejecting!
The GUI typically offers icons that perform the mount

$ whoami
tuxl
$ mount /media/cdrom
$ mount

/dev/cdrom on /media/cdrom type iso9660 (ro,nosuid,nodev,user=tuxl)

1 $ unount /media/cdrom

O Copyright IBM Corporation 2005

Figure 7-21. Mounting and Unmounting Rernovable Media LX024.0

Notes:
As you have seen two visuals ago, both the floppy and CD-ROM are predefined m i the
/etc/fstab file, but have the noauto option set, so they're not automatically mounted when
the system boots.
These entries are nevertheless useful, since the mount command uses this file to
complete the information about a filesystem if only a partial mount command is given: The
only command needed to mount a floppy disk is:

which will be expanded by the mount command to


mount -t auto -o m e r /dev/fdO /media/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. It's enough to be logged in on the console.

7-26 Linux Power User O Copyright IBM Corp. 2001,2005


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

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 it.
Make cure to always unmount a filesystem before ejecting it. This is particularly a problem
with floppy disks, who use a hardware eject. The software eject of a CD-ROM player is
disabled by Linux while a filesystem is mounted.

O Copyright IBM Corp. 2001,2005 Unit 7. A Tour through Linux 7-27


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

Checkpoint

TIF 1. Linux uses drive letters (A:, B:, C: and so forth),


just like Windows.

2. The best location for the mount command would be


a. letc
b. Ibin
c. lsbin
d. lusrlsbin

3. Where are most system-wide configuration files


stored?

O Copyright IBM Corporation 2005

Figure 7-22.Checkpoint

Notes:

7-28 Linux Power User O Copyright IBM Corp. 2001,2005


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

Unit Summary
Structure of the filesystem
- Ibin, Ilib, Isbin
- lboot
- Ietc
- Ihome, Iroot
- Itmp
- Iusr
- Ivar
Special filesystems
- Iproc
- lmnt
Special files
- Idev

O Copyright IBM Corporation 2005

Figure 7-23.Unit Summary LX024.0

Notes:

O Copyright IBM Corp. 2001,2005 Unit 7. A Tour through Linux 7-29


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

7-30 Linux Power User O Copyright IBM Corp. 2001,2005


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

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 UNlX 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

O Copyright IBM Corp. 2001,2005 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

Unit Objectives
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

O Copyright IBM Corporation 2005

Figure 8-1. Unit Objectives

Notes:

8-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

Editing Files
Use file command to determine the content of a file

$ f i l e /etc/passwd
/etc/passwd: ASCII t e x t
$ f i l e /usr/bin/passwd
/usr/bin/passwd: ELF 3 2 - b i t LSB e x e c u t a b l e

OTOedit text files, use an editor


.Non-text files can only be changed using the application
that created them, or with a hex editor
.But most configuration files under Linux are text files

O Copyright IBM Corporation 2005

Figure 8-2. Editing Files LX024.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.

O Copyright IBM Corp. 2001,2005 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 O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

The vi text editor


Default editor in al1 UNlX operating systems
Usually the only editor available in emergencies
Relatively hard to learn, but really powerful
As a Linux user, you should be able to use vi for basic editing tasks
- But it's OK if you prefer another editor for daily work
vi in Linux is usually vim (vi improved):
- Syntax highlighting
- Arrow keys, Del, BS work in insert mode
- Multi level undo
- Mouse support

O Copyright IBM Corporation 2005

Figure 8-3.The vi text editor LX024.0

Notes:
vi, which officially stands for visual interpreter, is the most commonly available editor in al1
UNlX 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, al1 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.

O Copyright IBM Corp. 2001,2005 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
e-mail message for instance). In al1 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 al1 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 O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

vi Modes
vi knows three modes of operation
- Command mode (for simple, one-letter commands)
- Edit mode (insert text)
- ex mode (for complicated commands)
Can easily change between modes

Command mode Edit mode


m-

Allows you to type simple,


one-letter commands
.. Allows you to insert text

ex mode
I T
Allows you to execute
complex commands

O Copyright IBM Corporation 2005

Figure 8-4. vi Modes LX024.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.

O Copyright IBM Corp. 2001,2005 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

Starting vi

O Copyright IBM Corporation 2005

Figure 8-5.Starting vi LX024.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 O Copyright IBM Corp. 2001,2005


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

Cursor Movement in Command Mode

O Copyright IBM Corporation 2005

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

Notes:
To move about in your file make sure you are in command mode.
One character left
One character right
Move to beginning of line
Move to end of line
One line up
One line down
\ '
C
\ \neQ
Go to the first line c \ f i u w l c
Go to the last line g;>e 1 evna \ C .
Pay attention to the uppercase commands!

O Copyright IBM Corp. 2001,2005 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

Editing Text in Command Mode


To delete a single character under cursor
To delete a single character left of cursor
To replace a single character
Undo the last change de~s0.d
To repeat last command
To join two lines together

command mode

O Copyright IBM Corporation 2005

Figure 8-7. Editing Text in Cornrnand Mode LX024.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 O Copyright IBM Corp. 2001,2005


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

Switching to Edit Mode


To insert text at begin of line I
To insert text before cursor i
To append text after cursor a
To append text at end of line
To go back to command mode

l iAam-
Command mode Edit mode

ESC

O Copyright IBM Corporation 2005

Figure 8-8.Switching to Edit Mode LX024.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 lnsert 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.

O Copyright IBM Corp. 2001,2005 Unit 8. Editing Files 8-11


Course materials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Notebook

Adding Text in Edit Mode

This file contains some lines.

line 3. S
line 3.
The last line is line 5.
N

L*

L*

- - INSERT - - 3,8 Al 1

Keystroke "i" switches vi to edit mode. New characters


can be inserted at the current position of the cursor
O Copyright IBM Corporation 2005

Figure 8-9.Adding Text in Edit Mode LX024.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 places 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 <ese> key. The bottom line should no longer show
"-- INSERT --".

8-12 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exiting the Edit Mode

This file contains some lines.


Line 2.
And this for example is line 3.
Line 4 follows line 3.
The last line is line 5.
N

3,8 ~ 1 1

Keystroke "ESC" leaves the edit mode.

O Copyright IBM Corporation 2005

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

To leave the edit mode, use the Escape key.

O Copyright IBM Corp. 2001,2005 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

Searching for Patterns


To search for a pattern (in command mode): I~patternr
To repeat the previous search: n

This file contains some lines.


Line 2.
And that for example is line 3.
Line 4 follows line 3.
The last line is line 5.
N

O Copyright IBM Corporation 2005

Figure 8-11. Searching for Patterns LX024.0

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

8-14 Linux Power User O Copyright IBM Corp. 2001,2005


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

Advanced search and replace can be done in ex mode:


To replace old with new: :1,$S /old/new/g

This file contains some lines.


Line 2.
And that for example is line 3.
Line 4 follows line 3.
The last line is line 5.
N

rcn5cr- AL- lnri~). o Copyright IBM Corporation 2005

Figure 8-12. Replacing Patterns LX024.0

Notes:
Advanced search and replace functions are available in ex mode. The command
:%1 ,$S /old/new/g for instance replaces al1 occurrences of the word "old" with "new".
Let's break down this command a little:
The ":" switches to ex mode.
"1 ,$" means that our command is going to apply to al1 lines, starting with line 1 and
ending with the last line of the file. You could also specify "1,5" to limit your search to
lines 1 through 5, inclusive. Other possibilities are ".,$", for the current line through to
the end, or "%", which also means the whole file.
"S" means that you're going to execute a search and replace. There are a lot of other
possibilities here, but "d" ¡S perhaps the most common: it allows you to delete lines.
The first "í" is the start delimiter of the search phrase. The second "1" is the end delimiter
of the search phrase, and the start of the replacing phrase. The third "/" is the end
delimiter of the replacing phrase.

O Copyright IBM Corp. 2001,2005 Unit 8. Editing Files 8-15


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Notebook

You are free to choose your delimiter character, but "/" is the most common. If your
delimiter character happens to be part of the search or replace phrase, then pick a
delimiter character which is not (usually ":" is used instead), or make sure you escape
the delimiter character with a backslash.
The "g" means a global replace. Normally only the first occurrence of the search phrase
on a particular line is replaced.
There are far more possible commands in ex mode. See the manual page of vi.

8-16 Linux Power User O Copyright IBM Corp. 2001,2005


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

Cut, Copy and Paste


To cut a whole line into buffer: dd
To copy a whole line into buffer: YY
To cut a word from the current cursor
position to its end: dw
To paste contents of buffers here: P
To cut, copy multiple lines, proceed command by number: 3dd, 8yy

O Copyright IBM Corporation 2005

Figure 8-13. Cut, Copy and Paste LX024.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
want to cut or copy.

O Copyright IBM Corp. 2001,2005 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

Cut and Paste

is file contains some lines.


ne 2.
d that for example is line 3.
ine 4 follows line 3.
he last line is line 5.

cut line 3 by pressing "dd"


This file contains some lines.

ne 4 follows line 3.
e last line is line 5.
d that for example is line 3.

...and insert it after line 4 by pressing "p"


O Copyright IBM Corporation 2005

Figure 8-14. Cut and Paste LX024.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 1) to go to the line you want to move. Now give the dd command. This
removes 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 can UNDO your last command if you make an error. So, if you delete
something in error, immediately type the u command to retrieve it.

8-18 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Copy and Paste

his file contains some lines.


ne 2.
d that for example is line 3.
ne 4 follows line 3.
he last line is line 5.

copy line 3 by pressing "yy"


This file contains some lines.

d that for example is line 3


ne 4 follows line 3.
e last line is line 5.
d that for example is line 3.

...and insert it after line 5 by pressing "p"


O Copyright IBM Corporation 2005

Figure 8-15. Copy and Paste LX024.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.

O Copyright IBM Corp. 2001,2005 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

vi Options
Options entered in ex mode change the behavior of the vi editor:
:se$all
:set autoindentlnuautoindent
:set number/nonumber
:set tistlnolist
:set showmade/noshowmad
:set tcibs"íspl=x
:set ignarecase/noígnorecase
:set wrapmargin-x
:set tx/notx
:set hls~9archr"nohlsearch
:syntax un/off
To make this options available to al1 vi sessions,
put it into a .exrc or .vimrc file in your HOME-directory

O Copyright IBM Corporation 2005

Figure 8-16. vi Options LX024.0

Notes:
vi has many settings for operation. Some of these affect the way text is presented, while
others make editing easier for novice users.
:set al1 Display al1 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)

8-20 Linux Power User O Copyright IBM Corp. 2001,2005


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 is 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=O Turn off word wrapping
:set tx Set MS-DOS style line endings (CRILF)
:set notx Set UNlX style line endings (LF)
:set hlsearch Set highlighting of search results on
:set nohlsearch Set highlighting of search results off
:syntax onloff Set syntax highlighting onloff
You may want to create a .exrc or .vimrc file in your home directory containlng these
commands (without the leading colon). The settings in this file are then read and applied
when starting vi(m).

O Copyright IBM Corp. 2001,2005 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

Exiting vi
To save and exit in command mode ZZ
To save in ex mode :W

To forcefully save file in ex mode :w!


To quit without saving in ex mode :cl
To forcefully exit in ex mode :q!
To save and exit in ex mode (recommended) :wq
To save and exit in ex mode, shorter :x

O Copyright IBM Corporation 2005

Figure 8-17. Exiting vi LX024.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.

- - -- --

8-22 Linux Power User O Copyright IBM Corp. 2001,2005


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

vi Cheat Sheet
Command mode Edit mode
To edit mode
II i ia B I - - -
Can now type
cut, copy, paste line join lines cursor move 1 text. Note: In
vim arrow keys,
delete char, word ,search, repeat, 1 k 11 Del, Backspace
will work.

I I I L I

Ex mode 1 7 I
search and replace
1 :%S /01d/new/~ 1
save, exit
:w :w! :q :q! :wq:x ]
O Copyright IBM Corporation 2005

Figure 8-18. vi Cheat Sheet LX024.0

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

O Copyright IBM Corp. 2001,2005 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

Other Editors
A typical Linux distribution comes with a large number of editors.
Examples:
Text mode editors
- pico (really simple)
- Original vi
- emacs (even more powerful and complicated than vi)
Graphical mode editors
- kedit, kwrite
- gedit
Hex editors allow you to change non-text files if you know the
interna1 structure
- khexedlt

O Copyright IBM Corporation 2005

Figure 8-19. Other Editors LX024.0

Notes:
If you don't want to use vi, or can't use v i 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!)

8-24 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in par1
without the prior written perrnission of IBM.
Student Notebook

Checkpoint
TIF 1. You need to learn vi because vi ¡Sthe best editor
for any job. F

2. What does the file command do?


a. It looks at the extension to determine the type of file.
b. It looks at the first few characters of the file and compares
rC

this to a database of known file types.


c. It asks the kernel for information about the file.
d. It makes a wild guess.

3. What is a hex editor?

O Copyright IBM Corporation 2005

Figure 8-20.Checkpoint LX024.0

Notes:

O Copyright IBM Corp. 2001,2005 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

Unit Summary
The most common editor on any UNlX is vi
vi has three modes of operation: command mode, edit mode and ex
mode
vi makes a copy of the file you are editing in an edit buffer. The
contents are not changed until you save the changes
A typical Linux distribution comes with a lot of other editors as well

O Copyright IBM Corporation 2005

Figure 8-21. Unit Summary

Notes:

8-26 Linux Power User O Copyright IBM Corp. 2001,2005


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

Unit 9. 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

O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-1


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

Unit Objectives
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

O Copyright IBM Corporation 2005

Figure 9-1. Unit Objectives

Notes:

9-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

The Shell
The "shell" is the user interface to Linux

O Copyright IBM Corporation 2005

Figure 9-2. The Shell LX024.0

Notes:
The shell is a special program in any UNlX 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.

O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-3


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

Shell Features
When the user types a command, various things are done by the
shell before the command is actually executed:
Wildcard expansisn * ? [1
InpuUOulput redireetion > >> 2>
Comwiand grauping { coml ; com2; )
Line continuatisn \
Shell variable expansion $VAR
Alias expansion dir -> Is -1
Shell scripting #!/bin/bash
For example, the Is *.doc command could be expanded to Ibinlls
--color=tty mydoc.doc user.doc before execution (depending on
settings and files present)

O Copyright IBM Corporation 2005

Figure 9-3.Shell Functions LX024.0

Notes:
As said, the shell allows you to type your command, after which it interprets it and executes
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 makes your life much simpler.
Some of these transformations are listed in the visual. You cover them in this unit. But
these are not the only things that the shell can do. Just like when we talked about vi, you
are only going to scratch the surface here. For more in-depth information, read the manual,
read the 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).

9-4 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Metacharacters and Reserved Words

e Metacharacters are characters that the shell interprets as


having a special meaning.
Examples:
<>I;!?*[]$\""-O{}

e Resewed words are words that the shell interprets as


special commands.
Examples:
case do done elif else esac fi for function
if in select then until while

O Copyright IBM Corporation 2005

Figure 9-4. Metacharactersand Reserved Words LX024.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 are always 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 character'.

' Technically, it is possible, but it only gets you in trouble later.


O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Basic Wildcard Expansion


When the shell encounters a word which contains a
wildcard, it tries to expand this to al1 matching filenames
in the given directory.

$ 1s -a /home/tuxl 1
. .. .et .w few myfile ne nest net new testl testl.2 testl.3
home
? matches a single ~haracter I
$ echo ne? - ?&\$C. vq Cc<rc.c& r
tk ? j'
tuxl
net new
testl
$ echo ?e? testl.2
few net new testl.3
myfile
* matches any string, including the n u l Z string ne
$ echan* - h numeio'L de ra<c€bí~s"~~ new
ne net new nest nest
$ echo *w net
new few few
.W
.et

O Copyright IBM Corporation 2005

Figure 9-5. Basic Wildcard Expansion LX024.0

Notes:
One of the first things the shell does after it has read your command is to try to perform
wildcard expansion. This means that it starts looking in your command for words that
contain (or solely consist of) one or more wildcards. It then looks 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 al1 by
itself matches any filename in the current directory except for hidden filenames (filenames
that start with a dot12.
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! As
an example, the command "userdel *" is entirely legal, but does not delete al1 user
accounts on your system.
And don't just blindly try "."' either, since that also matches the current directory, and "..", the higher-level directory. So if you
O.",

execute "rm -fr /tmp/.*", you are wiping out your whole system and not just the contents of Itmp

9-6 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

lmportant note: If wildcard expansion fails (thus: there is no file in the filesystem that
matches the pattern supplied), then the wildcards are passed as parameters to the
program, instead of the expanded filenames. This may lead to unexpected results.

O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-7


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

Advanced Wildcard Expansion


-
The wildcards [, 1, and ! match inclusive lists:

$ echo ne [stw]
net new

$ echo *[1-51
testl testl.2
testl.3
/
x c\dv~n\e, z +J O" testl
$ echo [!tnl*
testl.2
myfile few
testl.3
myfile
$ echo ?[!yl*[2-51 ne
testl.2 testl.3 new

40
l1 nest
net
few

O Copyright IBM Corporation 2005

Figure 9-6. Advanced Wildcard Expansion LX024.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 "1") 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 (al1 characters match except the ones listed). See the visual for
examples.

9-8 Linux Power User O Copyright IBM Corp. 2001,2005


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

File Descriptors

Every program has a number of file descriptors


associated with it
Three descriptors are assigned by the shell when the
program starts (STDIN, STDOUT and STDERR)
Other descriptors are assigned by the program when it
opens files

Standard in (O)
Standard In STDlN c O

Standard Out STDOUT > 1

Standard Error STDERR 2> 2 standard out (1) 4 standard error (2)

Q Copyright IBM Corporation 2005

Figure 9-7. File Descriptors LX024.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.

O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-9


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

lnput Redirection -

Default Standard Input:

$ cat
Ams terdam
Aas terdam
Utrecht
Utrecht

STDlN redirected from file:

$ cat < cities


Amstexsdam
Zrkrecht

O Copyright IBM Corporation 2005

Figure 9-8. lnput Redirection LX024.0

Notes:
The symbol tells cat to take input from the file instead of the keyboard.
The file table for the redirection example looks like the following:

1 Descriptor 1 Default 1 When command is running I


1 keyboard
1 screen 1 screen
1 screen 1 screen

9-10 Linux Power User O Copyright IBM Corp. 2001,2005


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

Output Redirection
Default Standard Out~ut: Idevlttv

Redirect output to a file:

Redirect and append output to a file:


Q 1s >> 1s.out

Create a file with redirection:


$ cat > new-file
Save this line
<Ctrl -D>
--

O Copyright IBM Corporation 2005

Figure 9-9.Output Redirection LX024.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 Is.out.
The file descriptor table in this example holds the following values:

1 Descriptor 1 Default 1 When command runs 1


O keyboard keyboard
1 screen file "ls.outn
2 screen screen

Using ordinary redirection overwrites an existing file. To avoid this, use the >> (no space
between them) to append output to an existing file.

O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-11


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

Error Redirection
Default Standard Error: /dev/tty

$ cat filea
cat: filea: No such file sr disectory

Redirect error output to a file:


$ cat filea 2> error.file
$ cat error.file
cae: fílea: No such file or directary

Redirect and append errors to a file:


I 1
1 $ cat filea 2>> error.file
l
Discard error out~ut:
$ cat filea 2> /dev/null

Figure 9-10. Error Redirection


O Copyright IBM Corporation 2005
A LX024.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 contains the
following:

Descriptor Default When command runs

10 1I keyboard 1I keyboard
1 screen screen
2 screen error.file
and for the second:

9-12 Linux Power User O Copyright IBM Corp. 2001,2005


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

1 Descriptor 1 Default 1 When command runs 1


1 keyboard 1 keyboard
1
2
screen
screen
screen
error.file !

O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-13


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

Combined Redirection
Combined redirects

$ cat < cities > cities.copy 2> error.file


$ cat >> cities.copy 2>> error.file < morecities

Association
This redirects stderr to where stdout is redirected:
A

$ cat cities > citie>.copy 2>~1 -


,,,i\L ,,,, &,&,4 9 L./ .'/e~.
...writes both stderr and stdout to cities,capy

be careful about thís:


$ cat cities 2>&1 > cities.copy
...
wrltes stderr ta /dev/tty and stdout to cities,copy

O Copyright IBM Corporation 2005

Figure 9-11. Combined Redirection LX024.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 is used, which is the screen. So, the error messages are redirected to the screen.
Remember that the default error messages are sent to the screen.
In bash, the sequence "&>" is identical to "2>&1".

9-14 Linux Power User O Copyright IBM Corp. 2001,2005


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

Pipes

A sequence of two or more commands separated by a


vertical bar (1) is called a pipe or pipeline

The standard output of commandl becomes the standard


input of command2

Stdin (O) Stdout (1)

Stderr (2) t t Stderr (2)

O Copyright IBM Corporation 2005

Figure 9-12. Pipes LX024.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 Is sends to standard out can now be counted by wc.

O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-15


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Filters
A filter is a command that reads from standard in, transforms the
input in some way and writes to standard out. They can, therefore,
be used at intermediate points in a pipeline.

$ 1s 1 grep .doc 1 wc - 1
4

O Copyright IBM Corporation 2005

Figure 9-13. Filters LX024.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
Is command lists al1 the files in the current directory and then pipes this information to the
grep command. The output of grep is piped to the wc -1 command. The result is that the
command counts the number of files in our current directory that contain ".docV.In this
example, the grep command is acting as a filter.

9-16 Linux Power User O Copyright IBM Corp. 2001,2005


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

Common Filters
expand, unexpand: Change tabs to spaces and vice versa
sed: Allows string substitutions
awk: Pattern scanning and processing
fmt: lnsert line wraps so text looks pretty
tac: Display lines in reverse order
tr: Substitute characters
grep: Only displays lines that match a pattern
ni: Number lines
pr: Format for printer
sort: Sort the lines in the file

O Copyright IBM Corporation 2005

Figure 9-14. Common Filters LX024.0

Notes:
There exists a large number of programs which can be used as a filter on an average UNlX
system. The list above shows the more common ones.
expand expands al1 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 doesnit 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 copies oldfile
to newfile, changing al1 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.

O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-17


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

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 al1 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 al1 lines.
pr formats your output for a printer, adding headers, footers, page numbers and page
breaks in the process.
sort sorts the lines in the file.

9-18 Linux Power User O Copyright IBM Corp. 2001,2005


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

Split Output

The tee command reads standard input and sends the


data to both standard out and a file.

$ 1s ( tee 1s.save 1 wc - 1
3

$ cat 1s.save
filel
f ile2
file3

O Copyright IBM Corporation 2005

Figure 9-15. Split Output LX024.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.

O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-19


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

Command Substitution
Command Substitution allows you to use the output of a command
as arguments for another command.
Use backticks (') or $0 notation:

$ rm - i '1s *.doc 1 grep tmp-

$ echo There are $(ps ax 1 wc -1) processes running.

O Copyright IBM Corporation 2005

Figure 9-16. Command Substitution LX024.0

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 ( I ) and with the $0 notation.
The examples in the visuals are equal and work as follows:
The Is command generates a list of files in the current directory ending in ".doc".
The grep command filters the list of files, and only shows al1 lines (filenames) that
contain the word "tmp".
The resulting list is used as arguments to the rm command.
In short, the command listed removes al1 files with names ending in ".doc", and containing
the string tmp.

9-20 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Command Grouping
Multiple commands can be entered on the same line, separated by
a semicolon (;)

$ date ; p w d

Commands can be grouped into one inputloutput stream by putting


1
curly braces around them:

$ I echo Print date: ; date ; cat c i t i e s ; ) 1 lpr

Commands can be executed in a subshell by putting round braces


around them:

$ ( echo P r i n t date: ; date ; cat c i t i e s )

O Copyright IBM Corporation 2005


1
1
l p r .-- \ p q ) / ~ QTC,

Figure 9-17. Command Grouping LX024.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 inputloutput stream by putting curly braces ("{" and
")") around them. This combines their inputloutput streams into one.
You can also group commands into one inputloutput stream by putting round braces ("("
and ")") around them. In this case, the grouped commands are executed in a subshell.

O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-21


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

Shell Variables
Variables are part of the environment of a process
A variable has an unique name
The first character must not be a digit
To assign a value to a variable use:
variable=value

O Copyright IBM Corporation 2005

Figure 9-18. Shell Variables LX024.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.

9-22 Linux Power User O Copyright IBM Corp. 2001,2005


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

Referencing Shell Variables


To reference the value of a variable, use:
$variable

$ echo $VARl
Hello class

$ echo $ V A R ~
2

O Copyright IBM Corporation 2005

Figure 9-19. Referencing Shell Variables

Notes:
To reference a variable, use the $variable expression.

O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-23


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

Exporting Shell Variables


The export command is used to pass variables from a parent to a
child process.
Changes made to variables in a child process do not affect the
variables in its parent.

$ export x=4
$ bash
9: echa $x
4
$ x-100
$ echo $ x
108
$ exit
$ echo $x
4

O Copyright IBM Corporatlon 2005

Figure 9-20. Exporting Shell Variables LX024.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 al1 subsequent child processes
(including subshells) too.
The export command exports a variable or lists 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.

9-24 Linux Power User O Copyright IBM Corp. 2001,2005


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

Standard Shell Variables


The shell uses several shell variables internally
- These variables are always written in uppercase
Example:
- $: PID of current shell
- PATH: Path which is searched for executables
- PS1: Primary shell prompt
- PS2: Secondary shell prompt
- PWD: Current working directory
- HONIE: Home directory of user
- LANG: Language of user
Overwriting these variables by accident can cause unexpected
results
-Always use lowercase variables in your own shell scripts to avoid
conflicts

O Copyright IBM Corporation 2005

Figure 9-21. Standard Shell Variables LX024.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 al1 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 is not searched. This is
considered a safety feature and therefore the default in most distributions.
PS1 The primary command prompt. This prompt ¡Sshown when the shell is able
to accept a command.

O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-25


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

Special character sequences exist which can be used in this prompt, and
which is expanded to, for instance, the current username, directory or time
of the day. See the manual page of bash for details.
The secondary command prompt. This prompt is shown for instarice after
the user ended a line with the line continuation character (backslcish).
PWD The current working directory.
HOME The home directory of the user
LANG The current language of the user. This variable is used for instante 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
ASCll sorting order.
There are far more shell variables that the shell uses internally. If you overwrite ttnem
accidentally, you might experience strange problems. It is therefore a good idea to use
lowercase variables in your own shell scripts.

9-26 Linux Power User O Copyright IBM Corp. 2001,2005


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

Return Codes from Commands


A command returns a value to the parent process. By convention,
zero means success and a non-zero value means an error
occurred.
A pipeline returns a single value to its parent
The environment variable ? contains the return code of the previous
command.

$ whoami
tuxl
$ echo $ ?
o
$ cat filea
cat: filea: No such file or directory
$ echo $ ?
1

O Copyright IBM Corporation 2005

Figure 9-22. Return Codes from Cornmands LX024.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 O means that the process ran correctly. A return code other than O 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 $?.

O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-27


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

Quoting Metacharacters
When you want a metacharacter NOT to be interpreted by the shell,
you need to quote it
Quoting a single character is done with the backslash (\)

$ echo The amount is uS\$ 5


The amount is US$ 5

Quoting a string is done with single (') or double (") quotes


1
- Double quotes allow interpretation of $, '(backtick) and \

$ amount=5
$ echo IThe amount is $amountl
The amount is $amount
$ echo 'The amount is $amountu
The amount is 5
O Copyright IBM Corporation 2005

F i g u r e 9-23. Q u o t i n g M e t a c h a r a c t e r s LX024.0

Notes:
When you want a certain metacharacter NOT to be interpreted by the shell, you rieed 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 ( I )

backslash (\). This allows you to use variables, command interpolation and q~ioting
non-metacharacters within a string.

9-28 Linux Power User O Copyriglit IBM Corp. 2001,2005


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

Quoting Non-Metacharacters
The backslash can also be used to give a special meaning to a
non-metacharacter (typically used in regular expressions)
- \n = newline
- \t = tab
- \b = bell
A backslash followed directly by Enter is used for line continuation
- The continued line ¡Sidentified with the $PS2 prompt (default: >)

$ cat/home/john/mydir/mysudir/data/information/letter\
> /pictures/logo.jpg

O Copyright IBM Corporation 2005

Figure 9-24. Quoting Non-Metacharacters LX024.0

Notes:
The backslash character may also be used to give a special meaning to a
non-metacharacter. This is typically used in regular expressions, for instance when you do
a grep. Some examples:
\n is expanded to a newline
\t is expanded to the tab character
\b is expanded to the bell sign
A backslash directly followed by the Enter key is used for line continuation.

O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-29


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

Aliases
The alias command allows you to set up aliases for often-used
commands
Examples:

$ alias ll=Ils -1'


$ alias rrn=Irm - i l
To show a11 currently defined allanes:
$ alias
To delete an alias:
$ unalias 11
$ 11
bash: 11: command not found

O Copyright IBM Corporation 2005

Figure 9-25. Aliases LX024.0

Notes:
The shell also supports aliases. An alias is typically a short letter combination whiich
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 al1 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.

9-30 Linux Power User O Copyright IBM Corp. 2001,2005


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

Checkpoint

TIF 1. A filter is a command which reads a file, performs


operations on this file and then writes the result
back to this file. P
2. The output of the Is command is:
ode @o th&e fpdr fyde
yk seven e i e t n y k ten
What will the output be if I run the Is ?e* command?
a. three seven ten
m s e v e n ten
c. one three five seven eight nine ten
d. ?e*

O Copyright IBM Corporation 2005

Figure 9-26.Checkpoint LX024.0

Notes:

O Copyright IBM Corp. 2001,2005 Unit 9. Shell Basics 9-31


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

Unit Summary
The shell is the command interpreter of Linux
The default shell in Linux is bash
A shell has a number of additional features, such as wildcard
expansion, alias expansion, redirection, command grouping,
variable expansion
Metacharacters are a number of characters that have a special
meaning to the shell
Reserved words are words that have a special meaning to the shell

O Copyright IBM Corporation 2005

Figure 9-27. Unit Summary LX024.0

Notes:

4 3 2 Linux Power User O Copyright IBM Corp. 2001,2005


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

Unit 10. 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

O Copyright IBM Corp. 2001,2005 Unit 10. Working with Processes 10-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Unit Objectives
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

O Copyright IBM Corporation 2005

Figure 10-1. Unit Objectives

Notes:

10-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

What Is a Process?
A program is an executable file
A process is a program which is being executed
Each process has its own environment:

aTo see the PID of your current shell process type:

O Copyright IBM Corporation 2005

Figure 10-2. What Is a Process? LX024.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 interna1 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.

O Copyright IBM Corp. 2001,2005 Unit 10. Working with Processes 10-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Starting and Stopping a Process


All processes are started by other processes
- ParentIChild relationship

.A process can be terminated because of two


reasons:
-The process terminates itself when done
-The process is terminated by a signal from another proces's

O Copyright IBM Corporation 2005

Figure 10-3. Starting and Stopping a Process LX024.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 proce!;~) 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 always
has Process ID 1'.
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.

' 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 arnount of processes and their narnes vary frorn kernel version to kernel version.

10-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

Login Process Environment

Linux System
isbinlmingetty

...forks lbinlbash
-bash (login shell)

O Copyright IBM Corporation 2005

Figure 10-4. Login Process Environment LX024.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 ¡Sstarted. 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.

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?

O Copyright IBM Corp. 2001,2005 Unit 10. Working with Processes 10-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Parents and Children

$ bash
$ -e~ho
$$
675

$ date
Thu Mar 25 22:28:21 CET 1999
$ <ctrr-CL>

PID PPlD
..........................................................................................................
bash
....................................
date 777 675
O Copyright IBM Corporation 2005

Figure 10-5. Parents and Children LX024.0

Notes:
The PID is the process identification number used by the kernel to distinguish the! different
processes. The PPlD 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 i:o be run.
In the example above, a second bash shell is started as a way to illustrate the parentlchild
relationship with processes. As another example, a second, different shell could be started
(for example csh) to run specific shell scripts or programs.

10-6 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Monitoring Processes
The ps command displays process status information

$ ps aux
USER P I D %CPU %MEM VSZ RSS TTY STAT START TIME COMKAND
root 1 0.0 0.0 1336 436 3 S Mar16 0:05 init
root 2 0.0 0.0 O O ? SW Mar16 0:00 [keventdl
root 3 0.0 0.0 O O 3 SW Mar16 0:05 [kapmdl
root 4 0.0 0.0 O O ? SW Mar16 0:05 [kswapdl
...
root 10248 0.0 0.1 2852 884 pts/2 R 13:47 0:00 ps aux

ps supports a large number of options - you typically use ps aux:


a al1 processes attached to a terminal
x al1 other processes
u provides more columns
options are typed without a leading "-" !
O Copyright IBM Corporation 2005

Figure 10-6. Monitoring Processes LX024.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 al1 processes, with and without a tty (a and x) in a user-oriented format (u).

O Copyright IBM Corp. 2001,2005 Unit 10. Working with Processes 10-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Viewing Process Hierarchy --

e pstrecr shows process hierarchy

$ pstree
init-+-apmd
1 -atd
1 -crond
I - SPm
1 -httpd-- -lo*[httpd]
1 -inetd
1 -kattraction.kss
1 -kdm-+-X
1 '-kdm---km-+-kbgndwm
1 1 -kfm
1 1 - kpanel
1 1 -krootwm
1 1-kvt---bash---man---sh-+-gunzip
1 1 - - less
1 '-startkde---autorun
1 -kflushd

O Copyright IBM Corporation 2005

F i g u r e 10-7. V i e w i n g P r o c e s s H i e r a r c h y LX024.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.

10-8 Linux Power User O Copyright lBM Corp. 2001,2005


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

Controlling Processes
Processes can be controlled in two ways:
- From the shell that started it, using its Job number
- From anywhere else on the system, using its P1D
Actions that can be performed on a running process:
- Terminate
- Kill
- StopIContinue
These actions are performed by sending signals

O Copyright IBM Corporation 2005

Figure 10-8.Controlling Processes LX024.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 receives any
keyboard input that is typed into the terminal. A background process does not receive any
keyboard input. Only one process can run in the foreground at once.

O Copyright IBM Corp. 2001,2005 Unit 10. Working with Processes 10-9
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Nofebook

Starting Processes

Foreground Processes
$ find / -name README

Foreground processes are invoked by simply typing a


command at the command line.

Background Processes

the end of the command line.


O Copyright IBM Corporation 2005

Figure 10-9. Starting Processes LX024.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 initiiating
terminal are referred to as background processes.
Background processes are most useful with commands that take a long time to ruin and do
not need to interact with the user.
A background process is started by ending the command line with a &. This musl: be the
last character on the command line.
When a background process is started, you can see two numbers.
[1] 417
This means:
[11 this is the first process you are running in the,
background.

10-10 Linux Power User O Copyright IBM Corp. 2001,2005


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

417 this is the process id o£ this process

--

O Copyright IBM Corp. 2001,2005 Unit 10. Working with Processes 10-11
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Notebook

Job Control in the Bash Shell

ccf rI-z> suspends foreground task

jobc lists background or suspended jobs

resume suspended task in the


foreground

resume suspended task in the


background

~Specifya job number for bg, fg and kill using %job

O Copyright IBM Corporation 2005

Figure 10-10. Job Control in the Bash Shell LX024.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 b g command. To bririg a
suspended or background process into the foreground, use the fg command.
To find out what suspended/backgroundjobs you have, issue the jobs command,.This
command shows 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 is listed.

10-12 Linux Power User O Copyright IBM Corp. 2001,2005


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

Job Control E x a m ~ l e

$ find / -name README &


[l] 2863
$ jobs
[l]+ running find / -name README &
$ fg %1
/usr/share/doc/packages/grub/~~~~~~
....
<ctrl - z>
[1]+ stopped find / -name README
$ bg 2863
$ jobs
[1]+ running f i n d / -nameREADME &
$ kill %find

O Copyright IBM Corporation 2005

Figure 10-11. Job Control Example LX024.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.

O Copyright IBM Corp. 2001,2005 Unit 10. Working with Processes 10-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

KiII Signals
Several signals can be sent to a process
- Using keyboard interrupts (if foreground process)
- Using the kifi command
Synopsis: kill -signal PID
- Using the killall command to kill al1 named apps
Synopsis: killall -signal application
Most important signals:

Signal Keyboard Meanina 1 Default action


o1 han~up 1 end process
interrupt end process
auit end ~ r o c e s sand core d u m ~
kill

O Copyright IBM Corporation 2005

Figure 10-12. Kill Signals LX024.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 UNlX 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 performs the default action for that signal, which in most cases
means that the application is 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 llog off
when a background process is running. Most daemons (discussed later) redefine this
signal to mean "re-read configuration file".

10-14 Linux Power User O Copyright IBM Corpi. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Notebook

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 al1 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 al1 the signals supported use the kill -1 command. This list also shows you the names
of signals. lnstead 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 p s
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.

O Copyright IBM Corp. 2001,2005 Unit 10. Working with Processes 10-15
Course materials rnay not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Running Long Processes

The nohup command stops a process from being killed if you


log off the system before it completes, by intercepting and
ignoring the SlGHUP and SlGQUlT (hangup and quit) signals.

$ nohup find / -name README &


1 nohup: appending output to 'nohup.outc I
$ logout

_I

O Copyright IBM Corporation 2005

Figure 10-13. Running Long Processes LX024.0

Notes:
nohup tells the process to ignore signals 01 and 03 (hangup and quit). This allows the
process to continue if you log off the system.
Since al1 processes need to have an associated parent process, commands that start with
nohup 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.

10-16 Linux Power User O Copyright IBM Corp. 2001,2005


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

Managing Process Priorities


Processes are scheduled according to priority

(negative values are


Base priority allowed only to root!)

O Copyright IBM Corporation 2005

Figure 10-14. Managing Process Priorities LX024.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 then gets 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.

O Copyright IBM Corp. 2001,2005 Unit 10. Working with Processes 10-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 gets
an equal amount of CPU time. Processes with a higher nice value get less CPU time than
processes with a low nice value.

10-18 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

The nice Command

The nice command is used to start a process with a user


defined priority
nice [-n <value>] <original command>

$ n i c e - n 10 myxrogram &
[l] 4862
$ PS 1
F UID PID PRI NI VSZ ... COMMAND
O 500 4372 9 ... -bash
O
O
500 4862
500 4863
15
21
@ 4860
3612
1556
...
...
myjrogram
PS 1

O Copyright IBM Corporation 2005

Figure 1 0-15. The nice command LX024.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 gets some CPU time.

O Copyright IBM Corp. 2001,2005 Unit 10. Working with Processes 10-19
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Notebook

The renice Command

The renice command is used to change the priority of a


currently running process
renice <new-priority> <PID>

$ renice 15 4862
4862: old priority 10, new priority 15
$ PS 1
F UID PID PRI NI VSZ COMMAND ...
O 500 4372
O 500 4862
O 500 4868
21
21 O
4860
3612
1556
6 - bash
myxrogram
PS 1
. ..
...
...

O Copyright IBM Corporation 2005

Figure 10-16. The renice Command LX024.0

Notes:
When you want to change the priority of a process which is already running, use ttie renice
command.

10-20 Linux Power User O Copyright IBM Corp. 2001,2005


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

Various integrated tools exist for process management


top, gpm, kpm
Availability depends on distribution

843 root 2 O 4608 4608 3212 S 020 179 011 kwm


876 root O O 3968 3968 2912 S 0 00 1 54 0 71s kbgndwm

Figure 1 0-17. lntegrated Process Management LX024.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 al1 day, despite the CPU cost. (Running top or kpm typically costs
about 2-5% CPU time.)

O Copyright IBM Corp. 2001,2005 Unit 10. Working with Processes 10-21
Course rnaterials rnay not be reproduced in whole or in pari
without the prior written permission of IBM.
Student Notebook

Daemons

The word "Daemon" refers to a never-ending process, usually a


system process that controls a system resource such as the
printer queue or performs a network service

O Copyright IBM Corporation 2005

Figure 10-18. Daernons LX024.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.
Ipd is one example of a daemon. Ipd tracks print job requests and the printers available to
handle them. The Ipd daemon maintains queues of outstanding requests and serids 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.

A daernon originally rneans a sort of a friendly ghost or spirit, which guards your interests on behalf of you.

10-22 Linux Power User O Copyright IBM Corp. 2001,2005


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

Checkpoint

TIF 1. Any user can send a signal to a process of another


user, and cause this process to halt. F

2. If a process is hanging, the proper order of trying to


terminate it with the lowest chance of data corruption ¡S:
a. kill -1, Ctrl-C, kill, Ctrl-\
b. Ctrl-Z, kill, kill -9, kill -15, Ctrl-C
c. kill -9, kill -15, Ctrl-C, Ctrl-Z
d. Ctrl-C, Ctrl-\, kill, kill -9

3. What is a daemon?
/'
U d p/dt5dB $M A& ,y P &¿&J

4 3 C/C s/J/PM?Y
O Copyright IBM Corporation 2005

Figure 10-19. Checkpoint LX024.0

Notes:

O Copyright IBM Corp. 2001,2005 Unit 10. Working with Processes 10-23
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Unit Summary
All processes are started by a "parent" process (except for init,
which is started by the kernel)
Every process is identified with a Process ldentifier (PID)
A special process is the shell, which can interpret user commands
Processes can terminate by themselves, or upon reception of a
signal
Signals can be sent by the shell, using a keyboard sequence, or by
the kill and killall commands
Processes are started with equal priority, but this can be changed
using the nice and renice commands
A daemon is a background process that typically controls a system
resource or offers a network service

O Copyright IBM Corporation 2005

Figure 10-20. Unit Surnmary

Notes:

10-24 Linux Power User O Copyright lBM Corp. 2001,2005


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

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

O Copyright IBM Corp. 2001,2005 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

Unit Objectives
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

O Copyright IBM Corporation 2005

Figure 11 -1. Unit Objectives

Notes:

11-2 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

The find Command


Search one or more directory structures for files that meet certain
specified criteria
Display the names of matching files or execute commands against
those files

Syntax:
$ find path expression

O Copyright IBM Corporation 2005

Figure 11-2. The find Command LX024.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 < f r m where <search for> <do smething t o it>

O Copyright IBM Corp. 2001,2005 Unit 11. Linux Utilities 11-3


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

Sample Directory Structure

blues
phone
phonel
phone2

blue box big


brown circle giant
green phone little
square small
O Copyright IBM Corporation 2005

Figure 11 -3. Sample Directory Structure

Notes:

11-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

Using find
Generally, you want to search a directory structure for files with
certain names and list the names found.

$ cd /home/joe
$ find .
-name phone
./shape/phone
./phone
On many other UNlX systems, with find you have to tell
it specifically to print the names using -print
$ find .
-name phone -print
./shape/phone
./phone

O Copyright IBM Corporatmn 2005

Figure 11 -4. Using find LX024.0

Notes:
Note that the directory search is recursive meaning that find searches the current directory
and al1 the subdirectories underneath it.
If not specified otherwise, the find command matches both directories and files.
The examples on the foil search for al1 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 UNlX versions that have not yet implemented the POSlX standard for the find
command, the -print option is required for the result to be displayed or used in a pipe.

O Copyright IBM Corp. 2001,2005 Unit 11. Linux Utilities 11-5


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

Executing Commands with find


The -exec option executes a command on each of the file names
found.

$ find .
-name l b * ' -exec 1s - i O \;
187787 ./color/blue
187788 . / c o l o r / b r o w n
187792 . / s h a p e / b o x
202083./size b i g
132754 . / b l u e s

" { ) " is a placeholder for each filename. The backslash


escapes the following semicolon.

O Copyright IBM Corporation 2005

Figure 11 -5. Executing Commands with find LX024.0

Notes:
The command following the -exec option, in this case the Is command, is executed for
each file name found. find replaces the {) with the names of the files matched. {) ic 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 lb*' -exec 1s - 1 E ) \;
is equivalent to
$ find . -name lb*' -1s

11-6 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

lnteractive Command Execution


The -ok option also causes command execution but on an

$ f ind . -name b\* -ok rm #

{3 \;
< rm ... ./color/blue > ? y
< rm ... ./color/brown > 3 y

O Copyright IBM Corporation 2005

Figure 11-6. lnteractive Command Execution LX024.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.

O Copyright IBM Corp. 2001,2005 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

/*
Additional find Options G/ i l nc

- type f ordinary file


d directory
- size +n larger than n blocks
-n smaller than n blocks
nc equal to n characters
modified more than x days ago
modified less than x days ago
modified x days ago
- perm onum access permissions match onum
mode access permissions match mode
-user user finds files owned by user
- newer ref.f ile file was modified more recently
than ref.file
-o Logical OR
-a Logical AND
O Copyright IBM Corporation 2005

Figure 11 -7. Additional find Options LX024.0

Notes:
There are many other options to the find command, which are listed in the on-line
manuals.
Some options of find are:
Allow searches for only files or only directories.
Search for files that exactly match a size (-size lo), that are
more than a size (-size + l o ) or that are below a certain size
(-size -10). Size values are expressed in blocks.
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.
Search for files that have a certain permission mask (isee
chmod).
-newer Search for files that are newer than the reference file.

11-8 Linux Power User O Copyright IBM Corp. 2001,2005


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

Allow multiple conditions to be matched (find a or b).


Require multiple conditions to be matched (find a and b).

O Copyright IBM Corp. 2001,2005 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

find Examples

$ find .
-perm 777
./size/little

File matches expr 1 aad expr 2:


$ find .
-name 'S*' -type f - a -size +2\
>-exec 1s - i I } \;
187791 ./shape/square
202086 ./size/small

File matches expr 1 or expr 2:


$ find .
-name big -0 -name Ic*' -
.
/color
./shape/circle
./size/big

O Copyright IBM Corporation 2005

Figure 11 -8. find Examples LX024.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 Is -i command is
executed on them.
The second example finds al1 the files (files and directories) that have their permissions set
as 777 and were modified more than four days ago.
The third example shows you both files and directories that have big as a name clr whose
name starts with a c.
The last example shows you al1 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 O Copyright IBM Corp. 2001,2005


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

locate Command
locate allows you to quickly find a file on the system, based on
simple criteria

$ locate passwd
/usr/share/man/manl/passwd.l.gz
/usr/share/man/man5/passwd.5.gz
/etc/passwd
/usr/bin/passwd

Requires that the superuser runs updatedb regularly


- Most distributions run updatedb automatically
- SuSE does not install locatelupdatedb by default

O Copyright IBM Corporation 2005

Figure 11-9. locate Command LX024.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.

O Copyright IBM Corp. 2001,2005 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

The cut Command


Pull selected columns or fields from one or more files.
Syntax:
cut - f (ields) -d(elimiter) f ile ( S )
cut - c(haracters) f ile (S)

O Copyright IBM Corporation 2005

Figure 11-10. The cut Command LX024.0

Notes:
The cut command is used to pul1 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 c:olumns.
The second syntax is used when the number of columns is not equal for each line.

11-12 Linux Power User O Copyright IBM Corp. 2001,2005


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

cut Example (1 of 2)

$ cat /etc/passwd
root:x:O:O:Big ~rother:/root:/bin/bash
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
tuxl:x:500:500::/home/tuxl:/bin/bash
tux2:x:501:501::/home/tux2:/bin/bash
J
ac\~@,t. - A6
$ cut -f1,6,7 -d: /etc/passwd
root:/root:/bin/bash
shutdown:/sbin:/sbin/shutdown
tuxl:/home/tuxl:/bin/bash
tux2:/home/tux2:/bin/bash

O Copyright IBM Corporation 2005


--

Figure 11-11. cut Example (1 of 2) LX024.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.

The output would be:


-
What would be the output of the following command:
$ cut -fl -do /etc/passwd?
~&,\-\-\cd?~c '' O"

This syntax can only be used correctly if the file is divided into columns that are separated
with a special delimiter character.

O Copyright IBM Corp. 2001,2005 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 Nofebook

cut Example (2 of 2)

$ PS
PID TTY STAT TIME COMMAND
374 PO S 0:00 -bash
460 PO R 0:OO ps

$ ps 1 cut -c-5,20-
PID COMMAND
374 -bash
471 ps

O Copyright IBM Corporation 2005

Figure 11 -1 2. cut Example (2 of 2) LX024.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 betweeri 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 1 c u t - f 5 - d H ",we would get this as output: s t a t
In order to overcome this problem we cannot use the syntax that defines columns with
delimiters. lnstead we have to tell cut what characters we want to see.
ps 1 c u t - c - 5 , 2 0 - tells the cut command only to display the characters specified;
characters 1 to 5 and characters 20 and further.

11-14 Linux Power User O Copyright IBM Corp. 2001,2005


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

The grep Command


Searches one or more files or standard input for lines matching
pattern

Simple match or Regular Expression

Syntax
grep [options] pattern [filel ...1

O Copyright IBM Corporation 2005

Figure 11 -13. The grep Command LX024.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.

O Copyright IBM Corp. 2001,2005 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

grep Sample Data Files


Phone 1:

Allet 10300 intern


Judith 20500 intern
Kees 30500 extern
Leo 40599 extern
Nannie 50599 extern
Peter 60300 intern

Phone 2:
Allet 1342 intern
Judith 2083 intern
Kees 3139 extern
Leo 4200 intern
Nannie 5200 intern
Peter 6342 extern
O Copyright IBM Corporation 2005

Figure 11 -1 4. grep Sample Data Files LX024.0

Notes:
This foil shows the sample files used to illustrate the examples that follows.

11-16 Linux Power User Q Copyright IBM Corp. 2001,2005


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

$ grep 20 phonel
Judi th 20500 intern

$ grep 20 phone*
phone1:Judith 20500 intern
phone2 :Judi th 2083 intern
phone2:Leo 4200 intern
phone2:Nannie 5200 intern
$ grep - v Judith phone2
Allet 1342 intern
Kees 3139 extern
Leo 4200 intern
Nannie 5200 intern
Peter 6342 ext ern

O Copyright IBM Corporation 2005

Figure 11-1 5. Basic grep LX024.0

Notes:
grep searches for the string given. If not specified otherwise, grep does 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.

O Copyright IBM Corp. 2001,2005 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

grep with Regular Expressions


Patterns with metacharacters should be in single quotes (' ') so that
the shell will leave it alone.

Valid metacharacters with grep: $ . * A [ ] -


Any single character
* Zero or more occurrences o£ the
preceding character
[ a - £] Any ONE o£ the characters in the
range a through f
Aa Any line that starts with a
z$ Any line that ends with z

O Copyright IBM Corporation 2005

Figure 11-16. grep with Regular Expressions LX024.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 matches zero
or more occurrences of the previous character. If you want to use it to match zerol 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 1 grep lnterpretation


I
1 shell 1 shell lnterpretation
I I
A 1 begins a line
I I
A
1 "old" bourne pipe symboll-4
I

1$ 1 ends a line 1$ 1 variable 1


any single character ? any single character
* any number of any characters * any number of any
[-1 single character range 1-1 single character range

11-18 Linux Power User O Copyright IBM Corp. 2001,2005


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

Regular Expression

1. Display al1 the processes that belong to tuxl

Using grep, write commands to select the following lines


from the phonel file:
2. Select al1 the lines of the file (blank and non-blank)

greP phonel

3. Select al1 the lines that contain an e and end in a O

phone 1

O Copyright IBM Corporation 2005

Figure 11-1 7. Regular Expression LX024.0

Notes:
Answers:
1. To display al1 processes running on the system that belong to ~UX,I enter:
$ p s aux 1 grep tuxl

2. Select al1 the lines of the file (blank and non-blank), enter:
$ grep l . * ' phonel
3. Select al1 the lines that contain an e and end in a 0, enter:
$ grep I e . * O $ l phonel

O Copyright IBM Corp. 2001,2005 Unit 11. Linux Utilities 11-19


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

-V Print lines that do not match


-c Print only a count of matching lines
Print only the names of the files with matching lines
-n Number the matching lines
Ignore the case of letters when making comparisons
Do a whole word search
-f <f iie> Read expressions from file instead of command line

O Copyright IBM Corporation 2005

Figure 11 -18. grep Options LX024.0

Notes:
grep supports various useful options. The most important ones are listed in the visual.
Obviously, these options can be combined. One of the most useful options is the -v option
in combination with the -f option. This is typically used in logfile analysis: Logfiles are
usually full of routine messages, and by putting these routine messages in an "ignore file"
you can filter your actual log file, discarding al1 routine messages, and displaying only the
interesting messages, with this single command:
grep -v - f ignorefile l o g f i l e
Another useful trick is to do a full-text search over a large number of files, displaying the
name of the file that matches automatically:
grep - 1 searchstring ' f i n d $HOME --e "*.t~t~~'

11-20 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Other greps
fgrep allows only fixed strings (no regular expressions)
e egrep allows for multiple (alternate) patterns

$ egrep '20500)40599(505991phonel
Judi th 20500 intern
Leo 40599extern
Nannie 50599extern

What does the following command do?

$ grep 30 phonel 1 grep intern


????????

O Copyright IBM Corporation 2005

Figure 11-1 9. Other greps LX024.0

Notes:
egrep is slightly slower than normal grep because it allows you to "or" patterns together
using the "1". To match al1 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 al1 lines in phonel that contain both the
string 30 and the string intern.
With a pipe from one grep to another, you can define an and-construct.

O Copyright IBM Corp. 2001,2005 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

The sort Command


The sort command sorts the lines in the file specified and writes the
result to standard output.

sort -t(delimiter) +field -0ptions file

$ cat animals
dog - 2

$ sort animals
cat.4
dog .2
penguin.10

O Copyright IBM Corporation 2005

Figure 11 -20. The sort Command LX024.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 O Copyright IBM Corp. 2001,2005


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

sort Examples
$ sort +0.1 animals
cat .4
penguin. 10
dag .2
$ sort -t. +1 animals
penguin.10
dog .2
cat.4
$ sort -t. - n +1 animals
dog .2
cat .4
penguin.10

Options:
- d sorts in dictionary order. Only letters, digits and spaces are
considered in comparisons
- r reverses the order of the specified sort
- n sorts numeric fields in arithmetic value
O Copyright IBM Corporatin 2005

Figure 11 -21. sort Examples LX024.0

Notes:
$ sort animals sorts the file animals on the first character of each line.
$ sort +0.1 animals forces 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 always tries to perform an ASCll sort.
$ sort -t. -n +1 animals performs a numeric sort on the second (+1) column.

O Copyright IBM Corp. 2001,2005 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

The head and tail Commands


The head command can be used to view the first few lines of a file
or files. The command syntax is:
$ head [ - l i n e s ] fi l e ( s )

$ head - 5 myfile
$ 1s - 1 1 head -12

The tail command displays the last few lines of a file or files. The
command syntax is:
$ tail [ ( - lines 1 +lines 1 - f 3 1 f ile (S)

$ tail -20 file


$ tail +20 file
$ tail -f file 1
O Copyright IBM Corporation 2005

Figure 11-22. The head and tail Commands LX024.0

Notes:
The head command shows 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 lndicates the number of lines to read beginning from the end of
the file. This displays 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 O Copyriglit IBM Corp. 2001,2005


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

displays 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.

O Copyright IBM Corp. 2001,2005 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

The type, which and whereis Commands


To find out what the path to a command ¡S, use type

$ type find echo


find is /usr/bin/find
echo is a shell builtin

To find out where the binary is located, use whieh

$ which find echo


/usr/bin/find
/bin/echo

To locate the binary, source and manual page files of a command,


use whereis

$ whereis find echo


find: /usr/bin/find /usr/man/manl/find.l
echo: /bin/echo /usr/man/manl/echo.l

O Copyright IBM Corporation 2005

Figure 11-23. The type, which and whereis Commands LX024.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 gfour
search path and runs the first one it finds. You can find out which copy of the proyram 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 also displays 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 O Copyright IBM Corp. 2001,2005


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

executable in /bin. The problem is that when you issue the echo command the built-in is
run and not the executable in /bin.

O Copyright IBM Corp. 2001,2005 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

The file Command


With the file command, you can find out what the type of data in the
file ¡s.

$ file /etc/passwd /bin/ls /home/peter /tmp/fake.jpg


/etc/passwd: ASCII text
/bin/ls: ELF 32-bit LSB executable, Intel 80386,
version 1, dynamically linked, stripped
/home/peter: directory
/tmp/fake.jpg: PDF document, version 1.3

O Copyright IBM Corporation 2005

Figure 11 -24.The file Command LX024.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 deterrriine what
kind of binary file it is and what operating system version it was compiled under.
The file command uses the /usrlsharelmagic 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:
$ f ile 'which comrnand'

11-28 Linux Power User O Copyright IBM Corp. 2001,2005


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

The gzip, gunzip and zcat Commands


To compress or uncompress files use gzip, gunzip or zcat

$ 1s - 1 filel
- m - m - r -- 1 teamOl teamOl 32031 Apr 6 23:40 filel
$ gzip - v filel
filel: 89.9% - - replaced with file1.g~
$ 1s - 1 file1.g~
- m - m - r - 1 teamOl t e a 0 1 3265 Apr 6 23:40 file1.g~
$ zcat filel
(output is the same as the output o£ the cat command with
the uncompressed file)
$ gunzip filel
$ 1s - 1 filel
-1w-17w-r- 1 teamOl teamOl 32031 Apr 6 23:40 filel

O Copyright IBM Corporation 2005

Figure 11 -25. The gzip, gunzip, and zcat Commands LX024.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.

O Copyright IBM Corp. 2001,2005 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 O Copyright IBM Corp. 2001,2005


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

The join and paste Commands


join and paste combine files

$ cat one
a apple another
b bee beast
$ cat two
a ape
b broken
$ join one two
a apple another ape
b bee beast broken
$ paste one two
a apple another a ape
b bee beast b broken

O Copyright 1BM Corporation 2005

Figure 11-26. The join and paste Commands LX024.0

Notes:
The join and paste commands allow you to merge files together. They're never used,
except for the most complicated shell scripts.

O Copyright IBM Corp. 2001,2005 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

Checkpoint
TIF 1. The command ps -aux 1 grep tux 1 grep netscape
lists al1 Netscape processes of a user named tux. F
2. Which command would best be used to locate al1 files
in your system that begin with the string "team"?
a. find / -name "9eam"
b. find / -name "team*"
C. find 1 -name "*team*"
d. find 1 -type f -name "team"

3. Translate the following command into your native


language:
Is -IR 1 egrep "txt$ltab$"I sort -rn +4 1 tail +4 1 head -5

Q Copyright IBM Corporation 2005

Figure 11 -27. Checkpoint

Notes:

11-32 Linux Power User O Copyright IBM Corp. 2001,2005


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

Unit Summary
The following commands were considered:
The find command is used to recursively search directories for files
with particular characteristics
The grep command is used to select entire lines containing a
particular pattern
The head and tail commands are used to view specific lines in a file
The sort command sorts the contents of a file by the options
specified
Find out where you can find commands with type, where and
whereis
The gzip, zcat and gunzip commands can be used to create and
work with compressed files

O Copyright IBM Corporation 2005

Figure 11 -28. Unit Sumrnary

Notes:

O Copyright IBM Corp. 2001,2005 Unit 11. Linux Utilities 11-33


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

11-34 Linux Power User O Copyright IBM Corp. 2001,2005


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

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:
lnvoke shell scripts in three separate ways and explain the
difference
Pass positional parameters to shell scripts and use them within
scripts
lmplement interactive shell scripts
Use conditional execution and loops
Perform simple arithmetic

How You Will Check Your Progress


Accountability :
Checkpoint questions
Exercises

O Copyright IBM Corp. 2001,2005 Unit 12. Shell Scripting 12-1


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Unit Objectives
After completing this unit, you should be able to:
lnvoke shell scripts in three separate ways and explain the
difference
Pass positional parameters to shell scripts and use them within
scripts
lmplement interactive shell scripts
Use conditional execution and loops
Perform simple arithmetic

O Copyright IBM Corporation 2005

Figure 14-1. Unit Objectives LX024.0

Notes:

12-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

What Is a Shell Script?


A shell script is a collection of commands stored in a text file.

$ pwd
$ date
$ 1s - 1

$ cat scriptl
pwd
date
1s - 1
$

O Copyright IBM Corporation 2005

Figure 12-2. What Is a Shell Script? LX024.0

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.

O Copyright IBM Corp. 2001,2005 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

lnvoking Shell Scripts (1 of 3)


The script does not have to be marked executable but must be
readable.
bash invokes a script in a child shell.

$ cat scriptl
date
$ bash s c r i p t l

Start of subshell

1 Running a command from scriptl

O Copyright IBM Corporation 2005

Figure 12-3. lnvoking Shell Scripts ( 1 of 3) LX024.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 script name 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 are not propagated to the initial shell.

12-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

lnvoking Shell Scripts (2 of 3)


Use the chmad command to make the script executable.
Then run the script as if it were a command.
The script is run in a child shell.

$ chmod 7 5 5 ./scriptl
$ ./scriptl

Start of subshell

t Running a command from scriptl


-bash &
7 bash

1
f date
............................
........................................................ ...............--.

1
O Copyright IBM Corporation 2005

Figure 12-4. lnvoking Shell Scripts (2 of 3) LX024.0

Notes:
The second method of invoking a shell script is by making it executable with chmod. This
allows you to cal1 the script directly. As with the first method, the script is executed in a
subshell and thus any changes to environment variables are not 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 script name. If the script is not in your $PATH, then you have to invoke
it with its relative or absolute pathname.

O Copyright IBM Corp. 2001,2005 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

lnvoking Shell Scripts (3 of 3)


.
Use the (dot) or source command to execute the script in your
current shell environment
Scripts executed with the dot command can change your current
environment

$ .
scriptl
$ source s c r i p t l

the date command is invoked


by your current shell

O Copyright IBM Corporation 2005

Figure 12-5. lnvoking Shell Scripts (3 of 3) LX024.0

Notes:
The third method is by invoking the script using the . (dot) or source command. 111 this
case, the script is executed in the current shell. This means that the script is able to make
changes to environment variables in the current shell.

12-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

lnvoking Shell Scripts in Another Shell


To make sure the shell script always runs in the shell where it was
intended for (sh, bash, csh), use the following on the first line of
your script:
#!/bin/bash
The script now always runs in bash - even if the users default shell
is something else
With this, the . (dot) or source invocation is no longer possible

O Copyright IBM Corporatmn 2005

Figure 12-6. lnvoking Shell Scripts in Another Sheil LX024.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 cure that the script is always invoked in a bash
shell. This is done by adding the following line on top:

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 Ibinlbash.
The same magic marker can also be used to identify perl scripts ('#!/usr/bin/perll), awk
scripts ('#!/usr/bin/awkl) and so forth.
There is one disadvantage: a shell script which starts like this is always 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.

O Copyright IBM Corp. 2001,2005 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

Typical Shell Script Contents


Handling of shell script arguments
Complex Redirection
Conditional Execution
Repeated Execution
User lnterfacing
Arithmetic

O Copyright IBM Corporation 2005

Figure 12-7. Typical Shell Script Contents LX024.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 O Copyright IBM Corp. 2001,2005


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

Shell Script Arguments


Parameters can be passed to shell scripts as arguments on the
command line
These arguments are stored in special shell variables
$1, $2, $3 ... refer to each of the arguments
$@ is "$1" "$2" "$3"
$* is "$1 $2 $3"
$# is the number of parameters

$ cat ascript
#!/bin/bash
echo First parameter: $1
echo Second parameter: $2
echo Number o£ parameters: $ #
$ ascript two one
First parameter: two
Second parameter: one
Number o£ parameters: 2

O Copyright IBM Corporation 2005

Figure 12-8. Shell Script Arguments LX024.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 ${lo).
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 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 ..."

O Copyright IBM Corp. 2001,2005 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 O Copyright IBM Corp. 2001,2005


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

Complex Redirection
To redirect fixed text into a command use << END

$ cat << END > cities


Ams terdam
Ro tterdam
1
END

To avoid large argument lists use xargs


$ rm *.txt
-bash: /bin/rm: Argument list too long
$ find .
-name '*.txtu@ 1 xargs rm

- Avoids large argument lists by running the command multiple


times, if necessary

O Copyright IBM Corporation 2005

Figure 12-9. Complex Redirection LX024.0

Notes:
In the previous units we've already seen redirection using >, >> and c.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 cc 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:
Ams terdam
Rotterdam
"END" is the delimiter string. It is not 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 '1s *.txtCwould 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,

O Copyright IBM Corp. 2001,2005 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 Nofebook

xargs has a large number of options that determine how the final command(s) are actually
formatted. For more information, see its manual page.

12-12 Linux Power User O Copyright IBM Corp. 2001,2005


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

Conditional Execution
The return code from a command or group of commands can be
used to determine whether to start the next command.

O Copyright IBM Corporation 2005

Figure 12-10. Conditional Execution LX024.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 11 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.

O Copyright I B M Corp. 2001,2005 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

The test Command (1 of 2)


The test command allows you to test for a given condition.
Syntax:
test expression o : [ expression ]

$ test - f myfile.txt 1
1 $ echo $1

Expressions to test file status:


- f <f i l e > file is an ordinary file
- d <file> file is a directory
-r <fiXe> file is readable
- w <file> file is writable
-x <fiLe> file is executable
- S <f lle> file has non-zero length
O Copyright IBM Corporation 2005

Figure 12-11. The test Command (1 of 2) LX024.0

Notes:
The test command can be invoked in two ways:
test expression
[ expression 1
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 O Copyright IBM Corp. 2001,2005


Course materials may not be reproduced in whole or in part
without the prior written perrnission of IBM.
iSt~dentNotebook

The test Command (2 of 2)


String tests:
- n <string> string is not empty
- z <string> string is empty
cstring> == <string> strings are equal
<string> ! - <string> strings are not equal

Arithmetic tests:
<value> -eq -=vahe> equals
<value> - n e <value> not equal
<value> -It <valuer less than
<value> - l e -=-vahe> less than or equal
<vaJue> -gt <value> greater than
<value> - g e <vahe> greater than or equal

O Copyright IBM Corporation 2005

Figure 12-12. The test Command (2 of 2) LX024.0

Notes:
The visual lists some more examples of test expressions. Remember that iri each and
every case the return value of the test command ($?) is set to O if the test is positive, and 1
if the test is negative.
Another thing to remember is to surround al1 your variables you use in a test expression
with double quotes. As an example, consider what would happen with the following
command:
test $VAR == " t e s t H
If $VAR is not empty, then the test is carried out and the return code is set to O 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:
t e s t == 'Itestu

This statement is obviously incorrect, since the == operator needs two argurnents, and
receives only one. In this case, test gives you a syntax error, and a return code of 2.
This could easily be prevented by using the following syntax:

O Copyright IBM Corp. 2001,2005 Unit 12. ShelW Scripting 12-15


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

test ll$VAR1l == lltestll


Now, if $VAR is empty or not defined, the statement is changed into:
test == "test"

This is a legal syntax. Obviously the return code is 1.

12-16 Linux Power User O Copyright IBM Corp. 2001,2005


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

The && and 11 commands


&& and 11 (2 vertical bars) can be used to conditionally execute a
single command:

commandl
a&&d command2
if (commandl successful) then do (command2)
lo(
commandl 1 1 command2
if (commandl not successful) then do (command2)

$ [ -f testfile 1 && m testfile


$ [ - f lockfile 1 1 ) touch lockfile
$ [ l1$TERMI1= l l x t e m v1l && echo This is no tty
$ cat doesnotexist 2>/dev/null 1 1 echo \
> 'Oh boy, this file does not exist.I1

O Copyright IBM Corporatin 2005

Figure 12-13. The && and 11 Commands LX024.0

Notes:
The first way of conditionally executing commands is by using the && and 11 operators.
These operators allow a single command to be executed, depending on the return code of
another single command.

O Copyright IBM Corp. 2001,2005 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

The if Command
The structure of the basic if statement is:
if statement is true
then
c a r r y out t h i s s e t of a c t i o n s
else
c a r r y out t h i s set of a c t i o n s

$ cat myscript
if [ II $MY-VALUEB1 - eq 10 1
then
echo MY-VALUE contains the value 10
else
echo MY-VALUE is not 10
fi
$

O Copyright IBM Corporation2005

Figure 12-14. The if Command LX024.0

Notes:
The if then else f i 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.

is the same as
if ccirrniandl
then
command2
fi
but the if statement is usually more readable, especially if there are a lot of comniands to
be executed.

12-18 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in p?rt
without the prior written perrnission of IBM.
Student Notebook

Command Repetition
A "loop" is a set of commands that is executed over and over
- Until or while a certain condition is true
- Or for each item from a list

if <conditiori> is true,
repeat this set of
commands

if <conditiori> is false,
leave this set of
commands

O Copyright IBM Corporation 2005

Figure 12-15. Command Repetition LX024.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

O Copyright IBM Corp. 2001,2005 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

The for Command


The structure the for loop ¡S:

Eor i d e n t i f i e r in l i s t
do
command (S) to be executed on $identifier
done

$ c a t my-forloop
f o r f i l e i n /tmp/mine-*
do
cp $ f i l e / o t h e r d i r / $ f i l e
done

O Copyright IBM Corporation 2005

Figure 12-17. The for Command LX024.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 Itmp directory.
Other examples are:
for fruit in Apple Pear Banana
do
echo 1 would like a $fruit
done
and
for file in 'find / h m e -perm 777'
do
echo Dangerous File Permissions on $ f i l e
done

O Copyright IBM Corp. 2001,2005 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

Shifting Shell Script Arguments


If you expect a large number of shell arguments (for example,
filenames), use the shift command in a while loop to handle them
all.

list of arguments: argl arg2 arg3 arg4 arg5 (count)


Variables: $1 $2 $3 $4 $5 $# = 5
after first loop: del. $1 $2 $3 $4 $# = 4
after second loop: del. del. $1 $2 $3 $# = 3

$ cat make-backup
while [ $ # -gt O 1
do
cp $1 $l.bak
shift-?\.,\ric. mr\\ario , brtir$nJ~\c
done

O Copyright IBM Corporation 2005

Figure 12-18. Shifting Shell Script Arguments LX024.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:
f o r f i l e i n $@
do
cp $ f i l e $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 O Copyright IBM Corp. 2001,2005


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

$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 tt-ie 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.

O Copyright IBM Corp. 2001,2005 Unit 12. ShelW Scripting 12-23


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

User Interaction: The read Command


The read command reads one line from stdin and assigns the
values read to a variable.

$ cat delfile
#!/bin/bash
#Usage delfile
echo Please enter the file name:
read name
if [ -f $name 1
then
rm $name
else
echo $name is not an ordinary file -
echo so it is not removed
fi

O Copyright IBM Corporation 2005

Figure 12-19. User Interaction: The read Cornmand LX024.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 riame
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 al1 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 O Copyright lBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
!Student Notebook

Arithmetic
The bash shell can perform simple arithmetic on integers using the
builtin let command or the $(( expr )) notation
Operators: *, 1, +, -, %

$ l e t x=2+3
$ echo $x
5
$ echo $ ( ( 2+3 11
5
$ l e t x=3* (3+5)
$ echo $x
24
$ l e t x=3*3+5
echo $x
14
$ x=$(( 3 * ( 3 + 5 1 11

O Copyright IBM Corporation 2005

Figure 12-20. Arithmetic LX024.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 $(O) notation only works on integers and is limitecl by certain
bounds, because it uses a "signed long int" variable type for interna1 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 2 3 1 - 1 or 2 6 3 - 1 .
The operators that can be used are:
*, for multiplications
1, for division (results are rounded down to the nearest integer)
+, for addition
-, for subtraction
%, for the remainder of a division
( and ), for argument grouping

O Copyright IBM Corp. 2001,2005 Unit 12. Shell Scripting 12-25


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Notebook

According to the POSlX standard, arithmetic is done before wildcard expansion aiid
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 showri that not
al1 versions of bash correctly implement this. If you want to be safe, make sure you
surround your expression with double quotes.
Also, make cure that any shell variables you use indeed contain integers: they should only
contain the digits 0-9.

12-26 Linux Power User O Copyright IBM Corp. 2001,2005


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

The expr Command


If your shell does not support S(()) or let, then use the expr
command for integer arithmetic
Not a shell builtin, so about 10 times slower
Same operators as let

$ echo -expr 3 + 5 -
1
Beware of the shell metacharacters *, ( and )!

$expr3* ( 3 + 5 )
bash: syntax error near unexpected token ' ( '
$ expr 3 \ * \ ( 3 + 5 \ )
24

O Copyright IBM Corporation 2005

Figure 12-21. The expr Comrnand LX024.0

Notes:
Not al1 shells support the built-in let command or the $(( )) notation. In that case, you 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.

O Copyright IBM Corp. 2001,2005 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

Command Search Order

w command

O Copyright IBM Corporation 2005

Figure 12-22. Cornrnand Search Order LX024.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 O Copyright IBM Corp. 2001,2005


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
!?tudentNotebook

Checkpoint (1 of 2)

1. What will the following piece of code do?


TERMTYPE=$TERM
if [ - n I1$TERMTYPE1l]
then
if [ - f /home/teamOl/custom~script 1
then

echo No custom script available!

else
echo You donlt have a TERM variable set!

O Copyright IBM Corporation 2005

Figure 12-23. Checkpoint (1 of 2) LX024.0

Notes:

O Copyright IBM Corp. 2001,2005 Unit 12. Shell Scripting 12-29


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

Checkpoint (2 of 2)
2. Write a script that will multiply any two numbers together.

O Copyright IBM Corporation 2005

Figure 12-24. Checkpoint (2 of 2) LX024.0

Notes:

12-30 Linux Power User O Copyright IBM Corp. 2001,2005


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

Unit Summarv
Positional Parameters are used to pass to scripts the values of
variable
To test for a particular condition the test command can be used.
This feature is frequently coupled with the if statement to control the
flow of a program and allow for conditional execution within scripts
The read command can be used to implement interactive scripts
The while and for commands are used to create loops in a script

O Copyright IBM Corporatin 2005

Figure 12-25. Unit Surnmary LX024.0

Notes:

O Copyright IBM Corp. 2001,2005 Unit 12. Shell Scripting 12-31


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

12-32 Linux Power User O Copyright IBM Corp. 2001,2005


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

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 Environmenfts
Switch between GNOME and KDE

How You Will Check Your Progress


Accountability:
Checkpoint questions
Machine exercises

O Copyright IBM Corp. 2001,2005 Unit 13. The Linux GUI 13-1
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Unit Objectives
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

O Copyright IBM Corporation 2005

Figure 13-1. Unit Objectives LX024.0

Notes:

13-2 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials may not be reproduced in whole or in part
without the prior written perrnission of IBM.
:Student Notebook

The Linux Graphical User Interface


The "X Window System" is the GUI of Linux
- Developed at MIT in 1984
- Current standards body: X Consortium
- Shortname: X
X uses client-server model with network connections
- Highly flexible
- Easy exchange of components
- Supports networked applications and sessions, independent of
the OS

O Copyright IBM Corporation 2005

Figure 13-2. The Linux Graphical User Interface LX024.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 UNlX system was using commands in an ASCll environment.
In 1987, a group of vendors and researchers formed the X-Consortium to coritinue 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 X11 R6.
Linux doesn't use the original X Window System but an implementation called XFree86.
X is an open standard which heavily uses standard TCPIIP network connections. This
makes it ideal in a mixed UNIXILinux 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.

O Copyright IBM Corp. 2001,2005 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

ClientlServer Architecture

1 X Window System Server


I

' 1 1 Application 1 1 1 ~p~lication 1


O Copyright IBM Corporation 2005

Figure 13-3. Client/Sewer Architecture LX024.0

The X Window System uses a clientlserver architecture, which makes it very flexible. The
central piece of software is the X Server. The X Server traps al1 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 O Copyright IBM Corp. 2001,2005


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

X Components
An X Server
- Controls keyboard, mouse and one or more screens
- Controls resolution, refresh rate and color depth
- Allows simultaneous access by several clients
- Performs basic graphic operations
- Forwards keyboard and mouse events to the correct clients
An X Client
- Is for instance an application
- Receives keyboard and mouse inputs from server
- Sends output to be displayed to server
A Window Manager
- Is a special X Client
- Performs "windows dressing" on other clients
- Allows other client windows to be moved, iconified and so forth

O Copyright IBM Corporation 2005

Figure 13-4. X Components LX024.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, al1 keyboard and mouse events are received and forwarded
to the appropriate X clients (X clients identify to the server al1 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 is sent al1
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 itc own window,
but displays the borders around other windows, and thus ensures that windows can be
resized, moved and iconified.

O Copyright IBM Corp. 2001,2005 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
barsl, launchers2, pagers3 and so forth.

' A task bar is an area which shows al1 applications that'are currently running.
A launcher allows you to start other applications, usually by using come sort of menu structure andlor start button.
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 al1 desktops. This allows you to work with multiple windows easily.

13-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

X Servers in Linux
Most distributions use XFree86 (www.xfree86.org) as their X Server
- Open Source
- Supports most video adapters
Other X Servers for Linux are available as well
- Metro-X (http://www.metrolink.com)
- Xi Graphics (http://www.xig.com)
- ...

O Copyright IBM Corporatmn 2005

Figure 13-5.X Servers in Linux LX024.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 rriost important
of which are Metro-X and Xi Graphics.

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.

O Copyright IBM Corp. 2001,2005 Unit 13. The Linux GUI 13-7
Course rnaterials may not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

XFree86 Configuration
XFree86 needs to be configured for your hardware
- Keyboard
- Mouse
- Graphical adapter
- Monitor
Things to configure: refresh rate, resolution, color depth
Config file: letcIX1llXF86Config
Manual configuration possible, but hard
- See XFree86-HOWTO for details
Automated configuration tools available:
- During installation of distribution
- XFree86 tools: xf86config, X -configure
- Distribution tools: redhat-config-xfree86 (Red Hat and Fedora),
sax21yast2 (SuSE)

O Copyright IBM Corporation 2005

Figure 13-6. XFree86 Configuration LX024.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 é, c and 8)
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 110 use.
These values are al1 limited by the capabilities of your hardware.

13-8 Linux Power User O Copyright IBM Corp. 2001,2005


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

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 are 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 generates flicker, and causes headaches in the long run. For
continued use, a refresh rate of 60 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 goes down.
The last consideration is the resolution itself. By having more pixels on the screen, each
pixel is 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 are.
As you can see, configuring color depth, refresh rate and resolution for your c:ombination 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
(letclX11IXF86Config or IetclX11lXF86Config-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 and Fedora)
sax, sax2 (tools supplied by SUSE)
And there may well be others.

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.
One Hertz (Hz) means "one per second".

O Copyright IBM Corp. 2001,2005 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

Desktop Environments
A Desktop Environment is:
- A set of tools, libraries and standards that allows rapid
development of X clients
- A set of X clients (including one or more window managers) that
are developed with these tools, libraries and standards
Examples:
- GNOME (GNU Network Object Model Environment)
- KDE (K Desktop Environment)
Advantages of Desktop Environments
- lntegration (cut and paste via clipboard, drag and drop)
- Common look (themes)

O Copyright IBM Corporation 2005

Figure 13-7. Desktop Environrnents LX024.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 KDIE.
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 have the same look and feel. In most cases, this culrriinates 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, is
used by any client from that desktop environment.

13-10 Linux Power User O Copyright IBM Corp. 2001,2005


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

The K Desktop Environment (KDE)

q n with the technological t u p a r u g of t

KDE 1s an hternet prqcct that 1s Ir* opm in evsry saisa Dtvelopmait takes place m the lntwnet and ir
a5cused on OUI msj(img lidf. USENETnew3 g r o w , Md IRC channela to whih we inwte and wlcomr

WE is a mahire desktop iute p o w i w asolid baso to m ever growing number of wplic&iolif a Unin
wakrtationr KDE has bveloped a high qMity dwsbpment framewmk f m Unix. whch dlovr foi t k rapid
and e f l c M t crcatrin of applicationr

Tbr fint b d P d KMfire 1.2 u mmw avsilabk. Rekased on 26th 2ü32, KOffice-l 2 Betal offers m a y
nou features and ~mprovemnl~, and c e r t a l l a few bugr l o be f o v d and repated.

KDE 3.0 Rslcusd!


ai b&d 3rd m 2 , thc KDE Prolect released KDE 3 0,the md-Generatiion of the Leading Dsrktop f a
LiwxlUNIX, Offeriq Entsrpriwl, Govermntr. S c M . md Busines$esa Outstaarg Frce wd Open
Dtsktop Solutm A dmqd.g has b n n m& avalable R e d m m m thc -cmint

I m c c 1.1.1 R c k w d !
UI Deeen*xr 17th. 2W1, the KDE Projsct ideased KOffne 1 1 1, an update to KOffre I 1 KOffre 1s afree,
qien Sovce, n t q a t e d office sute b m s t r a t n g t k richxos and poww of the KDE c l e v w m n t
envlronment me M I siniunamemi c m t m s Iinks to the source md biniuy paskaaes a3 w d as a@ ded
of informatim abaut the currmt features of thc Küífce p a c h c s msre V1 dso a Ed d chuwr Mth
ct to i
h prs-i vasion of KOffw

Figure 13-8.The K Desktop Environment (KDE) LX024.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 aiutomatically
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 al1 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 see a number of other buttons, which start various often-used programs.
The second area shows the virtual desktops that are currently configurecl. 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 locks your screen, and
the exit button logs you out.

O Copyright IBM Corp. 2001,2005 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 O Copyright IBM Corp. 2001,2005


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

The GNOME Desktop Environment

Figure 13-9.The GNOME Desktop Environment LX024.0

Notes:
The visual shows a screenshot of a GNOME (GNU Object Modeling Environrnent) desktop,
again taken from a Red Hat system. As you can see, the basic functionality is not al1 that
different.

O Copyright IBM Corp. 2001,2005 Unit 13. The Linux GUI 13-13
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Notebook

Starting X
If logged in on a text terminal, run startx
- Only starts a single session
- When session ends, you are back in your text terminal
If you want to enable the graphical login screen, bring the system
into runlevel 5
- To switch manually use init 5 command
- To make change permanent, edit Ietclinittab:
id:5:initdefault:

O Copyright IBM Corporation 2005

Figure 13-10. Starting X LX024.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 al1 other
applications that make up your desktop.
The second way is by switching to runlevel 5'.
Switching to runlevel 5 can be achieved with the command init 5, and can be configured as
default runlevel by editing the file tetctinittab: Find the line that currently says

and change it to

' 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 O Copyright IBM Corp. 2001,2005


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

When your system reboots, it starts in runlevel 5 automatically.


In runlevel 5, a so-called "display manager" is started. This program (depending on your
settings this is xdm, kdm or gdm) displays a graphical login prompt. When a user logs on,
it subsequently starts the favorite window manager of that user, just as with startx.

O Copyright IBM Corp. 2001,2005 Unit 13. The Linux GUI 13-15
Course rnaterials rnay not be reproduced in whole or in par1
without the prior written perrnission of IBM.
Student Notebook

Choosing Your Desktop Environment


Most distributions provide multiple desktop environments
To choose between them, select from the Login prompt
Every user can have hislher own preference

O Copyright IBM Corporation 2005

Figure 13-11. Choosing your Desktop Environment LX024.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 is stored and is listed as your preferred choice
next time you log in.

13-16 Linux Power User O Copyright IBM Corp. 2001,2005


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

Checkpoint
TIF 1. The main configuration file of KDE is
letclX11lXF86Config
2. What statement describes the function of the
X server best?
a. It receives input from the keyboard and mouse and
forwards this to the appropriate client, and it receives
output from the clients and displays this on the screen.
b. It performs the "window dressing": It makes sure that
every application has a border around its windows so
that the window can be resized, moved and iconified.
c. It allows the user to type commands while in a
graphical environment.
d. It shows a set of eyes looking at the cursor.
3. How do you start X?

O Copyright IBM Corporation 2005

Figure 13-12, Checkpoint

Notes:

O Copyright IBM Corp. 2001,2005 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

Unit Summary
The GUI of Linux is based on the X Window System (X for short)
X uses a client-server model
The most common X server under Linux is XFree86
A Desktop Environment is a set of tools, libraries and standards
that allow development of X clients, and a set of X clients developed
with this
The most common Desktop Environments on Linux are KDE and
GNOME
To switch between Desktop Environments, use the pull-down menu
from the graphical login prompt

O Copyright IBM Corporation 2005

Figure 13-13. Unit Summary

Notes:

13-18 Linux Power User O Copyright IBM Corp. 2001,2005


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

Unit 14. Customizing the User Environment


What This Unit Is About
This unit demonstrates how a user's environment can bcs 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 GUI

How You Will Check Your Progress


Checkpoint questions
Exercises

O Copyright IBM Corp. 2001,2005 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

Unit Objectives
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 GUI

O Copyright IBM Corporation 2005

Figure 14-1. Unit Objectives

Notes:

14-2 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
jitudent Notebook

Bash lnitialization (Login Shell)


1 Ietclprofile
$HOMEl.bash-profile
-oro $HOME/.bash login
-oro$ ~ ~ ~ ~ / . ~ r % f i l e

$HOMEl.bash-logout
O Copyright IBM Corporation 2005

Figure 14-2. Bash lnitialization (Login Shell) LX024.0

Notes:
The first file that shell uses at login is Ietclprofile.This file contains variables specifying the
basic environment for al1 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 $HOMEI.bash_profile. This file serves the same pwrpose as
Ietclprofile but this file can be changed by the user. If it is not found, $HOME/.bash-login
is used, and if that file is not found, $HOME/.profile is used.
Ensure that newly created variables do not inadvertently conflict with standard variables
such as MAIL, PS1, PS2, and so forth.

O Copyright IBM Corp. 2001,2005 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

Bash lnitialization (non-Login Shell)

O Copyright IBM Corporation 2005

Figure 14-3. Bash lnitialization (non-LoginShell) LX024.0

Notes:
When a shell is started, but not as a login shell, Ietclprofile and -1.bashjrofile 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 O Copyright IBM Corp. 2001,2005


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

Bash lnitialization with Red Hat Extencions

$HOME/.bash-profile
$HOME/.bashrc
export BASH-ENV=$HOME/.bashrc
letclbashrc

$HOME/.bash-logout
O Copyright IBM Corporation 2005

Figure 14-4. Bash lnitializationwith Red Hat Extensions LX024.0

Notes:
On a Red Hat system, a number of extra files are called when a user starts bash.
First, Ietclprofile 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, $BASHENV is set to $HOME/.bashrc. This erisures 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 letclbashrc. This ensures that global optioris 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:

O Copyright IBM Corp. 2001,2005 Unit 14. Customizing the User Environment 14-5
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission 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 O Copyright IBM Corp. 2001,2005


Course materials may not be reproduced in whole or in par1
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 O Copyright IBM Corp. 2001,2005


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

KDE Customization

O Copyright IBM Corporat~on2005

Figure 14-6. KDE Customization LX024.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.

O Copyright IBM Corp. 2001,2005 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

GNOME Customization

Accessibility Advanced Background Font


i tfsm 7.lt3I.ill
," 7 m

Keyboard Keybacld ~enus&~oatbars Mouse

Neiwork proxy Screensa~er Sound Tkeme

m
Windaws

O Copyright IBM Corporation 2005

Figure 14-7. GNOME Customization LX024.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 O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Checkpoint

1. Which file would you use to customize your environment


variables and why this file?

2. What do the following variables define on your system?


PATH, PS1

0 Copyright IBM Corporation 2005

Figure 14-8. Checkpoint

Notes:
Write down your answers here:

O Copyright IBM Corp. 2001,2005 Unit 14. Customizing the User Environment 14-11
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Notebook

Unit Summary
A number of shell scripts allow you to customize your shell
environment
Both KDE and GNOME have an integrated "control center" for
customization

O Copyright IBM Corporation 2005

Figure 14-9. Unit Sumrnary

Notes:

14-12 Linux Power User O Copyright IBM Corp. 2001,2005


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

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
lnstall and deinstall additional software
Configure a printer
Configure a sound card
Configure a network adapter

How You Will Check Your Progress


Accountability :
Checkpoint questions
Machine exercises

O Copyright IBM Corp. 2001,2005 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

Unit Objectives
After completing this unit, you should be able to:
Discuss System Management tools
lnstall and deinstall additional software
Configure a printer
Configure a sound card
Configure a network adapter

O Copyright IBM Corporation 2005

Figure 15-1. Unit Objectives LX024.0

Notes:

15-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

Why System Configuration


Most system configuration is done during installation
Might need to change system configuration afterwards:
- Things not configured during installation
- Configuration failed during installation
- Environment changed after installation
Three ways to change system configuration
- Temporary - until next system reboot
- Manually - changing config files by hand
- Automated - using system administration tools
Typical items to be configured on a workstation:
- Addlremove software
- Printers
- Sound Cards
- Network

O Copyright IBM Corporatin 2005

Figure 15-2. Why System Configuration LX024.0

Notes:
In most distributions, a "workstation" install takes care of configuring most of your system.
In fact, in al1 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 configurcition to your
Linux workstation:
Certain things were not be configured during the installation. This might ble because the
distribution manufacturer left that component out altogether, or that you clecided to skip
that part of the installation process.
The attempted configuration of a certain thing failed. This typically happens to sound
cards: 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.

O Copyright IBM Corp. 2001,2005 Unit 15. Basic System Corifiguration 15-3
Course rnaterials rnay 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 nwmber 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 makirig 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 al1 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 al1 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 al1 configuration options that the programmer has built into the service.
A Linux system is highly configurable and supports a lot of cervices and hardware. In this
unit, we're only going to look at four of the most common system administration tasks that
you encounter on a typical workstation:
Adding and removing software
Configuring printers
Configuring sound cards
Configuring network adapters

15-4 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written permission of IBM.
!Student Notebook

System Configuration Tools


Various tools have been developed to ease system administration
- Application specific (Samba SWAT, ...)
- Distribution specific (system-config-*, SuSE yast, ...)
- Desktop Environment specific (gmenu, kcantral, ...)
- Generic LinuxIUNIX (webmin, ...)
The "perfect" tool
does not exist (yet?)

O Copyrkght IBM Corporation 2005

Figure 15-3.System Configuration Tools LX024.0

Notes:
One of the main disadvantages of Linux as compared to commercial UNlXes as AIX, for
instance, is that there is no single, large manufacturer behind it who can force al1
developers to work according to a single standard. This is particularly visible lwhen 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 al1 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 UNlX configuration tools.
The perfect tool however does not exist. Now what "perfect" is, is in the eyeis of the
beholder, but al1 of the tools that present themselves as generic still suffer oine major
deficiency (as of now): They currently do not motivate the author of a program to also write

O Copyright IBM Corp. 2001,2005 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 always lags behind, increases the chanc:e 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 sliould
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 owm
distribution specific tools, and some applications have their own tools as well. This means
that you 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 O Copyright IBM Corp. 2001,2005


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

AddinglRemoving Software Using RPM


Use rpm to insta11 or upgrade software packages
Common options:
-i : installing new packages
-U : upgrading existing packages
-e : removing packages
" StJ
I ,:O :l
ri\
[h+b7' .> &e

/
$ rpm -ihv myprog-1.2-34.i386.rpm
myprog ######k##w
4 & f ~ b
.... \ .
~ajrQ
pfcy.c d+
$ rpm -Uhv myprog-1.2-78.i386.rpm

The -h options shows a progress bar

O Copyright IBM Corporation 2005

Figure 15-4. AddinglRemoving Software Using RPM LX024.0

Notes:
Most distributions in the market today distribute their software in "RPM" format'. RPM,
which stands for "RPM Package ~ a n a ~ e r *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, corifiguration files
and other files.
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.
* 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.

O Copyright IBM Corp. 2001,2005 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, al1 these components are automatically compressed.
When an PRM package (afile which generally ends with ".rpmW)is installed, the information
about it goes into a database on disk (usually /var/lib/rpm). This makes it possible to
retrieve al1 information about al1 installed packages ~vithouthaving 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 only cover the most common
things:
lnstalling 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 O Copyright IBM Corp. 2001,2005


Course rnaterials may not be reproduced in whole or in part
without the prior written perrnission of IBM.
:Student Notebook

Querying the RPM Database


Options:
-i : list information
-1 : list al1 files
-p: queries new packages before installing
L / p ty
/ ~v al 4 hcrori e,!

1
I

# rpm -qi myprog


Name : myprog Relocations: (not relocatable)
Version : 1.0.1 Vendor: IBM Inc.

# rpm -qi myprog

# r p m -qlp yourprog-1.0-23.i386.rpm
/usr/bin/foo
/etc/foorc
/usr/share/man/manl/foo.l.gz
O Copyright IBM Corporation 2005

Figure 15-5. Querying the RPM Database LX024.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 show~sup. Adding
the -i option gives you al1 information about a package, while adding the -1 option gives you
al1 the files that are part of this package. To query al1 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: cpackagename-<version>.rpm. Also note that some distributions (for
example, SUSE) do not include the version number in the package filename.

O Copyright IBM Corp. 2001,2005 Unit 15. Basic System Corifiguration 15-9
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

AddinglRemoving Software from a .tar.gz File


.tar.gz (.tgz): default distribution format for source code
- tar = "tape archiver": stores a directory tree in a single file
- gz = "GNU Zip": compression program
To unpack a .tar.gz or .tgz archive:
cd /usr/src
tar -zxvf archive-versi0n.tar.g~
cd <archivename>
Read INSTALL or README file for installation instructions
Should be installed under /usr/local

O Copyright IBM Corporation 2005

Figure 15-6. AddingIRemoving Software from a .tar.gz File LX024.0

Notes:
The default distribution format for source code in the Linux community (and to a large
extent, the UNlX 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
al1 of this in one run. The default location to perform this operation is /usr/src. The archive
itself usually creates its own subdirectory (/usr/src/<archive-version>) and stores al1 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 O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
iSt~dentNotebook

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 al1 installed files by hand.

O Copyright IBM Corp. 2001,2005 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

Printer Configuration
On Red Hat, Fedora and SuSE, the printer subsystem is CUPS
(Common UNlX Printing System)

Configuration done through lpadmin or with a browser


(http://hostname:631/) (recommended!)
O Copyright IBM Corporation 2005

Figure 15-7. Printer Configuration LX024.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 UNlX 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 Ipadmin
to configure CUPS, or point your browser to http:ll<hostname>:631.This gives you an

15-12 Linux Power User O Copyright IBM Corp. 2001,2005


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

HTTP-interface to the cupsd daemon and is by far the easiest method of co~nfiguring
CUPS.
Once configured, you can submit print jobs to CUPS by using the Ip commaiid (derived
from and compatible with AT&T1sSystem V printing subsystem) or the Ipr command
(derived from and compatible with BSD's printing subsystem). Graphical applications are
typically compatible with kdeprint, which means that they cal1 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 Ipq: These commands show you the jobs queued to be printeid.
lpcancel and Iprm: These commands allow you to cancel a print job.

O Copyright IBM Corp. 2001,2005 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

Sound Card Configuration


Configuration usually done with dedicated tool
Red Hat, Fedora: system-config-soamndeard
SuSE: yastt2 or alsaconf

...checks your

modules s. coa
Sound Card support requires correct loading of
kernel modules!
O Copyright IBM Corporation 2005

Figure 15-8. Sound Card Configuration LX024.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
sound card 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 system-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.

Pieces of code that can be loaded into the kernel while the system is running to provide support for one specific hardware component.
This file used to be called /etc/conf.modules.
- -

15-14 Linux Power User O Copyright IBM Corp. 2001,2005


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

Network Configuration
Need correct network module to be loaded into kernel
- 1etclmodules.conf
Need to set correct IP addresses etc.
- Generally done with ifconfig command
- For DHCP, use dhcpcd, pump or dhclient
Configuration done through scripts which are different in eaeh
distribution
- Red Hat, Fedora: letclsysconfiglnetwork-scriptslifcfg-ethO
-SuSE: letclsysconfiglnetworWifcfg-ethO
Use distribution specific tool to configure
- Red Hat, Fedora: system-config-network
- SuSE: yast

O Copyright IBM Corporation 2005

Figure 15-9. Network Configuration LX024.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 al1 these parameters locally.
Instead, you need to start a DHCP client which requests al1 parameters from a DHCP

O Copyright IBM Corp. 2001,2005 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 severa1 DHCP clients for Linux. The one most often used
today is dhclient.
For automated configuration of your network in Red Hat Linux, start
system-config-network. For SUSE, use yast.

15-16 Linux Power User O Copyright IBM Corp. 2001,2005


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

Checkpoint
TIF 1. When you configure your system as a DHCP
client, you don't need to configure IP addresses
and so forth yourselves.

2. The correct command to install an additional RPM


would be:
a. rpm -i xpuzzles.rpm
b. rpm -e xpuzzles-5.5.2-4.i386.rpm
c. rpm -qip xpuzzles.rpm
d. rpm -i xpuzzles-5.5.2-4.i386.rpm

3. What is the proper series of commands to install a


.tar.gz file?

O Copyright IBM Corporation 2005

Figure 15-10. Checkpoint LX024.0

Notes:

O Copyright IBM Corp. 2001,2005 Unit 15. Basic System Configuration 15-17
Course materials rnay not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Unit Summarv
System configuration is necessary if the installation program did or
could not configure your system, or if your environment changetl
after installation
System administration can be temporary, manual or automatic
System administration is being made easy by system administration
tools
The perfect system administration tool does not yet exist
You have to find out which tools are available on your distribution,
and which tool works for you
Common things to do on a workstation are: adding and removing
software, configuring printers, configuring sound cards and
configuring network interfaces

O Copyright IBM Corporation 2005

Figure 15-11 . Unit Summary LX024.0

Notes:

15-18 Linux Power User O Copyright IBM Corp. 2001,2005


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

Unit 16. Connecting to the lnternet


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 settimgs of a Linux
workstation.

What You Should Be Able to Do


After completing this unit, you should be able to:
Connect to the lnternet using a regular modem and an ISDN
adapter
Describe how to connect to the lnternet when using broadband
connection (cable or xDSL)
Describe the security issues involved in connecting to the lnternet
Apply reasonable security measures

How You Will Check Your Progress


Accountability:
Checkpoint questions
Exercises

O Copyright IBM Corp. 2001,2005 Unit 16. Connecting to the lnternet 16-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Unit Objectives
After completing this unit, you should be able to:
Connect to the lnternet using a regular modem and an ISDN
adapter
Describe how to connect to the lnternet when using a broadband
connection (cable or xDSL)
Describe the security issues involved in connecting to the lnternet
Apply reasonable security measures

O Copyright IBM Corporation 2005

Figure 16-1. Unit Objectives

Notes:

16-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

Connectina to the lnternet


Connecting to the lnternet = Establishing a channel which allows
you to send IP packets to your ISP and vice versa
Four most common connection types:
- Regular modem connection
- ISDN connection
- Cable modem connection
- xDSL connection
Connection types differ in:
- Cost (one-time, fixed and variable)
- Bandwidth, Latency
-Availability
- Additional features such as fixed IP addresses

O Copyright IBM Corporation2005

Figure 16-2. Connecting to the lnternet LX024.0

Notes:
Most users 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 lnternet Service Provider
(ISP) and vice versa. And since the ISP's network is part of the Internet, this in fact leads to
an "lnternet 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 ~ b ~ sand
' , that in most areas around the world you
need to pay the telephone company (telco) a certain amount of money per second that
' Kilobits (1024 bits) per second, so about 5 Kilobytes (1024 bytes) per second.
O Copyright IBM Corp. 2001,2005 Unit 16. Connecting to the lnternet 16-3
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

you're connected. (In the US, with most subscriptions, local calls are free or orily cost a
fixed amount per call, no matter how long the cal1 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 c:ompany.
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 fa11 outside the
scope of this course.
Al1 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, eq~uipment
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.

xDSL is the generic abbreviation for a range of techniques, including ADSL, HDSL, SDSL and so forth. For home and srnall office use,
ADSL (Asymmetrical Digital Subscriber Line) is the most common variant. Its download speed is typically about two to eight times higher
than its upload speed, because most home users and small offices download more from the lnternet than that they uplo~ad.Hence the
asymmetry.

16-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

Modem Connections
Use an analog telephone line to establish a digital data connection
(MOdulation/DEModulation)
PPP is used for IP packet encapsulation between your PC and the
lSPs router

Internet

Built-in or ISP modem

0 Copyright IBM Corporation 2005

F i g u r e 16-3. M o d e m C o n n e c t i o n s LX024.0

Notes:
A regular modem connection is the most common way of connecting to the Unternet. 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 paekets over this
connection, you need to encapsulate them. This is done using the PPP protocol.

O Copyright IBM Corp. 2001,2005 Unit 16. Connecting to the lnternet 16-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Modem Connections in Linux


External modems have device names IdevlttySn
-COMA = ttySO, COM2 = ttyS1
Interna1 modems usually emulate a serial port - nothing special
- Winmodems require a software driver which is usually only
available under Windows (with a few exceptions)
To setup connection, need to invoke pppd
- Best done using a graphical frontend such as kppp

O Copyr'ght IBM Corporation 2005

Figure 16-4. Modem Connections in Linux LX024.0

Notes:
In Linux, modems are identified using their device name. For the modem connect:edto the
first serial port (COMI), the device name is 1 d e v / t t ~ ~COM2
0 ~ , is /dev/ttySl, and so forth.
If you have an interna1 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 externa1 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 lBlVl
(MWave modem).

Note the capital S. A lowercase S means something entirely different here.

16-6 Linux Power User O Copyright IBM Corp. 2001,2005


C O U ~materials
S~ may not be reproduced in whole or in par!
without the prior written permission of IBM.
Student Notebook

Connecting to the lnternet 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.

O Copyright IBM Corp. 2001,2005 Unit 16. Connecting to the lnternet 16-7
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

ISDN Principles
ISDN = lntegrated Services Digital Network
- Provides a 100% digital network
- Popular in Europe
Most popular variant for home use is ISDN-2
- 2 channels, 64 Kbps each
One ISDN-2 connection can have up to eight Multiple Subscriber
Numbers (MSN)

Linux workstation ISP routei

A
lnternet
3
O Copyright IBM Corporation 2005

Figure 16-5. ISDN Principies LX024.0

Notes:
ISDN (Integrated Services Digital Network) provides a 100% digital network, whic:h 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-24, this gives you
two outside lines and a maximum of eight telephone numbers (called Multiple Subscriber
Numbers or MSNS~). Each outside line or "channel" is capable of transporting 64 Kbps,
bidirectional. Channels can be used individually (placing two phone calls simultan~eouslyor
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.
ISDN-2 is also called Basic Rate lnterface (BRI). The ISDN variant for srnall cornpanies is ISDN-30, which is also callecl Prirnary Rate
lnterface (PRI). As the name suggests, this gives you 30 outside lines to use.
In Gerrnan-speakingcountries, the abbreviation EAZ is used instead, which stands for Endgerate Auswahl Ziffer.

16-8 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

ISDN in Linux
Linux implements pseudo-tty's which accept regular modem
commands to set up ISDN connections
- IdevlttylO through Idevlttyl63
-Can be used just like a modem in your lnternet dialer
- Need a special AT command to configure MSN:
AT&E0123456789
Applications can also access the ISDN adapter directly
- Requires an ISDN-capable dialer such as isdntonfig
- Supports channel bundling
- Automatically configures MSN
More documentation:
-
/usrlsrc/linuxlDocumentation

O Copyright IBM Corporation

Figure 16-6. ISDN in Linux LX024.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/ttylO through / d e ~ / t t ~ 1 6 accept
3 ~ ) regular AT commands as an
analog modem would, and can therefore be used as a regular modem in your lnternet
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 c;ommands
screen of your lnternet 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 lnternet 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.

tee-tee-why-capital ai-zero, not tee-tee-why-el-zero!

O Copyright IBM Corp. 2001,2005 Unit 16. Connecting to the lnternet 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/linuxlDocumentation.

16-10 Linux Power User O Copyright IBM Corp. 2001,2005


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

Cable Modems Principles


Cable modems use available, but unused frequency ranges in the
cable TV network
Typical bandwidth: 30 Mbps shared
Connecting requires a "cable modem"

Linux workstation
with built-in
ethernet ada~ter DHCP
ISP server I
Cable
modem
jppjsGT&-E-g
"L
O Copyright IBM Corporation 2005

Figure 16-7. Cable Modem Principies LX024.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 system7. 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.
Some solutions do not require an ethernet adapter in your system, but use USB. Because of the restricted bandwidth available over
USB, you want to avoid this.

O Copyright IBM Corp. 2001,2005 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 lSPs either. (It might be that your cable TV provider contracted this
work out to a "real" ISP, but the principie stays the same.)

16-12 Linux Power User O Copyright IBM Corp. 2001,2005


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

xDSL Principles
Generic name for utilizing additional bandwidth in "local loop" of
telephone network
Various implementations: ADSL, HDSL, SDSL, ...
Bandwidth is dependent on implementation, phone line quality and
distance
Connecting requires a splitter or filters, and an xDSL modem

Linux workstation

O Copyright IBM Corporation 2005

Figure 16-8. xDSL Principles LX024.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 Presente".
These techniques al1 allow you to use your existing telephone cable as a data carrier, in
addition to allowing you to place regular telephone calls over it8. 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 ethernetg, and the telco
connects its xDSL modem to its network. This allows IP communications.

This is possible because a telephone cal1 only uses the frequency range up to 4 KHz, while the cable itself is able to transport much
higher frequencies.
Again, some solutions do not use an ethernet adapter but use USE instead. Because of the limited bandwidth of USB you want to
avoid this.

O Copyright IBM Corp. 2001,2005 Unit 16. Connecting to the lnternet 16-13
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Cable and xDSL in Linux


Most cable and xDSL modems connect to your Linux PC via a small
Ethernet network, and bridgelroute traffic into the lSPs network
Other connection types are possible too, but less common: USB,
serial, wireless (not covered here)
Configure your ethernet adapter as directed by the ISP
- Static IP address
- DHCP

O Copyright IBM Corporation 2005

Figure 16-9. Cable Modems in Linux LX024.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 O Copyright IBM Corp. 2001,2005


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

lnternet Security
Being conneGted to the Internet ís a security risk
- Especially with an "always on" connection (cable, xDSL...)
Every workstation needs basic security measures
- Good passwords
- No unneeded services running
- Latest versions of al1 services that are running
To determine network services that are running:

# netstat -anutp

To disable unneeded services:

# chkconfig <SERVICE> off


1
Never start your browser as root!
Never log in to your system as root (unless needed)!
-
O Copyright IBM Corporation 2005

Figure 16-10. lnternet Security LX024.0

Notes:
When connected to the Internet, especially when you are connected via a high-bandwidth,
always-on connection with a UNlX 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.

O Copyright IBM Corp. 2001,2005 Unit 16. Connecting to the lnternet 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 intolO.
On a Linux workstation, there is no reason to run any network service at al1 (we're! not
talking about sewers 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 al1 ports that the system is currently listening on (meaning that a
service is running on that port), and al1 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, y o i ~can run
the fuser -n tcp <portnumber> or fuser -n udp <portnumber> command, which gives
you the PID of the process that opened the port. You then need to use ps to find out the
process name.
Second, stop al1 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 Ar~h~itecture).
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.

'O 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 O Copyright IBM Corp. 2001,2005


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

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.
Series of scripts that perform low-level initialization of hardware
on a SuSE system. These scripts should generally not be
disabled.
chargen: Network service that generates characters via TCP (port 19).
Should be disabled.
chargen-udp: Network sewice that generates characters via UDP (port 19).
Should be disabled.
crond: Main scheduling daemon in Linux. Should not be disabled.
cups: Daemon for the Common UNlX Printing System. Needed if you
want to use a printer, even if the printer you're using is
connected to a network instead of a local port.
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 al1 characters back that are sent to
it via TCP (port 7). Used to test network functions. Should be
disabled.
echo-udp: Network sewice that echoes al1 characters back that are sent to
it via UDP (port 7). Used to test network functions. Should be
disabled.
esound: A multiplexing and caching sound daemon. Used by many
applications that produce sound. Should generally be enabled,
unless you do not run any applications that produce sound.
fbset: Service that can query and change console frame buffer
settings, allowing you to display more than the standard 80x25
characters on a text virtual terminal. Also, in some situations,
your X server uses frame buffers to display graphics.
If your X server doesn't use frame buffers, and if you're not
interested in text virtual terminals, you can safely disable this.

O Copyright IBM Corp. 2001,2005 Unit 16. Connecting to the lnternet 16-17
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

finger: Network service that gives other users information ovcsr the
users on this system. Should be disabled.
firstboot: Script that runs the first time a system boots after installation,
and configures a few things that could not be handled by the
installation program itself, such as sound, user accouiits and
registration. This service disables itself once it has ruri.
gpm: Daemon that allows you to use your mouse in a text c.onsole
(Alt-F1 through Alt-F6). Can be disabled if you don't use it, but
does not open any network ports.
hotplug: Service that handles the removal/insertion of various
hot-pluggable devices, except PCMCIA. Should be enabled if
you use these hot-pluggable devices, such as USB, FireWire or
CardBus.
hwscan: SuSE service responsible for detecting new hardware added to
the system. Can be disabled if you don't add new hartjware to
your system, or configure your hardware manually after adding
it to the system.
identd: Network service that allows others to verify your identity (TCP
port 113). Should be disabled in general, but is someti~mes
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.
iptables: Service that starts the iptables firewall scripts. Enable this only
if you use iptables rules. iptables and ipchains are rnutually
exclusive: only enable one of these, but not both.
irda: Daemon for support of Infrared. Only needed if you have
devices that communicate with your system through Irifrared.
irqbalance Kernel routine that balances IRQ request over CPUs i f you
have a multiprocessor system. Best to leave this running, even
on a single-CPU system.
isdn: Service that loads ISDN kernel modules and configures ISDN
devices. Only enable this if you have an ISDN adapter.
joystick: Daemon that manages joysticks. Can be disabled if you don't
have these.
kdcrotate: Daemon that rotates the list of KDCs (Kerberos Domain
Controllers) in a Kerberos-controlled environment. Only needed
if you use Kerberos for authentication.
kbdlkeytable: Service that loads the correct keyboard mapping file at startup.
Only required if you have a non-US keyboard.

16-18 Linux Power User O Copyright IBM Corp. 2001,2005


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

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.
ksysguardd: KDE daemon that can guard your system from attacks by
remote computers. Can usually be disabled.
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: FedoraIRed 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 tiardware
manually after adding it to the system.
lirc: Daemon that supports sending and receiving lnfrared signals of
the most common IR remote controls. Can be disabled if you
don't use IR on your system.
lisa Small daemon which is intended to run on end user systems. It
provides something like a "network neighborhood", but only
relying on the TCPIIP protocol stack. Only needed if you want
to let your users see a sort of network neighborhood when they
open their file browser.
Ipd: Printer spool daemon. Should not be disabled unless you don't
print on this system.
messagebus: Daemon that implements a system for sending messages
between applications. Can usually be disabled, unless you are
running these applications.
mdadmd: Daemon that manages md (Software RAID) devices, and is
intended as a replacement for the mdtools and raidtools. Only
useful if you have Software RAID devices and are not satisfied
with the default tools to manage these.
microcode-ctl : Service that updates the microcode on lntel CPUs. Can usually
be disabled unless you need to run an updated microcode on
your CPU.
netfs: Service that performs network mounts (via NFS or SMB). Can
be disabled if you don't define remote filesystems or shares in
Ietclfstab.
network: Service that configures low-level networking. Should not be
disabled.
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.

O Copyright IBM Corp. 2001,2005 Unit 16. Connecting to the lnternet 16-19
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

nfslock: Network daemon (RPC service; see portmap) that needs to run
both on an NFS client and sewer to support the NFS protocol.
Generally not needed on a workstation, unless you are an NFS
client or server.
nscd: Name Sewice Caching Daemon: Caches DNS requests on a
workstation. This can improve performance for applications that
do a lot of DNS queries, particularly NIS. You can leavfethis
running safely if you think/feel/know that it improves
performance in your situation.
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 systenn.
openct: Service that allows you to talk to smart card readers. Can be
disabled if you don't use smart cards on your system.
pcscd Provides a WinSCard interface to communicate with srnart card
readers. Can be disabled if you don't use smart cards on your
system.
pcmcia: Service that starts the cardctl daemon, which handles al1
PCMCIA device removals/inserts. You need this
service/daemon if you want to use PCMCIA devices.
portmap: Network daemon (TCP and UDP port 111) that is needed for al1
RPC-based services, such as NFS and NIS. Do not enable
portmap unless you need one of the cervices nfs, nfslock,
ypbind, or ypserv.
postfix: Network daemon (TCP port 25) which handles incomiiig 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.
ptal Daemon that allows you to print to and scan from HP OfficeJet
All-ln-One printers. Only needed if you have these pririters.
radvd: Network daemon that advertised routes on IPv6. Do not enable
this service unless you're on an IPv6 network.
random: Service that saves the random state when the system halts,
and rectores 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.
resmgr: Daemon that provides user access to raw devices, such as CD
burners. Only needed if you want to provide users witti this
capability.

16-20 Linux Power User O Copyright IBM Corp. 2001,2005


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

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.
rpasswdd : Daemon that allows secure remote password updates.
Generally not required on a workstation.
rpmconf igcheck: Script that scans for unresolved .rpmnew, .rpmorig and
.rpmsave files, and alerts the user to their existence. Only
needed if you do automatic upgrades of RPMs.
These files are the result of RPM upgrades, when RPM cannot
figure out what to do with a particular configuration file. It is up
to the user to make al1 necessary configuration changes, and
subsequently delete these files.
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.
saslauthd: Daemon that implements the SASL (Simple Authentication and
Security Layer) protocol: a protocol that can add authentication
support to arbitrary connection-based protocols. You need this
daemon only if you use SASL-based authentication.
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.
setserial: Service that configures serial ports. Only needed if you use
serial devices (such as serial mice or modems) and the
program you're using cannot configure the serial port itself.
sgi-fam: Network daemon (RPC service; see portmap) that is used to
monitor file changes. Can be disabled.
smartd: Self Monitoring and Reporting Technology (SMAHT) daemon:
tracks reports from hardware devices (for example, hard disks)
that report errors.
Samba daemon startup scripts. Samba allows Windows
systems to access your filesystems and printers by emulating a
Windows server. Only needed if you want to give Windows
clients access to your files andlor printers.

O Copyright IBM Corp. 2001,2005 Unit 16. Connecting to the lnternet 16-21
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Notebook

smpppd: SuSE Meta PPP Daemon: backend for kinternet. Reqiuired for
modem, ISDN and DSL connections on a SuSE system.
snmpd and snmptrapd: Network daemons (TCP and UDP ports 161 and 162) 1:hat allow
remote management of this system via the SNMP protocol.
Disable unless your systems need to be remotely mariaged.
splash-*: Services that display splash screens at various stagec of the
boot process. Not required, but look nice.
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 almlost every
server runs it so that the administrator can do remote
administration.
SuSEfirewall2 SuSE script that configures iptables for you. Use only if you
want to use iptables-style firewalling.
syslog: Service that allows logging of events to /var/log/messages and
a few other files. Should be enabled at al1 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 disalbled.
vncserver Daemon that makes it possible to display the output 0.f a
locally-running X server remotely (with a client tool vncviewer).
Can generally be disabled unless you use VNC.
winbind: Daemon that is part of the Samba suite of applications. Enable
this only if you're running a Samba server and need winbind
capability.
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 systerri in
graphical mode (runlevel 5) but also allows remote logins, if
configured incorrectly. If you want to login in graphical mode,
then this service should be running, but make sure it olnly
listens to the loopback interface. This can be seen with the
command netstat -a.
Fedora and Red Hat use xdm/kdm/gdm as well, but do not start
it through a System V init script. Instead, they start it directly
from /etc/inittab.

16-22 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

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.
xntpd: 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.
ypbind: Network daemon (RPC service; see portmap) which is used on
a NIS client to bind to an NIS server. Not needed on a
workstation, unless you are part of an NIS domain.
yum: Fedora utility that checks for and can automatically download
and install updated RPM packages. Enable this service only if
you want to use yum to keep your system up to date.
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 TCPIIP protocol suite
however, and that is outside the scope of this courseii.

l 1 The "Linux Network Administration II: Network Security and Firewalls" course (course code LX24) covers this iri great detail.

O Copyright IBM Corp. 2001,2005 Unit 16. Connecting to the lnternet 16-23
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Checkpoint

TIF 1. Linux-based systems are more secure than


Microsoft-based systems. You therefore don't
have to worry about security when connecting
to the Internet.

2. Which of the following connection methods generally


does NOT involve PPP?
a. Regular modems
b. ISDN connections
c. Cable or xDSL

3. What is the device name of serial port COM2?

O Copyright IBM Corporation 2005

Figure 16-11. Checkpoint LX024.0

Notes:

16-24 Linux Power User O Copyright IBM Corp. 2001,2005


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

Unit Summary
There are four ways of connecting to the Internet:
- Regular modem
- ISDN connections
- Cable modems
- xDSL
Regular modems and ISDN connections are best configured using
kppp or other graphical dialers
Cable and xDSL connections are typically configured as regular
ethernet cards
The best network security on a Linux workstation is not to run any
network services at al1

O Copyright IBM Corporation 2005

Figure 16-12. Unit Summary LX024.0

Notes:

O Copyright IBM Corp. 2001,2005 Unit 16. Connecting to the lnternet 16-25
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Notebook

16-26 Linux Power User O Copyright IBM Corp. 2001,2005


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

Unit 17. lntegrating Linux in a Windows


Environment

What This Unit Is About


This unit gives 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

O Copyright IBM Corp. 2001,2005 Unit 17. lntegrating Linux in a Windows Environment 17-1
Course materials rnay not be reproduced in whole or in part
without the prior written permission of IBM.
Sfudent Notebook

Unit Objectives
After completing this unit, you should be able to:
Access files on Windows filesystems
Run Windows programs
Access Windows servers
Read Windows document formats

O Copyright IBM Corporation 2005

Figure 17-1 . Unit Objectives

Notes:

17-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

Accessing Files on Windows Filesystems


Linux: Unified Filesystem
- Virtual directory tree
- Al1 physical filesystems are
"mounted"

WWL-J
bin nib lshare lX11R lkde lgnome letc fln luxl flux2 flux3 11~x4

Windows: Drive Letters for


each separate filesystem

O Copyright IBM Corporation 2005

Figure 17-2. Accessing Files on Windows Filesystems LX024.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 has to be read both by Windows and
by Linux. Since Windows can't handle Linux partitions, this data is 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 al1
FAT-based filesystems, and supports Access Control Lists (ACLs).

O Copyright IBM Corp. 2001,2005 Unit 17. lntegrating 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 al1 IDE and SCSl disks, followed by al1 logical partitions on al1 IDE
and SCSl 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 Imntlfloppy, 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 O Copyright IBM Corp. 2001,2005


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

Mounting Windows Filesystems


To mount the first primary partition on your first IDE hard disk on the
mount point lmntlwin95:

# mount /dev/hdal /mnt/win95


.. .or
# mount - t vfat /dev/hdal /mnt/win95

All files on your C:-disk are now accessible in lmntlwin95


Make permanent by adding this to letclfstab:

/dev/hda5 / ext2 defaults 1 1


/dev/hda2 /boot ext2 defaults 1 2
/dev/hda6 swap swap defaults O O
/dev/hdal /mnt/win95 vfat defaults O O

O Copyright IBM Corporation 2005

Figure 17-3. Mounting Windows Filesystems LX024.0

Notes:
Since the Linux kernel supports virtually al1 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 Ietclfstab file.
Note: Not al1 distributions include read-only support for the NTFS filesystem..This
particularly applies to Red Hat and Fedora. 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 NTl2000lXP and Linux.

O Copyright IBM Corp. 2001,2005 Unit 17. lntegrating Linux in a Windows Environment 17-5
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Accessing Windows Filesystems Directly


mtoois is a collection of tools that can readlwrite Windows
filesystems directly, using drive letters.

# mcopy c:autoexec.bat /root/autoexec.bat


# mformat a:
# mdir a:

Devices must not be mounted!


Drive letters are mapped to physical devices in /etclmtools.cor~f:

drive a: file=fl/dev/fdO1n
exclusive 1.44m mformat-only
drive c: file=w/dev/hdalm

O Copyright IBM Corporation 2005

Figure 17-4. Accessing Windows Filesystems Directly LX024.0

Notes:
The mtools is a collection of programs that can readlwrite Windows filesystems clirectly,
without mounting them, using drive letters. All commands have the same name (vvith an
"m" prepended) and the same syntax as the corresponding MS-DOSIWindows colmmand.
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 tolfrom UNlX
mdel Delete an MS-DOS file
mdeltree Delete an MS-DOS directory tree
mdir Display an MS-DOS directory

17-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

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 ZipIJazz 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!

O Copyright IBM Corp. 2001,2005 Unit 17. lntegrating 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

Running Windows Programs


To run a Windows program, the underlying Windows OS needs to
be emulated
Can be done at two levels:
- Emulate a PC and install Windows on it
- Emulate Windows itself
Note that you need a license for Windows if you use any Windows
software (including single DLLs)

O Copyright IBM Corporation 2005

Figure 17-5. Running Windows Programs LX024.0

Notes:
Every Windows program that you want to run under Linux, expects the underlying
operating system to be Windows. So you 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 O Copyright IBM Corp. 2001,2005


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

PC Emulators
Emulate a PC on which you install Windows
Do need a Windows license
Bochs (http:llbochs.soundforge.net)
- Emulates a complete PC in software
- Can run under any POSlX compatible OS
- Can run on any architecture
- Open Source
- Big performance loss
VMWare (http:llwww.vmware.com)
- Emulates a complete PC in software
- Only runs on Linuxllntel or Windows NTIlntel
- Commercial Product
- About 30% performance loss

O Copynght IBM Corporation 2005

Figure 17-6. PC Emulators LX024.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 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 POSlX compatible operating system. (Every UNlX is by definition POSlX
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

O Copyright IBM Corp. 2001,2005 Unit 17. lntegrating 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 reasoniably 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 disadvanitage of
VMWare is that it only runs on Linux and Windows NT on the lntel platform.

17-10 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

VMWare Screenshot

O Copyright IBM Corporation 2005

Figure 17-7. VMWare Screenshot LX024.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 BlOS takes control
and tests the memory. It then proceeds to boot the operating system from the virtual hard
disk.

O Copyright IBM Corp. 2001,2005 Unit 17. lntegrating 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

Windows Emulators
win4lin (http://www.netraverse.com)
- Commercial product
- Emulates Windows kernel
- Needs Windows DLLs
- Needs Windows license
-
WlNE WlNdows Emulator (http://www.winehq.com)
- Open Source product
- Does not need a Windows license if only WlNE or third party
DLLs are used
- Can use Windows DLLs (beware of license!)
- To see if your application is supported, go to Web site
CrocsOver Office (http://www .codeweavers.com)
- Commercial extension to WlNE

O Copyright IBM Corporation 2005

Figure 17-8. Windows Emulators LX024.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 WlNE 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 APls have been implemented, which
allows you to use most of the Windows software currently on the market. The WlrrlE Web
site features a large database where people can report their rate of success in ruiining a

17-12 Linux Power User O Copyright IBM Corp. 2001,2005


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

particular application. WINE runs on any Intel-based UNIX, including Linux, FreeBSD and
Solaris.
With native WINE, you need to make al1 configuration settings to run a particular Windows
application yourself. CrossOver Office is a commercial extension to WINE, developed by
CodeWeavers (http://www.codeweavers.com). It contains al1 the necessary settings for a
lot of Windows applications, and that makes installation of these applications much
smoother.

O Copyright IBM Corp. 2001,2005 Unit 17. lntegrating 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

win4lin Screenshot

O Copyr'ght IBM Corporation 2005

Figure 17-9. win4lin Screenshot LX024.0

Notes:
The visual shows win4lin in action. win4lin emulates the Windows kernel, on top of which
al1 regular Windows programs can run, including your taskbar, the configuration panel and
so forth.

17-14 Linux Power User O Copyright IBM Corp~.2001,2005


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

WlNE Screenshot

O Copyright IBM Corporation 2005

Figure 17-10. WlNE Screenshot LX024.0

Notes:
The visual shows WlNE in action. An application running under WlNE 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.

O Copyright IBM Corp. 2001,2005 Unit 17. lntegrating 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

Accessing Windows Servers


Samba (http://www.samba.org)
- Open Source product
- Runs on any UNIX
- Used to replace a Windows sen/er (not covered here)
-Also includes a number of client tools: smbclient, smbmount,
smbprint
smbciient allows you to retrieve information about a Windows
server, and to access files "ftp-style"
smbmount allows you to mount Windows shares over the network
smbprint allows you to print documents to a Windows-attachedl
printer

O Copyright IBM Corporation 2005

Figure 17-11. Accessing Windows Servers LX024.0

Notes:
In a Windows environment, your data frequently resides on a Windows server, or you 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 sewers. It can run on
any UNIX. The server side of Samba is not covered in this course'.
Samba includes a number of client tools as well, which were originally used to test the
sewer side of Samba, but have grown to be an excellent solution when you want to
integrate Linux in a Windows environment.

' There is a separate, two day course about Samba available from IBM under course code LX26
17-16 Linux Power User O Copyright IBM Corp. 2001,2005
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

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.

O Copyright IBM Corp. 2001,2005 Unit 17. lntegrating Linux in a Windows Environment 17-17
Course materials rnay not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

smbclient Examples

# smbclient - L winserver - N
# smbclient - L winserver - U user
# smbclient - L winserver - U user%password
# smbclient //winserver/share -U user%pw
smb> get filel
smb> put file2
smb> quit

Options:
-L lists the shares on the server
-N guest access
-U qualified access

O Copyright IBM Corporation 2005

Figure 17-12. smbclient Examples LX024.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 <usernarne> or
-U <username>%<password> allows you to retrieve information as a specific us'er.
Note: if you use the ~ u s e r n a m e ~ % ~ p a s s w notation,
o r d ~ then you need to realize that
everybody on the system can read your password with a simple p s 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.

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 is then smbclient \\\\winserver\\share -U user%pw.

17-18 Linux Power User O Copyright IBM Corp..2001,2005


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

smbmount Examples
To mount a share as an filesystem:

# smbmount //winserver/share /mnt/win95


.
..or
# mount -t smbfs //winserver/share /mnt/win95
# mount - t smbfs - o username=tuxl \
> password=secret //winserver/share /mnt/win95

Make permanent by adding this to Ietclfstab:

ldevlhda5 1 ext2 defaults 11


Idevlhda2 Iboot ext2 defaults 12
ldevlhda6 swap swap defaults OO
Ilwinserverlshare Imntlwin95 smbfs defaults,username=user%password O O

O Copyright IBM Corporation 2005

Figure 17-13. smbmount Examples LX024.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. Khe -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 Ietclfstab file. It is then
automatically be mounted when your system boots.
Note again that if you put the password on the command line or in the Ietclfstab file, then
everybody on the system is able to see the password, through a ps command or by
viewing the contents of Ietclfstab!

O Copyright IBM Corp. 2001,2005 Unit 17. lntegrating Linux in a Windows Environment 17-19
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

smbprint
smbprfint is usually not called directly but integrated into printer
spool mechanism
Configure using the regular printer configuration tools
- Select "SMB Printer"
- Configure servername, printer name, printer type, username and
password
After configuration the new printer can be used as a normal printer

Figure 17-14. smbprint LX024.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 al1 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 O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Notebook

Readina Windows Document Formats


Most native office programs for Linux read and save Windows
document formats
- StarOffice/OpenOffice
- koffice
- AbiWord

$ file mytext.doc
mytext.doc: Microsoft Office Document
$ swriter mytext.doc

Note that not al1 document features may be supported

O Copyright IBM Corporation 2005

Figure 17-15. Reading Windows Document Formats LX024.0

Notes:
Most native office applications for Linux, such as StarOfficeIOpenOff ice, koff ice and
AbiWord can read, and in most cases also write documents in Microsoft Windows native
formats.
Note however that not al1 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 is read correctly, but the video clip does not play. This is simply because
kpresenter as of yet does not have the ability to play video clips.

O Copyright IBM Corp. 2001,2005 Unit 17. lntegrating Linux in a Windows Environment 17-21
Course materials rnay not be reproduced in whole or in part
without the prior written permission of IBM.
Student Notebook

Other Useful Programs


rdesktop: Connect to a Windows Terminal Server
vnc: Allows you to "take over" a Windows systems screen remotely
dosi2unix and unix2dos: Convert Windows text files (CRILF) to
UNlX text files (LF)
cygwin (http://www.cygwin.com): Series of Linux tools running
under Windows

O Copyright IBM Corporation 2005

Figure 17-16. Other Useful Programs LX024.0

Notes:
There are a few other programs that may be useful if you try to integrate your Lini~x
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.
VNC (Virtual Network Computing) allows you to "take over" the screen of another
computer. This screen is then displayed locally on your own GUI. VNC works withi virtually
al1 operating systems, including Linux and Windows.
dos2unix and unix2dos are little programs that convert text files in Windows format (using
the CRILF end-of-line standard) to UNlX format (using the single LF end-of-line standard)
and vice versa.
cygwin is a library that implements the UNlX API, combined with a set of Linux tools, that
run under Windows. This means that al1 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 O Copyright IBM Corp. 2001,2005


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

Checkpoint

TIF 1. To make a mount of a Windows filesystem


permanent, you need to add it to letclfstab.

You want to run a third-party program under Linux that


was written to run under Windows. Which solution
does generally not require you to have a Windows
license?
a. Bochs
b. WlNE
c. VMWare
d. Win4Lin

3. What command allows you to mount a share from a


Windows server?
O Copyright IBM Corporatin 2005

Figure 17-17. Checkpoint LX024.0

Notes:

O Copyright IBM Corp. 2001,2005 Unit 17. lntegrating 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 Nofebook

Unit Summary
To access files on Windows filesystems, either mount these
filesystems or use the mtools
To run Windows programs use a PC emulator such as Bochs or
VMWare, or use a Windows emulator such as win4lin or WlNE
CrossOver Office allows you to install Windows programs directly
under Linux.
To access Windows servers you can use the client programs from
the Samba product: smbclient, smbmount and smbprint
To read Windows document formats you can use almost any native
Linux office program: StarOffice/OpenOffice, koffice, AbiWord
and others
Several other useful programs exist, including rdesktop

O Copyright IBM Corporalion2005

Figure 17-18. Unit Sumrnary LX024.0

Notes:

17-24 Linux Power User O Copyright IBM Corp. 2001,2005


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

Appendix A. Checkpoint Solutions


Unit 1. lntroduction to Linux
1. False
2. b
3. Tux

Unit 2. lnstalling Linux


1. True
2. b
3. A currently installed and configured operating systeni, such as
Windows.

Unit 3. Using the System


1. False
2. a, b and d are al1 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/tuxl /mydoc /tmp/tempdoc

Unit 5. File and Directory Permissions


1. yes
2. yes
3. yes
4. no
5. yes
6. yes

O Copyright IBM Corp. 2001,2005 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. Inletc

Unit 8. Editing Files


1. False

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. Shell Basics


1. False
2. b

Unit 10. Working with Processes


1 . False

A-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

3. A daemon is a never-ending background process that controls a


system resource or performs a network service.

Unit 11. Linux Utilities


1. False
2. b
3. Generate a long, recursive list, starting from l.
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/tuxl Icustom--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

echo $(( $1 * $2 ))

Unit 13. The Linux Gui


1. False
2. a

O Copyright IBM Corp. 2001,2005 Appendix A. Checkpoint Solutions A-3


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

3. With the startx command, or by switching the system to runlevel 5.

Unit 14. Customizing the User Environment


1. $HOME/.bashjrofile because this ovewrites the defaults set in
Ietclprofile. 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-versi0n.tar.g~
cd <archivename>
Read INSTALL or README file for further installation instructions.

Unit 16. Connecting to the lnternet


1. Falce
2. c
3. /dev/ttyS1

Unit 17. lntegrating Linux in a Windows Environment


1. True
2. b
3. smbmount

A-4 Linux Power User O Copyright lBM Corp. 2001,2005


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

Appendix B. Certification lnformation


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 lnstitute (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.
CompTlA (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. CompTlA 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 hislher 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 al1 three certification programs, the support of IBM extends to the following:
1. lnvolvement and/or active support in developing the certification prograrri, 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.

O Copyright IBM Corp. 2001,2005 Appendix B. Certification lnformation B-1


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission 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 partic;ular
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 IBMJLinux curriculum. Its aim is to
teach a Linux novice to install and configure Linux so that helshe is able to run Liriux on
hislher personal workstation or home system in an environment that is mostly bas'ed on
MS-Windows.
The LX03 (Linux System Administration 1: Implementation) is the main systeni
administration course. Its aim is to teach a Linux user the techniques and practice:; used in
installing, configuring, running and maintaining a Linux-based server.
The LX07 (Linux Network Administration 1: TCPIIP and TCPIIP Services) is the main
network administration course. Its aim is to teach a Linux system administrator how to
configure TCPJIP and various TCPJIP cervices 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 progi'amming
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) ¡Sthe course which covers Apache, the most
commonly used Web server on Linux and other UNlX platforms.
-
The LX26 (Linux integration with Windows Samba) is the course which coverc; 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 O Copyright IBM Corp. 2001,2005


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

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 IBMILinux 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 WlNS 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.

O Copyright IBM Corp. 2001,2005 Appendix B. Certification lnformation B-3


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

EducationICertification Matrix

The following table lists the required and recommended courses for each of the cupported
certification programs:
CompTlA LPI
Course
Linux+ Test 101 1 ~ e s 102
t 1 Test 201 1 Test 202
LX02 /
/ / ~ e ~ u i r eRequired
d 1
Required / Required / Required / Required / R ~ I I
LX03 Required Required Required Required Required Required
LX07 Required Required Required FIequired
LX22 1 Recomm. 1 ¡1 -
LX23 Recomm.
LX24 Required Hecomm.
fX25 Recomm. Required
LX26 Recomm. Required
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. CompTlA 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, 110
ports, DMA, ATA devices, SCSl devices, IEEE 1394 devices, PCMCIA devicei~,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 lealds to
CompTlA 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 al1
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
RHCTIRHCE certification. They cannot be used for other certifications though, and
these courses are not scheduled in al1 countries.

B-4 Linux Power User O Copyright 1BM Corp. 2001,2005


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

lndex
/etc/X11/XF86Config-4 13-9
Symbols Ihome 7-9
! 3-26
Ilib 7-4
- 12-25
/media 7-10
" 9-28
Imnt 7-10
# 3-10,12-24
10pt 7-18
#! 12-7
Iproc 7-11
$ 3-10,ll-18
Iroot 7-12
$# 12-9
Isbin 7-4
$$ 9-25,10-3,10-6
Itmp 7-13
$(( )) 12-25
Iusr 7-14
$0 9-20 Iusrllocal 7-15
$* 12-9
Ivar 7-16
$? 9-27,12-15
< 9-10
$@ 12-9
<< 12-11
$1 12-9 -- 12-15
$2 12-9
> 9-11
$BASH-ENV 14-4
>> 9-11
$HOME 9-26
? 9-6
$HOME/.bash-login 14-3
\ 9-28
$HOME/.bash_profile 14-3
\b 9-29
$HOME/.bashrc 14-4
\n 9-29
$HOME/.profile 14-3
\t 9-29
$LANG 9-26
A 11-18
$PATH 7-4,9-25,12-4,12-5
{ 9-21
$PS1 9-25
$PS2 9-26
1 9-15
$PWD 9-26
11 12-13,12-17
} 9-21
$variable 9-23
9-20
% 12-25
&& 12-13,12-17
&> 9-14 Numerics
' 9-28 2> 9-12
( 9-21,12-25 2>> 9-12
) 9-21,12-25 80386 1-5
* 9-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
1 12-25 Alan Cox 1-12
Ibin 7-4 alias 4-23,9-30
1b00t 7-5 alsasound 16-16
Idev 7-6 anacron 16-16
Idevlnull 4-4,9-12 apmd 16-17
Ietc 7-8 apropos 6-6
Ietclbashrc 14-5 arithmetic 12-25
Ietclfstab 7-24,17-5 atd 16-17
Ietclinittab 13-14 autofs 16-17
1etclmodules.conf 15-14,15-15 awk 9-17,12-7
Ietclprofile 14-3
Ietclskel 7-8
/etclX11/XF86Config 13-9

O Copyright IBM Corp. 2001,2005 lndex X-1


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

B cron 6-6
backticks 9-20 crond 16-17
bash 1-4,9-3 CrossOver Office 17-13
bg 10-12,10-13 C S ~ 10-6,12-7
Block special devices 7-6 Ctrl-D 3-29
B O C ~ S17-9 CUPS 15-12
boot disk 2-26 CUPS 16-17
Boot Loader 2-17 C U ~ S 15-13
~
boot loader 2-17 cut 11-12
bootable media 2-10 -d option 1 1-1 3
BootMagic 2-17 -f option 11-13
Bourne Again Shell 9-3 CVS. See Concurrent Versioning System
Broadcast Address 2-19 cygwin 17-22
BSD 15-12
BSD license 1-9
D
daemon 10-22
C date 3-16
daytime 16-17
Cable modem 16-4,16-11
cal 3-17 Default gateway 2-19
cat 4-20,9-18 Default router 2-19
cd 4-9 Desktop Environment 13-1O
Character special devices 7-6 devices 7-6
chargen 16-17 dhclient 15-16
chat 16-7 DHCP 2-19,15-15
chkconfig 16-16 Directories 4-4
chmod 5-9,12-5 directories 4-4
clear 3-20 Disk Druid 2-8,2-15
Command grouping 9-21 display manager 13-15
command prompt 3-10 display managers 10-5
Command substitution 9-20 DNS server 2-19
commands documentation 6-15
--help option 6-12 dollar sign 3-10
Common UNlX Printing System 15-12 dos2unix 17-22
compress 1 1-29 drive letters 7-3
CompTlA B-1
~oncurrentVersioning System 1-1 o
Conditional execution 12-13
E
echo 3-20,10-3,10-6,16-17
configuration
egrep 11-21
automated 15-4
else 12-13,12-18
firewall 2-24
emacs 1-4,8-3
manual 15-4
esound 16-17
modem 2-24
Ethernet 2-19
network 15-15
ex 8-7
printer 2-24,15-12
exit 3-29
sound 15-14
expand 9-17
sound card 2-24
export 9-24
temporary 15-4
expr 12-27
time zone 2-24
extended partition 2-5
tools 15-5
console 3-4
core dump 10-15
Cp 4-16
F
fbset 16-17
-i option 4-17 fdisk 2-8,2-15
-R option 4-17 fg 10-12,10-13

X-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

fgrep 11-21 H
fi 12-13,12-18 Hardware-HOWTO 2-3
file 8-3,1 1 -28 hash sign 3-10
binary 4-4 head 11-24
descriptors 9-9 hexdump 4-22
editing 8-3 history 3-25
hidden 4-5 Hostname 2-19
interna1 structure 4-3 hotpIug 16-18
naming 4-5 HOWTOS 6-13
special 4-4 Hurd 1-4
text 4-4 hwscan 16-18
filters 9-16
find 11-3
-a option 1 1 -9 I
-exec option 1 1-6 IDE 2-6
-mtime option 1 1-8 identd 16-18
-newer option 1 1-8 if 12-13, 12-18
-o option 1 1 -9 ifconfig 15-15
-ok option 1 1-7 info 6-8
-perm option 1 1-8 init 10-4,10-16
-print option 1 1 -5 installation class 2-14
-size option 1 1-8 installation program 2-12
-type option 1 1-8 lnternet Service Provider 16-3
finger 3-19,6-5,16-18 IP address 2-19
firstboot 16-18 ipchains 16-18, 16-23
fmt 9-18 iptables 16-18, 16-23
for 12-21,12-22 irda 16-18
Free Software Foundation 1-3 ISDN 16-4,16-8
fsck 7-17 isdn 16-18
FSF. See Free Software Foundation isdn-config 16-9
fuser 16-16

J
G Job Control 10-12
gCC 1-4 job number 10-9
gdb 10-15 jobs 10-12
gdm 10-5,13-15,13-16 join 11-31
General Public License 1-8 joystick 16-18
GlMP 13-12
gIibc 1-4
GNOME 13-13 K
GNU Object Modeling Environment 13-13 K Desktop Environment 13-11
GNU. See GNU's Not Unix kbd 16-18
GNU's Not Unix 1-3 kdcrotate 16-18
GPL. See General Public License KDE 13-11
gpm 3-27,16-18 kdeprint 15-13
graphical file managers 4-25 kdm 10-5,13-15,13-16
Graphical User lnterface 2-22 kedit 8-3,8-5
grep 9-16,9-18,11-15,11-17 Kerberos 2-20
-f option 1 1-20 kernel 7-5
-voption 11-17,11-20 keyboard layout 2-13
G R U B 2-16,2-18,2-26,7-5 keytable 16-18
GUI. See Graphical User lnterface kill 10-12,10-13,10-14
gunzip 11-29 signals 10-14
gzip 11-29,15-10 killall 10-14, 10-15
-v option 1 1-29 koffice 17-21

O Copyright IBM Corp. 2001,2005 lndex X-3


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

Konqueror 13-12
kotalk 16-19
kpm 10-21
kppp 16-7 M
kpresenter 17-21 major number 7-6
ksysguardd 16-19 makewhatis 6-6
~ S Y S V 16-16 man 6-3, 15-6
ktalk 16-19 -k option 6-6
kudzu 16-19 sections 6-7
Massachusetts lnstitute of Technology 1-3, 13-3
Master Boot Record 2-5
L master boot record 2-17
language 2-13 MBR. See Master Boot Record
Larry Ewing 1-12 MD5 encryption 2-20
LDAP 2-20 mdadmd 16-19
less 4-21, 6-5 Memory Management Unit 1-5
let 12-25 mesg 3-22
Libraries 7-4 messagebus 16-19
LILO 2-16, 2-18, 2-26, 7-5 Metro-X 13-7
Linus Torvalds 1-5, 1-1O Minix 1-5
Linux File System Hierarchy Standard 7-3 minor number 7-6
Linux Professional lnstitute B-1 MIT. See Massachusetts lnstitute of Technology
lirc 16-19 mkdir 4-10
locate 11-11 -p option 4-12
lockfiles 7-16 mknod 2-6, 7-7
Locking 3-28 mkpasswd 3-14
logfiles 7-16 MMU. See Memory Management Unit
logging on 3-3 modem 16-3
logging out 3-29 more 4-21
logical partitions 2-5 mount 7-22, 17-5
login 10-5 mountpoint 7-22
login name 10-5 mouse type 2-13
login shell 10-5 MSN 16-9
IO~OU 3-29
~ mtools 17-4, 17-6
lost+found directory 7-17 multi-tasking 3-3
Ip 15-13 multi-user 3-3
lpadmin 15-12 mv 4-18
lpcancel 15-13 -i option 4-19
Ipd 10-22, 16-19
LPI. See Linux Professional Institute
Ipq 15-13 N
Ipr 15-13 NDA. See Non-Disclosure Agreement
lprm 15-13 netfs 16-19
LPRng 15-12 netscape 10-15
lpstat 15-13 netstat 16-16
IS 4-5, 4-13, 9-20 network 16-19
-a option 4-13 adapter 2-19
-d option 5-5 configuration 2-19
-1 option 5-5 Network Address 2-19
LXO2 8-2 nfs 16-19
LX03 B-2 nfslock 16-20
LX07 8-2 nfsserver 16-19
Lx22 8-2 nice 10-19
LX23 9-18, 8-2 -n option 10-19
LX24 16-23, B-2 NIS 2-20
LX25 8-2 nl 9-18

X-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

nmbd 16-21 PPS 15-12


nohup 10-12, 10-16 pr 9-18
Non-Disclosure Agreement 1-3 primary partitions 2-5
nscd 16-20 process 10-3
ntpd 16-20 background 10-9
ntsysv 16-16 controlling 10-9
foreground 10-9
parent/child relationship 10-6
O priorities 10-17
od 4-22 starting and stopping 10-4
openct 16-20 Process ID 10-3, 10-9, 10-13
OpenOffice 7-18, 17-21 process table 10-3
PS 10-7, 10-15
a option 10-7
P u option 10-7
package groups 2-21 x option 10-7
parted 2-7 pstree 10-8
partition ptal 16-20
/boot 2-16 pty 7-7
/home 2-16 pwd 4-8
/opt 2-16
/tmp 2-15
Iusr 2-15 Q
/usr/local 2-16 Quoting metacharacters 9-28
/var 2-16
root 2-15
Partition Table 2-5 R
partitioning 2-5 radvd 16-20
PartitionMagic 2-7, 2-9 random 16-20
partitions 2-3 rawdevices 16-20
passwd 3-14 rawrite 2-10
password 3-3, 10-5 rdesktop 17-22
paste 11-31 read 12-24
path name 4-6 Red Hat B-1
absolute 4-6 Red Hat Certified Engineer B-1
relative 4-6 Red Hat Certified Technician B-1
pcmcia 16-20 Red Hat Package Manager 15-7
~ C S C 16-20
~ redhat-config-xfree86 13-9
pdksh 12-7 redirection
penguin 1-12 combined 9-14
perl 12-7 input 9-10
permissions 5-3 output 9-11
changing 5-9 pipes 9-15
directory 5-6 Regular Expressions 11-18
file 5-6 renice 10-20
levels 5-4 resmgr 16-20
octal notation 5-11 return code 9-27
required 5-8 RHCE. See Red Hat Certified Engineer
symbolic notation 5-9 RHCT. See Red Hat Certified Technician
types 5-6 rhnsd 16-21
umask 5-13 Richard Stallman 1-3
PID. See Process ID rm 4-23, 9-20
portmap 16-20 -f option 4-23
postfix 16-20 -i option 4-23
PPP 16-5 -r option 4-23
pppd 16-7 rmdir 4-11

O Copyright IBM Corp. 2001,2005 lndex X-5


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

-p option 4-12 -d option 1 1-23


root 2-20,3-3 -n option 1 1-23
rpasswdd 16-21 -r option 1 1-23
RPM 15-7 -t option 1 1-22
rpm 15-8 source 12-6
-a option 15-9 splash 16-22
-e option 15-8 spIit 4-24
-i option 15-8,15-9 spool files 7-16
-1 option 15-9 S S ~ 3-4
-p option 15-9 sshd 16-22
-q option 15-9 standard error 9-9
-U option 15-8 standard input 9-9
rpmconfigcheck 16-21 standard output 9-9
rsync 16-21 StarOffice 17-21
runlevel 13-14 startx 13-14
stderr 9-9
stdin 9-9
S stdout 9-9
Samba 16-22,17-16,8-3 strings 4-22
Samba daemon 16-21 Subnetmask 2-19
saslauthd 16-21 superuser 2-20
sax 13-9 swap space 2-15
sax2 13-9 S Y S ~ O ~16-22
scsl 2-6
sed 9-17
sendmail 16-21 T
serial terminal 3-4 tac 9-18
services 16-21 tail 11-24
setserial 16-21 -f option 1 1-24
sgi-fam 16-21 talk 3-21
sh 9-3 tar 15-10
shadow passwords 2-20 tee 9-19
shell 9-3,10-3 telnet 3-4
aliases 9-30 terminal emulator 3-9
metacharacters 9-5 test 12-13,12-14,12-15
reserved words 9-5 then 12-13,12-18
scripting 12-3 time 16-22
variables 9-22 tkrat 10-15
shell scripts Token Ring 2-19
invocation 12-4 top 10-21
shift 12-9,12-22 ~ O U C 4-14
~
signals 10-1 4 tr 9-18
hangup 10-14 TUX 1-12
interrupt 10-15 type I 1-26
kiII 10-15
quit 10-15
sleep 12-20 U
smartd 16-21 umask 5-13
smbclient 17-17,17-18 umount 7-23
smbd 16-21 unalias 9-30
smbfs 16-21 unexpand 9-17
smbmount 17-17,17-19 unified filesystem 7-3
smbprint 17-17, 17-20 UnitedLinux B-1
snmpd 16-22 UNlX 1-3,3-3
Software RAID 16-19 unix2dos 17-22
SOrt 9-18, 1 1-22 updatedb 1 1 -1 1

X-6 Linux Power User O Copyright IBM Corp,,2001,2005


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

upgrade 2-14 X-Consortium 13-3


user accounts 2-20 xdm 10-5, 13-15, 16-22
user authentication 3-3 xDSL 16-4, 16-13
User Private Groups 5-13 xf86config 13-9
username 3-3 XFree86 13-3
Xfs 16-23
v Xi Graphics 13-7
xinetd 16-23
vi 8-3, 8-5, 17-22 XIOC~ 3-28
cheat sheet 8-23 xntpd 16-23
command mode 8-7, 8-10
cursor movement 8-9
edit mode 8-7, 8-11 Y
ex mode 8-7, 8-15 YaST 2-8
exiting 8-22 yast 15-16
modes 8-7 yast2 15-14
options 8-20 ypbind 16-23
searching 8-14 yum 16-23
vim 8-6
virtual terminal 7-7
virtual terminals 3-5
dock 3-28 zcat 11-29
VMWare 17-9
VNC 16-22, 17-22
vncserver 16-22
vncviewer 16-22

W
wall 3-20
WC 9-15
-1 option 9-16
whereis 11-26
which 11-26
while 12-20, 12-22
W ~ O 3-18
who am i 3-18
whoami 3-18
wildcard expansion 9-6
win4lin 17-12, 17-14
winbind 16-22
window manager 10-5, 13-5
Windows for Workgroups 1-5
WlNE 17-12, 17-15
wine 10-15, 16-22
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

O Copyright IBM Corp. 2001,2005 lndex X-7


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

X-8 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials may not be reproduced in whole or in part
without the prior written permission of IBM.
Linux
Power User
(Course Code QLX02)

Student Exercises
ERC 4.0

I BM Certified Caurse Material


Student Exercises

Contents
Trademarks ....................................................... v
Exercises Description .............................................. vii

Exercise 1. lntroduction to Linux ........................................ 1-1

Exercise 2. lnstalling Linux ............................................. 2-1

Exercise 3. Using the System ........................................... 3-1

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

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

Exercise 6. Linux Documentation ........................................ 6-1

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

Exercise 8. Editing Files ............................................... 8-1

Exercise 9. Shell Basics ................................................ 9-1

Exercise 10. Working with Processes ........................... .,....... 10-1

Exercise 11. Linux Utilities .............................................11-1

Exercise 12. Shell Scripting .............................................12-1

Exercise 13. The Linux GUI ............................................ 13-1

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

Exercise 15. Basic System Configuration ................................ 15-1

Exercise 16. Securing a Linux Workstation ....................... ........ 16-1 S

Exercise 17. lntegrating Linux in a Windows Environment .................. 17-1

Exercise 18. End-of-course Challenge Exercise ........................... 18-1

O Copyright IBM Corp. 2001. 2005 Contents iii


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

iv Linux Power User O Copyright IBM Corp. 2001,2005


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

Trademarks
The reader should recognize that the following terms, which appear in the cointent of this
training document, are official trademarks of IBM or other companies:
IBM8 is a registered trademark of lnternational Business Machines Corporation.
The following are trademarks of lnternational Business Machines Corporatiori in the United
States, or other countries, or both:

Microsoft, Windows and Windows NT are trademarks of Microsoft Corporation in the


United States, other countries, or both.
lntel and Pentium are trademarks of lntel Corporation in the United States, other countries,
or both.
UNlX 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.

O Copyright IBM Corp. 2001,2005 Trademarks v


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Exercises

vi Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercises Description
The objective of the Linux Power User exercises is to let the you
become familiar with installing and running Linux on your personal
workstation. To achieve this, a variety of real-world exercises are
performed, aimed at simulating real-world tasks.
Each exercise unit consists of two parts:
Exercise lnstructions -This section contains what it is you are to
accomplish. There are no definitive details on how to perform the
tasks. You are given the opportunity to work through the exercise
given what you learned in the unit presentation, utilizing the unit
Student Notebook, your past experience, the online documentation
and maybe a little intuition.
Exercise lnstructions With Hints -This section is an exact
duplicate of the Exercise lnstructions section except that in addition,
specific details andlor hints are provided to help step you through the
exercise. A combination of using the lnstructions section along with
lnstructions With Hints section can make for a rewarding combination
providing you with no hints when you don't want them and hints when
you need them.
In this last section, multiple ways to accomplish the same task are
often provided. Where this has been done, the various rnethods are
separated by an -0R-
All exercises and hints apply both to Red Hat and SuSEl equally,
unless mentioned.

O Copyright IBM Corp. 2001,2005 Exercises Description vii


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

viii Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise 1. lntroduction to Linux


Notice: This unit has no exercises. This page is here to ensure that unit nurribers and
exercise numbers stay synchronized.

--

O Copyright IBM Corp. 2001,2005 Exercise 1. lntroduction to Linux 1-1


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

1-2 Linux Power User O Copyright IBM Corp. 2001,2005


Course materials may not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Exercises

Exercise 2. lnstalling Linux


What This Exercise Is About
This exercise lets you install Linux.

What You Should Be Able to Do


After completing this exercise you should have experience with:
Preparing a system for installation
Partitioning a system
Installing Linux

Required Materials
A set of installation CDs for your distribution

O Copyright IBM Corp. 2001,2005 Exercise 2. lnstalling Linux 2-1


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

Exercise lnstructions
Note: The exercises in this course material have been designed for and tested ori the
following three distributions:
Fedora Core 3
Red Hat Enterprise Linux 4 Workstation
SUSE Linux Professional 9.3
If you are using one of these three distributions, follow the instructions below that apply to
your distribution. If you are using another distribution, or another version of one of the three
distributions above, then your instructor gives you additional information.
Depending on the circumstances, your instructor loans you a full set of CDs for each
distribution, so you can perform a CD-based install, or your instructor loans you a network
install CD, so you can perform a network-based install.
If you need to perform a network install, your instructor gives you additional infornnation,
specifically:
The install method: NFS, FTP or HTTP
The IP address that is to be used for your workstation, if DHCP is not used
The name or IP address of the install server
The path to the installation images on the install server

Installing Fedora Cora 3


- 1. (CD-based install only) Insert the Fedora Core 1 CD 3 in the CD-ROM drive.
-2. (Network-based install only) Insert the Fedora Core 3 boot.iso CD in the CID-ROM
drive.
-3. Turn on or reboot the computer.
-4. The system boots from CD, and you see a screen giving you different installation
options. We use standard installation, so press Enter.
If your system is not booting from CD, then either your system cannot boot from CD
at all, or your BlOS is not set up to boot from CD. In this case, ask your instiructor for
additional instructions.
-5. (CD-based install only) Fedora gives you the option of testing the CD media before
you begin the install. If you're using official install media, or if your CDs have been
tested before, skip the media test. Otherwise, press OK to perform a media test and
follow the subsequent screens to test al1 your CDs.
Note that a media test may take up to 10 minutes per CD, depending on your
CD-drive speed.

2-2 Linux Power User O Copyright IBM Corp,,2001,2005


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

-6. (CD-based install only) Fedora now starts the graphical install method. This might
take a couple of minutes. At the graphical "Welcome to Fedora Core" iscreen, click
Next.
-7. Choose the language for the installation process and click Next.
-8. Choose your keyboard model and layout, and click Next.
-9. (Network-based install only) Choose the network installation method: NFS, HTTP or
FTP.
-10. (Network-based install only) Configure the local IP configuration: DHC;P or fixed IP.
- 11. (Network-based install only) Enter the details of the network install server.
- 12. (Network-based install only) Fedora now starts the graphical install method. This
might take a couple of minutes. At the graphical "Welcome to Fedora Core" screen,
click Next.
- 13. Choose your mouse type and port. If you have a two-button mouse, select "Emulate
3 Buttons" as well. Click Next.
- 14. Choose your monitor and click Next.
- 15. Fedora now tries to detect an existing installation. If an existing installation has been
detected, you see the "Upgrade Examine" screen. In this screen select "lnstall
Fedora Core". Click Next.
- 16. At the "lnstallation Type" screen, choose the "Workstation" installation type. Click
Next.
- 17. At the "Disk Partitioning Setup" screen, Choose to "Manually partition with Disk
Druid". Click Next.
- 18. The Disk Druid screen appears and shows the current layout of your disks. If
everything is correct, you should only see a small (200-500 MB) Windows
9x/ME/NT/2000/XP partition.
You can now start adding Linux partitions. Make sure you create three additional
partitions:
One partition is used as root partition. Its mount point should be "/", the
partition type should be "Linux native", the size of this partition should be 4.0
Gigabytes (4000 Megabytes) and should be formatted with an ext3
filesystem.
The second partition is used as swap space. A swap space does not have a
mount point (it shows as "<Swap>"). The size should be equal to the amount
of real memory, with a maximum of 256 MB, and the partition type should be
"Linux swap".
Add a boot partition. It's mount point should be Iboot, the partition type should
be "Linux Native", the size of this partition should be 100 MB.

O Copyright IBM Corp. 2001,2005 Exercise 2. lnstalling Linux 2-3


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Exercises

- 19. Let the instructor check your partition configuration before you save it! After
the instructor has checked your partition configuration, click Next.
-20. The install program now allows you to configure your boot loader. You can iaccept al1
defaults here:
Use GRUB as the boot loader
The default boot image is Fedora Core, and Windows is also bootable.
Do not configure a boot loader password.
-21. Configure your network adapters. Your instructor tells you whether to use DHCP or
not. If not, he or she provides you with the IP Address, Netmask, Network and
Broadcast addresses, and with the Hostname, Gateway and DNS addresses. Enter
these values, double-check them and click Next.
-22. The next screen allows you to configure firewall rules. We're not going to uise this
type of firewalling, so select "No firewall". Enable SELinux change that frorn Active
to Disabled click Next then click Proceed.
-23. The installer now asks for languages to be installed. This depends on which spell
checker libraries are installed. So select all languages you are planning to use on
your system. Click Next.
-24. Now select your Time Zone, then click Next.
-25. In the next screen you need to set the root password. For convenience in the class,
set the root password to ibmlnx. Click Next.
-26. At the "Workstation Defaults" screen, select "Customize software package.; to be
installed". Then click Next and add the "KDE Desktop Environment" group. Click
Next.
-27. Note the location of the log file: /root/install.log and click Next.
-28. Fedora now formats the filesystems and install Fedora Core 3. This may ta.ke
anywhere from 5 minutes to an hour, depending on the number of packages to
install, and the speed of the computer.
While installing, you can see what is going on in detail by switching to the third
virtual terminal with Ctrl-Alt-F3. Switch back with Alt-F7. Also take a look at other
virtual screens (1 through 6).
-29. Choose to create a custom boot disk for your system. You need a blank floppy for
this, which your instructor provides.
-30. Your installation is now complete. Remove the custom boot disk from the drive and
click Reboot to reboot your system.
-31. When your Fedora system boots for the first time, the Fedora Setup agent is started.
Click the "Next" button.
-32. Read the License Agreement, select "Yes, I agree" and click Next.

- - --
2-4 Linux Power User O Copyright IBM Corp. 2001,2005
Course materials may not be reproduced in whole or in part
without the prior written perniission of IBM.
Student Exercises

-33. Check the date and time. If the network has an NTP server, configure X
i here as well.
Click Next.
-34. Configure Display. Select Monitor Resolution and Color Depth then click Next.
-35. Add a personal user account for yourself, with a password you make I J yourself
~
Then click Next.
-36. Verify that your sound card has been detected and is configured correctly, by playing
a test sound. Then click Next.
-37. Do not install additional software. Click Next, then click Next again.

O Copyright IBM Corp. 2001,2005 Exercise 2. lnstalling Linux 2-5


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Exercises

lnstalling Red Hat Enterprise Linux 4 Workstation


- 1. (CD-based install only) lnsert the RHEL 4 WS CD 1 in the CD-ROM drive.
-2. (Network-based install only) lnsert the RHEL 4 WS boot.iso CD in the CD-ROM
drive.
-3. Turn on or reboot the computer.
-4. The system boots from CD, and you see a screen giving you different installation
options. We use standard installation, so press Enter.
If your system is not booting from CD, then either your system cannot boot from CD
at all, or your BlOS is not set up to boot from CD. In this case, ask your instructor for
additional instructions.
-5. (CD-based install only) Red Hat gives you the option of testing the CD meclia before
you begin the install. If you're using official install media, or if your CDs have been
tested before, skip the media test. Otherwise, press OK to perform a media test and
follow the subsequent screens to test al1 your CDs.
Note that a media test may take up to 10 minutes per CD, depending on your
CD-drive speed.
-6. (CD-Based install only) Red Hat starts the graphical install method. This m~ighttake
a couple of minutes. At the graphical "Welcome to Red Hat Enterprise Lin~ix"
screen, click Next.
-7. Choose the language for the installation process and click Next.
-8. Choose your keyboard model and layout, and click Next.
-9. (Network-based install only) Choose the network installation method: NFS, HTTP or
FTP.
- 10. (Network-based install only) Configure the local IP configuration: DHCP or fixed IP.
- 11. (Network-based install only) Enter the details of the network install server.
- 12. (Network-based install only) Red Hat now starts the graphical install method. This
might take a couple of minutes. At the graphical "Welcome to Red Hat Enterprise
Linux" screen, click Next.
- 13. Choose your mouse type and port. If you have a two-button mouse, select "Emulate
3 Buttons" as well. Click Next.
- 14. Red Hat now tries to detect an existing installation. If an existing installation has
been detected, you see the "Upgrade Examine" screen. In this screen select
"Perform a new Red Hat Linux installation". Click Next.
- 15. At the "Disk Partitioning Setup" screen, Choose to "Manually partition with Disk
Druid". Click Next.

2-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

-16. The Disk Druid screen appears and shows the current layout of your disks. If
everything is correct, you should only see a small (200-500 MB) Windows
9x/MElNTl2000/XP partition.
You can now start adding Linux partitions. Make sure you create three additional
partitions:
The first partition should be Iboot 150 MB.
One partition is used as root partition. Its mount point should be "/",the
partition type should be "Linux native", the size of this partition should be 3.5
Gigabytes (3500 Megabytes) and should be formatted with an ext3
filesystem.
The second partition is used as swap space. A swap space does not have a
mount point (it shows as "<Swap>"). The size should be equal lo the amount
of real memory, with a maximum of 256 MB, and the partition type should be
"Linux swap".
- 17. Let the instructor check your partition configuration before you save it! After
the instructor has checked your partition configuration, click Next.
-18. The insta11 program now allows you to configure your boot loader. You can accept al1
defaults here:
Use GRUB as the boot loader
The default boot image is Red Hat Linux, and Windows is also bootable
Do not configure a boot loader password
- 19. Configure your network adapters. Your instructor tells you whether to use DHCP or
not. If not, he or she provides you with the IP Address, Netmask, Network and
Broadcast addresses, and with the Hostname, Gateway and DNS addresses. Enter
these values, double-check them and click Next.
-20. The next screen allows you to configure firewall rules. We're not going to use this
type of firewalling, so select "No firewall" and click Next.
-21. The installer now asks for languages to be installed. This depends on which spell
checker libraries are installed. So, select al1 languages you are planning to use on
your system. Click Next.
-22. Now select your Time Zone, then click Next.
-23. In the next screen you need to set the root password. For convenience in the class,
set the root password to ibmlnx. Click Next.
-24. At the "Package Installation" screen, select "Customize the set of packages to be
installed". Then click Next and add the "KDE Desktop Environment" group. Click
Next.
-25. Note the location of the log file: /root/install.log and click Next.

O Copyright IBM Corp. 2001,2005 Exercise 2. lnstalling Linux 2-7


Course rnaterials rnay not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

-26. Red Hat now formats the filesystems and install Red Hat Linux. This takes
anywhere from 5 minutes to an hour, depending on the number of packages to
install, and the speed of the computer.
While installing, you can see what is going on in detail by switching to the third
virtual terminal with Ctrl-Alt-F3. Switch back with Alt-F7. Also take a look at other
virtual screens (1 through 6).
-27. Your installation is now complete. Click Exit to reboot your system. When the CD
drive opens, remove your CD.
-28. When your Red Hat Linux system boots for the first time, the Red Hat Setup agent is
started. Click the "Next" button.
-29. Read the License Agreement, select "Yes, I agree" and click Next.
-30. Check the date and time. If the network has an NTP server, configure it here as well.
Click Next.
-31. Configure Display (for X). Choose Configure then Resolution then Color D~epth.
-32. On Red Hat Login, choose "Tell me why I need to register and provide a Rled Hat
login." Click Next.
-33. Click "1 cannot complete registration at this time. Remind me later." Click Next.
-34. Add a personal user account for yourself, with a password you make up yourself.
Then click Next.
-35. Verify that your sound card has been detected and is configured correctly, by playing
a test sound. Then click Next.
-36. Do not register with the Red Hat Network. Then click Next.
-37. Do not install additional software. Click Next, then click Next again.

2-8 Linux Power User O Copyright IBM Corp. 2001,2005


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

lnstalling SuSE Linux Professional9.3


-1. Insert the SuSE Linux 9.3CD 1 in the CD-ROM drive.
-2. Turn on or reboot the computer.
-3. The system boots from CD, and you see a screen giving you different installation
options.
If you are going t o do a CD-based installation, then select "lnstallation".
If you are going t o do a network-based installation, then select F3 and choose
nfs. Note: It tries to access server and fail. This is okay. Continue withi Step 4.
If your system is not booting from CD, then either your system cannot boot from CD
at all, or your BlOS is not set up to boot from CD. In this case, ask youlr instructor for
additional instructions.
-4. (Network-based install only) Select the language for the network configuration
process.
-5. (Network-based install only) Select your keyboard map.
-6. (Network-based install only) In the main menu, select "Kernel Modules (hardware
drivers)". Then, select "Load network card modules". Now select the rietwork driver
(kernel module) you need for your network card and press Enter. If you don't know
what network card is in the system, ask the instructor. Do not add any parameters,
unless your instructor tells you so. You should now get a message "Module xxx
loaded successfully". If this message does not appear, ask your instr~ictorfor help.
-7. (Network-based install only) Go back to the main menu and select "Start installation
1system". Then select "Start installationlupdate".
-8. (Network-based install only) Select "Network as the source medium. Select the
network install protocol (FTP, HTTP, NFS, SMB or TFTP).
-9. (Network-based install only) Check with your instructor whether the systems in the
classroom should be configured using DHCP, and make the choice accordingly.
- 10.(Network-based install only) Enter the IP address of the install server, then enter the
installation directory where the install image is located.
- 11. Select the language for the installation process.
- 12.If your system has already been installed with Linux, then you get a pop-up window
about this. Select "New installation" and click OK.
- 13.Browse through the autodetected installation settings, and make chaiiges if
required:
Make sure that your keyboard layout is correctly detected.
Make sure that your mouse is correctly detected.
Make sure that your root partition is at least 3.5GB.

O Copyright IBM Corp. 2001,2005 Exercise 2. InstaYling Linux 2-9


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

As software, make sure that you add "GNOME system" to the default
selection of software.
Make sure that your windows partition is included at the "sections" bullet of
your boot loader. (replace code in MBR, activate boot loader partition)
Make sure the correct timezone is selected.
Make sure the correct language is selected.
Click "Accept" and click "Yes, install" at the popup screen. SuSE now insta.lls itself.
This takes 5 minutes to an hour, depending on the speed of your computer.
- 14. Note that SuSE automatically reboots when it is nearly finished with CDI. This is
normal. When the CDs boot screen appears, do nothing so that the system boots
from hard disk. This continues the installation process automatically.
- 15. When the installation is finished, you need to enter the root password. For
convenience in class, use ibmlnx as the root password.
- 16. The next screen allows you to configure your network. Make sure al1 detec:ted
values are ok. If necessary, consult your instructor for IP addresses and such. Then,
click Next.
- 17. If you have an lnternet connection, you can test your lnternet connection and check
for the latest updates. Click Next.
- 18. If you tested your lnternet connection and checked for updates, then you might get a
pop-up window asking you whether you want to download and install availisble
updates. Select "No, Skip Update" in this screen: we update the system manually
later. Click Next.
- 19. Select "Local (/etc/passwd)" as User Authentication Method. Click Next.
-20. Add a local user account for yourself, using a secret password. Do NOT select "Auto
Login". Then click Next.
-21. SuSEConfig now executes several configuration scripts. This might take several
minutes.
-22. If you feel like it, read the release notes for this version. Then click Next.
-23. Check your hardware configuration, then click Next.
-24. Click Finish.
-25. Remove the last install CD from the CD-drive.

END OF EXERCISE

2-10 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise 3. Using the System


What This Exercise Is About
The purpose of this exercise is to become familiar with L-inux,the
command syntax and some basic commands. The exercise also
serves to show come multi-user concepts.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Switch between virtual terminals
Log in to a Linux system and change passwords
Execute basic commands
Use the wall and write commands to communicate with other
users
Use keyboard control keys to control command line output
Use the mouse to copy and paste commands
Use the command history
Lock a Linux system
Log out of a Linux system

O Copyright IBM Corp. 2001,2005 Exercise 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 Exercises

Exercise lnstructions
Logging in on a virtual terminal
In this section you are going to log in to the system using both text and graphical virtual
terminals.
- 1. If the install went correctly then you should now see a graphical login pronnpt. If this
is not the case, ask your instructor to fix this. (You learn how to do this yourself later
in the course.)
-2. Verify that you indeed have seven different virtual terminals. Cycle through them by
pressing Alt-Fn, where n is the terminal number you want to access. Use C:trl-Alt-Fn
when you are in a graphical terminal.
-3. In your first virtual terminal (ttyl), log in to the system with your own username which
you also configured when installing the system.
-4. In your second virtual terminal (tty2), log in to the system as root. After having
logged in, look at the command prompt. Do you notice anything different from the
command prompt in the other virtual terminals?
-5. In your seventh virtual terminal (tty7), log in to the system with your own ursername
and password.
-6. Open a terminal window. Take a look at the command prompt. Does it differ from the
command prompt on ttyl? Why or why not?

Basic Commands
In this section we are going to execute some basic commands, in order to familiarize
yourself with the command syntax of Linux, and the fact that you are currently on a
multi-user, multi-tasking system.
All commands in this section are executed on virtual terminal seven (the graphical login
prompt where you are logged in as yourself), using the terminal window you just opened,
unless specified otherwise.
-7. Change your password. Memorize this password because no one can find out your
password if you forget ¡t.
-8. Display the system's date.
-9. Display the whole calendar for the year 2005.
- 10. Display the month of January for the year 1999 and 99. Are 1999 and 99 th~esame?
- 11. Generate a list of al1 users present on your system.
- 12. Display your login name.
- 13. Display the login information of your own user account, and of root.
- 14. Clear your screen.

3-2 Linux Power User O Copyright IBM Corp. 2001,2005


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
!itudent Exercises

- 15. Print the text Out to lunch on your display.


- 16. Make sure you are willing to receive messages
-17. Write the message Out to lunch to the display of root. Check whether root got the
message.
- 18. Write the message Out to lunch to the display of al1 users. Check whether
everybody on your system got the message.

Keyboard and Mouse Tips


- 19. The bash shell has a command history function. View some of the cornmands you
have entered. Try to alter one of these commands, then run the comniand again.
-20. Your terminal has a buffer that keeps track of the output of your comrriands. View
the output of the previous commands.
-21. Bash supports command and filename completion with the TAB character. Try to
use this feature, both on commands and on filenames.
-22. Both in a text terminal and an emulated terminal in the graphical desktop, try to
re-execute commands by scrolling up a little, selecting the command with the left
mouse button, and then pasting it onto the same terminal again with the middle
mouse button.
Also try this across different text and graphical terminals.
Note: SuSE does not enable gpm by default, so your mouse won't work in a text
terminal when you are using SuSE.

Using the history


-23. Use the history command to view the last 20 commands you typed.
-24. Execute one of the commands from the history list.
-25. Execute the echo command again, this time changing the word "lunch" to "dinner".
-26. Bash also supports searching in the history. Try this feature as well.

Locking terminals
Note: Not al1 distributions install vlock and xlock by default. If vlock and xlock are not
installed, then you learn how to do that in Exercise 15 - Basic System Configuration.
-27. Lock a virtual terminal. Can you switch to another virtual terminal while this one is
locked? Unlock the terminal.
-28. Lock the console. Can you switch to another virtual terminal now? Urilock the
console.

O Copyright IBM Corp. 2001,2005 Exercise 3. Using the System 3-3


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

-29. Lock the graphical environment and then unlock it again.

Logging off
-30. Log off al1 users that are logged in at any TTY.

3-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise lnstructions With Hints


>> All hints are identified with the two greater-than symbols like this one.
>> All hints apply to al1 distributions equally, unless mentioned.

Logging in on a virtual terminal


In this section you are going to log in to the system using both text and graphical virtual
terminals.
- 1. If the install went correctly then you should now see a graphical login prompt. If this
is not the case, ask your instructor to fix this. (You learn how to do this yourself later
in the course.)
Verify that you indeed have seven different virtual terminals. Cycle through them by
pressing Alt-Fn, where n is the terminal number you want to access. Llse Ctrl-Alt-Fn
when you are in a graphical terminal.
>> ~Ctrl-Alt-F1>
>> <Alt-F2>
>> <Alt-F3>
>> <Alt-F4>
>> <Alt-F5>
>> <Alt-F6>
>> <Alt-F7>
-3. In your first virtual terminal (ttyl), log in to the system with your own username which
you also configured when installing the system.
>> ~Ctrl-Alt-F1>
>> Login: (your username)
>> Password: (your password)
-4. In your second virtual terminal (tty2), log in to the system as root. After having
logged in, look at the command prompt. Do you notice anything different from the
command prompt in the other virtual terminals?
>> <Alt-F2>
>> Login: root
>> Password: ibmlnx
-5. In your seventh virtual terminal (tty7), log in to the system with your own username
and password.
,>Login: (your username)
>> Password: (your password)
-6. Open a terminal window. Take a look at the command prompt. Does it differ from the
command prompt on ttyl ? Why or why not?

O Copyright IBM Corp. 2001,2005 Exercise 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 Exercises

>) On a Fedora or Red Hat system, a terminal window can be starteci from the
"Red Hat" button in the upper left hand corner; System Tools; Terminal. You
can also drag this icon to your quick launch bar, if you want to.
>> On a SuSE system, the terminal icon can be found in the launch bar.

Basic Commands
In this section we are going to execute some basic commands, in order to familinrize
yourself with the command syntax of Linux, and the fact that you are currently ori a
multi-user, multi-tasking system.
All commands in this section are executed on virtual terminal seven (the graphical login
prompt where you are logged in as yourself), using the terminal window you just opened,
unless specified otherwise.
-7. Change your password. Memorize this password because no one can find out your
password if you forget it.
>> $ passwd
>> Changing password for <username>
>> (current) UNlX password: (your current password)
>> New UNlX password: (your new password)
>> Retype new UNlX password: (your new password)
>, passwd: al1 authentication tokens updated successfully.
-8. Display the system's date.
>> $ date
-9. Display the whole calendar for the year 2005.
>> $ cal 2005
- 10. Display the month of January for the year 1999 and 99. Are 1999 and 99 the same?
>>$ cal 1 1999
>,$ cal 1 99
- 11. Generate a list of al1 users present on your system.
>> $ who
-0R-
>> $ finger
- 12. Display your login name.
>> $ whoami
-0R-
>> $ who am i
- 13. Display the login information of your own user account, and of root.
>> $ finger <username>

3-6 Linux Power User O Copyright IBM Corp. 2001,2005


Course materials may not be reproduced in whole or in part
without the prior written pern?issionof IBM.
Student Exercises

>> $ finger root


- 14. Clear your screen.
>> $ clear
- 15. Print the text Out to lunch on your display.
>> $ echo Out to lunch
- 16. Make sure you are willing to receive messages
>> $ mesg y
-17. Write the message Out to lunch to the display of root. Check whether root got the
message.
>> $ write root
>> Out to lunch
>> ~Ctrl-D>
>> ~Ctrl-Alt-F2>
>> ~Alt-F7>
- 18. Write the message Out to lunch to the display of al1 users. Check whether
everybody on your system got the message.
>> $ wall
>> Out to lunch
>> ~Ctrl-D>
>> ~Ctrl-Alt-F1>
>> ~Alt-F2>
>> eAlt-F7>

Keyboard and Mouse Tips


- 19. The bash shell has a command history function. View some of the ca~mmandsyou
have entered. Try to alter one of these commands, then run the comrnand again.

-20. Your terminal has a buffer that keeps track of the output of your comrnands. View
the output of the previous commands.
>> eshift page-up>
>> eshift page-down>
-21. Bash supports command and filename completion with the TAB character. Try to
use this feature, both on commands and on filenames.
>> $ pass<TAB>
>> $ cat /etc/passcTAB>

O Copyright IBM Corp. 2001,2005 Exercise 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 Exercises

-22. Both in a text terminal and an emulated terminal in the graphical desktop, try to
re-execute commands by scrolling up a little, selecting the command with the left
mouse button, and then pasting it onto the same terminal again with the middle
mouse button.
Also try this across different text and graphical terminals.
Note: SuSE does not enable gpm by default, so your mouse won't work in a text
terminal when you are using SuSE.

Using the history


-23. Use the history command to view the last 20 commands you typed.
>> $ history 20
-24. Execute one of the commands from the history list.
>> $ !2
-25. Execute the echo command again, this time changing the word "lunch" to "dinner".
>> $ !echo:s/lunch/dinner/
-26. Bash also supports searching in the history. Try this feature as well.
>> $ cCtrl-R>cle

Locking terminals
Note: Not al1 distributions install vlock and xlock by default. If vlock and xlock are not
installed, then you learn how to do that in Exercise 15 - Basic System Configuration.
-27. Lock a virtual terminal. Can you switch to another virtual terminal while this one is
locked? Unlock the terminal.
,>~Ctrl-Alt-F1>
» $ vlock
>> ~Alt-F2>
>> ~Alt-F1>
>> Type your password or the root password ibmlnx to unlock the terminal
-28. Lock the console. Can you switch to another virtual terminal now? Unlock the
console.
>> $ vlock -a
>> cAIt-F2>
>> Type your password or the root password ibmlnx to unlock the console.
-29. Lock the graphical environment and then unlock it again.
>> cCtrl-Alt-F7>
>> $ xlock

3-8 Linux Power User O Copyright IBM Corp. 2001,2005


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

-0R-
Click on the padlock ¡con
- OR
Use the "Lock Screen" function in your "Start" menu.
>> Type your password to unlock the graphical environment.

Logging off
-30. Log off al1 users that are logged in at any TTY.
>> <Ctrl-Alt-F1>
>> $ exit
>> <AIt-F2>
$ logout
>> <Alt-F7>
>> Click on the GNOME or KDE button and select "Log out"

END OF EXERCISE

O Copyright IBM Corp. 2001,2005 Exercise 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 Exercises

3-10 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise 4. Working with Files and Directories


What This Exercise Is About
This exercise provides the students with the opportunity to begin
working with directories and the files they contain.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Work with directories
Work with files
Work with files and directories recursively
Work with binary files

O Copyright IBM Corp. 2001,2005 Exercise 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.
Sfudent Exercises

Exercise lnstructions
Working with directories
- 1. If you are not logged in as yourself at tty7, log in now. Make sure you've got a
terminal window open.
-2. Check the directory you are placed in. What directory is this?
-3. Change your current directory to the root directory (1).
-4. Verify that you are in the root directory and then execute both a simple and a long
listing of the files in that directory.
-5. List al1 files in the current directory and list al1 files in the current directory and below.
Note: This command provides extensive output. Once you have seen enough, end
the command with the correct <Ctrl> sequence.
-6. Return to your home directory and list its contents including hidden files.
-7. Create a directory in your home directory called mydir. Then, issue the command to
view a long listing of your home directory and the -1mydir directory. (Do not show
the contents of the directories.) What is the size of each directory?
-8. Change to the mydir directory. Create two zero-length files called myfilel and
myfile2.
-9. lssue the command to view a long listing of the contents of the mydir directory.
What are the sizes of myfilel and myfile2?
- 10. Return to your home directory and use the I s -R command to view your directory
tree.
- 11. Try to remove the mydir directory. Does it work?
- 12. Go to the mydir directory once more and delete the two files in that directory. Then
go back up to your home directory and delete the mydir directory.

Working with files


- 13. Look at the contents of the Ietclpasswd file. The letclpasswd file contains a list of
al1 the users authorized to use the system.
- 14. Copy the /etc/passwd file to your home directory, and rename it to usersfile.
- 15. Split the usersfile into a number of smaller files, of 200 bytes each.
- 16. Make a long listing of al1 files in your home directory.

Working with files and directories recursively


- 17. Create a directory sub1 and create a directory sub2 in subl. Do this al1 with one
command.

4-2 Linux Power User O Copyright IBM Corp. 2001,2005


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
- 18. Go to the sub2 directory and create a file called myfile.
- 19. Go back to your home directory. Then make a copy of the whole subl directory tree
by the name of treel . Make a recursive listing of al1 files and directories in subl and
treel .
-20. You now have two directory trees, named subl and treel . Move the directory tree
treel into the subl subdirectory.
-21. List the contents of your home directory. Make a recursive listing of al1 files and
directories in the subl directory.

Working with binary files


-22. List the content of the file Ibinlls using od or hexdump.
-23. List al1 strings in the Ibinlls program.

END OF EXERCISE

O Copyright IBM Corp. 2001,2005 Exercise 4. Working with Files and I)irectories 4-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Sfudent Exercises

Exercise lnstructions With Hints


Working with directories
- 1. If you are not logged in as yourself at tty7, log in now. Make sure you've got a
terminal window open.
>> ~Ctrl-Alt-F7>
>> Login: cusername>
» Password: <password>
>> Open a terminal window
-2. Check the directory you are placed in. What directory is this?
>> $ pwd
-3. Change your current directory to the root directory (1).

-4. Verify that you are in the root directory and then execute both a simple and a long
listing of the files in that directory.
>> $ pwd
>> $ Is
>> $ Is -1
-5. List al1 files in the current directory and list al1 files in the current directory and below.
Note: This command provides extensive output. Once you have seen enough, end
the command with the correct <Ctrl> sequence.

-6. Return to your home directory and list its contents including hidden files.

-7. Create a directory in your home directory called mydir. Then, issue the command to
view a long listing of your home directory and the -1mydir directory. (Do not show
the contents of the directories.) What is the size of each directory?
>,$ mkdir mydir
>> $ IS -Id .
>> $ Is -Id mydir
-0R-
.
$ Is -Id mydir

4-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

-8. Change to the mydir directory. Create two zero-length files called myfilel and
myfile2.
>> $ cd mydir
>) $ touch myfilel
>> $ touch myfile2
-0R-
$ touch myfilel myfile2
-9. Issue the command to view a long listing of the contents of the mydir directory.
What are the sizes of myfilel and myfile2?

- 10. Return to your home directory and use the Is -R command to view your directory
tree.

- 11. Try to remove the mydir directory. Does it work?


>> $ rmdir mydir
-12. Go to the mydir directory once more and delete the two files in that directory. Then
go back up to your home directory and delete the mydir directory.
>> $ cd mydir
>> $ rm myfilel myfile2
» $ cd ..
>> $ rmdir mydir

Working with files


- 13. Look at the contents of the letclpasswd file. The letclpasswd file cointains a list of
al1 the users authorized to use the system.
>> $ cat letclpasswd
-0R-
$ more letclpasswd
-0R-
$ less letclpasswd
- 14. Copy the /etc/passwd file to your home directory, and rename it to usersfile.
>) $ cp letclpasswd -1usersfile
-0R-
$ cp /etc/passwd .
$ mv passwd usersfile
- 15. Split the usersfile into a number of smaller files, of 200 bytes each.

O Copyright IBM Corp. 2001,2005 Exercise 4. Working with Files and Uirectories 4-5
Course materials may not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Exercises

>> $ split -b 200 usersfile usersfile.


- 16. Make a long listing of al1 files in your home directory.
>> $ 1s -1 -
Working with files and directories recursively
- 17. Create a directory sub1 and create a directory sub2 in subl. Do this al1 with one
command.
>> $ mkdir -p sublIsub2
- 18. Go to the sub2 directory and create a file called myfile.
>> $ cd sub l /sub2
>> $ touch myfile
- 19. Go back to your home directory. Then make a copy of the whole sub1 directory tree
by the name of treel. Make a recursive listing of al1 files and directories in subl and
treel .
>> $ cd
>> $ cp -R subl treel
>> $ Is -1
>> $ IS -R sub1
>> $ Is -R treel
-20. You now have two directory trees, named sub1 and treel . Move the directory tree
treel into the subl subdirectory.
>> $ mv treel subl
-21. List the contents of your home directory. Make a recursive listing of al1 files and
directories in the subl directory.

Working with binary files


-22. List the content of the file /bin/ls using od or hexdump.
>> $ od Ibinlls
-0R-
$ hexdump /bin/ls
-23. List al1 strings in the /bin/ls program.
>> $ strings /bin/ls

END OF EXERCISE

4-6 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in par1
without the prior written perrnission of IBM.
rStudent Exercises

Exercise 5. File and Directory Permissions

What This Exercise Is About


This exercise provides the student the opportunity to work with file and
directory permissions.

What You Should Be Able to Do


At the end of the lab, you should be able to apply file and directory
permissions.

O Copyright IBM Corp. 2001,2005 Exercise 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 Exercises

Exercise lnstructions
Creating User Accounts
In order to demonstrate permissions in full, you need to create a few additional users, tuxl
and tux2, who both are members of the penguins group. For this, you need to execute a
few command that have not been covered in the course, and which normally need not be
executed by a regular user. They are covered in full in the LX03.
- 1. On tty3, log in as root
-2. Execute the following series of commands:
# groupadd penguins
# useradd -m -g penguins -c "Tux the Penguin (1)" tuxl
# useradd -m -g penguins -c "Tux the Periguin (2)" tux2
# passwd tuxl
New password: penguinl
Retype new password: penguinl
# passwd tux2
New password: penguin2
Retype new password: penguin2
-3. On ttyl , log in as tuxl with password penguinl , and on tty2, log in as tux2 with
password penguin2.

File and directory permissions


-4. Switch to VT 1, where you are logged in as tuxl , and look at the permissions on
your home directory.
-5. Switch to VT2, where you are logged in as tux2. Try to change to the home directory
of tuxl , or read the contents of the home directory of tuxl . Does this work?
On a Fedora or Red Hat system, both commands fail, since the default permissions
on a users home directory are set to rwx------. On a SuSE system, both command
succeed, since the default permissions are set to rwxr-xr-x.
-6. FedoraIRed Hat only: Switch to ttyl . Change the permissions on the home
directory of tuxl so that other users are allowed to read and access it. Then try to
access the directory again as tux2. Does this work now?
-7. As tux2, try to create and delete files in tuxl S home directory. Does this work?
-8. Switch once again to ttyl . Create a "bin" directory and copy the file /bin/ls in there,
renaming it to my-ls in the process.
-9. SuSE only: Log out and log in again. (SuSE only adds -1bin to your path if it exists
when you log in.)

5-2 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
:Student Exercises

- 10. Set the permissions on my-ls to rw-r-----, then try to execute it, both as tuxl and
tux2. Does this work? Why not?
- 11. Now set the permissions to rwxr-xr-x, then try to execute it once more, both as tuxl
and tux2. Does this work now?
- 12. Try to execute my-ls as tuxl and as tux2, and as yourself, but now with permissions
rw------- rw-rw----, rwx------ , rwx--x--- and rwx--x--x as well. What pe!rmissions are
required, at a minimum, for tuxl to execute my-ls? What permissions are required
for tux2? What permissions does your own user account require?

END OF EXERCISE

O Copyright IBM Corp. 2001,2005 Exercise 5. File and Directory Perrnissions 5-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise lnstructions With Hints


Creating User Accounts
In order to demonstrate permissions in full, you need to create a few additional users, tuxl
and tux2, who both are members of the penguins group. For this, you need to execute a
few command that have not been covered in the course, and which normally need not be
executed by a regular user. They are covered in full in the LX03.
- 1. On tty3, log in as root
>> ~Ctrl-Alt-F3>
>> Login: root
>> Password: ibmlnx
-2. Execute the following series of commands:
# groupadd penguins
# useradd -m -g penguins -c "Tux the Penguin (1)" tuxl
# useradd -m -g penguins -c "Tux the Penguin (2)" tux2
# passwd tuxl
New password: penguinl
Retype new password: penguinl
# passwd tux2
New password: penguin2
Retype new password: penguin2
-3. On ttyl, log in as tuxl with password penguinl, and on tty2, log in as tux2 with
password penguin2.
>, ~Alt-F1>
>> Login: tuxl
>> Password: penguinl
>> ~Alt-F2>
>> Login: tux2
>> Password: penguin2

File and directory permissions


-4. Switch to VT 1, where you are logged in as tuxl , and look at the permissions on
your home directory.

-5. Switch to VT2, where you are logged in as tux2. Try to change to the home directory
of tuxl , or read the contents of the home directory of tuxl . Does this work?
>> ~Alt-F2>
>> $ cd /home/tuxl

5-4 Linux Power User O Copyright IBM Corp. 2001,2005


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
5itudent Exercises

>> $ Is lhomeltuxl
On a Fedora or Red Hat system, both commands fail, since the default permissions
on a users home directory are set to rwx------. On a SuSE system, both commands
succeed, since the default permissions are set to rwxr-xr-x.
-6. FedoralRed Hat only: Switch to ttyl . Change the permissions on the home
directory of tuxl so that other users are allowed to read and access it. Then try to
access the directory again as tux2. Does this work now?
>> <Alt-F1>
>> $ chmod 755 lhomeltuxl
-0R-
$ chmod go+rx lhomeltuxl
>> <Alt-F2>
>> $ cd Ihomeltuxl
>> $ Is Ihomeltuxl
-7. As tux2, try to create and delete files in tuxl s home directory. Does this work?
>> $ touch testfile
-8. Switch once again to ttyl. Create a "bin" directory and copy the file /biin/ls in there,
renaming it to my-ls in the process.
>> <Alt-F1>
>> $ mkdir /homeltuxl/bin
>> $ cp Ibinlls Ihomeltuxllbin/my~ls
-9. SuSE only: Log out and log in again. (SuSE only adds -/bin to your path if it exists
when you log in.)
>> $ logout
>> Login: tuxl
>> Password: penguinl
- 10. Set the permissions on my-ls to rw-r-----, then try to execute it, both as tuxl and
tux2. Does this work? Why not?
>> $ chmod 640 Ihomeltuxllbinlmy~ls
-0R-
$ chmod u=rw,g=r,o= lhome/tuxllbinlmy~ls
>> $ my-ls
>> <Alt-F2>
>> $ lhomeltuxllbinlmy~ls
>> <Alt-F1>
- 11. Now set the permissions to rwxr-xr-x, then try to execute it once more, both as tuxl
and tux2. Does this work now?
>> $ chmod 755 /home/tuxl/binlmy~ls
- OR -

O Copyright IBM Corp. 2001,2005 Exercise 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 Exercises

$ chmod u=rwx,go=rx /home/tuxlIbinlmy-ls


>> $ my-1s
,><Alt-F2>
>> $ /home/tuxl /bin/my-ls
>> <Alt-F1>

- 12. Try to execute my-ls as tuxl and as tux2, and as yourself, but now with permissions
rw------- , rw-rw----, rwx------, rwx--x--- and rwx--x--x as well. What permissions are
required, at a minimum, for tuxl to execute my-ls? What permissions are i'equired
for tux2? What permissions does your own user account require?

END OF EXERCISE

5-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise 6. Linux Documentation


What This Exercise Is About
The purpose of this exercise is to give the students the opportunity to
explore and experiment with the man and info commantjs. Students
also read the FAQ and HOWTO documentation.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Use the man command
Use the info command
Locate and use other Linux documentation

O Copyright IBM Corp. 2001,2005 Exercise 6. Linux Dociimentation 6-1


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

Exercise lnstructions
Man Pages
- 1. If you are not already logged on, log in as tuxl at ttyl.
-2. Bring up the man pages for the man command. Read the text that follows ,to obtain
a better understanding of the functionality of the rnan command.
-3. Search for the string PAGER in the manual page of the rnan command.
-4. Use the cq> key to end the rnan command.
-5. Bring up the rnan page of the Is command. Move though the manual pages:
Go to the last page
Go to the previous page
Go to the first page
Type these commands while looking at the rnan page of 1s.
-6. Close the rnan command.
-7. Find out which manual pages al1 deal with passwd. Then view each pagel giving the
correct section number.
Note: If the rnan -k or apropos commands do not work, then you need to run the
makewhatis command as root. Normally, the makewhatis command is executed
each night automatically, but since your system is freshly installed, this might not
have happened yet.

lnfo command
-8. View the info documentation for the finger command. Are you actually reading info
documentation now?
-9. Move through this page by using the espace> and cbackspace> keys.
- 10. Read the help for the info command. Use the el> key to go back to the finger
information.
- 11. End the info command.
- 12. Read the info documentation of the info command. Use the menu by using the
<tab> and <m> keys.
- 13. info has a nice built-in tutorial. If you have spare time during this course, look at the
tutorial to see some of the advanced features of info.

Other Documentation

6-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

- 14. Make a listing of al1 directories in the /usr/share/doc directory. Browse come of these
directories to see what sort of information is available.
- 15. If the classroom systems have an lnternet connection, then take a looEc at the
http://www.tldp.org Web site. This is the main documentation Web site for Linux.
Note that in come classrooms come additional configuration of your Web browser
might be needed because the classroom is behind a socks or proxy-based firewall.
In this case, your instructor gives you additional instructions.

END OF EXERCISE

- -

O Copyright IBM Corp. 2001,2005 Exercise 6. Linux Documentation 6-3


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

Exercise lnstructions With Hints


Man Pages
- 1. If you are not already logged on, log in as tuxl at ttyl.
>> ~Ctrl-Alt-F1>
>> Login: tuxl
>> Password: penguinl (the password does not appear on the screen)
-2. Bring up the rnan pages for the rnan command. Read the text that follows to obtain
a better understanding of the functionality of the rnan command.
>> $ rnan rnan
-3. Search for the string PAGER in the manual page of the rnan command.

-4. Use the cq> key to end the rnan command.

-5. Bring up the rnan page of the Is command. Move though the manual pages:
Go to the last page
Go to the previous page
Go to the first page
Type these commands while looking at the rnan page of 1s.
>> $ rnan Is
>> Go to last page: G
>> Go to previous page: b
>> Go to first page: 1G
-6. Close the rnan command.

-7. Find out which manual pages al1 deal with passwd. Then view each page, giving the
correct section number.
Note: If the rnan -k or apropos commands do not work, then you need to run the
makewhatis command as root. Normally, the makewhatis command is executed
each night automatically, but since your system is freshly installed, this might not
have happened yet.
>> $ rnan -k passwd or apropos passwd
>> $ rnan 1 passwd
>> $ rnan 5 passwd

lnfo command

6-4 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Sfudent Exercises

-8. View the info documentation for the finger command. Are you actually reading info
documentation now?
>> $ info f inger
>> No. Look at the upper left corner of your screen. It says *manpages*, which
means that there is no info documentation for finger. If info cannot locate the
correct info document, it locates and displays its manual page. If there is no
manual page, info shows the top node.
-9. Move through this page by using the espace> and <backspace> keys.
>> <space> shows the next page of information
>> <backspace> show the previous page
- 10. Read the help for the info command. Use the <I>key to go back to the finger
information.
>> To enter help type ?
>> To quit the help type l.
-11. End the info command.

- 12. Read the info documentation of the info command. Use the menu by using the
<tab> and <m> keys.
>> info info
>> <tab>
» m
>> <enter>

>' q
- 13. info has a nice built-in tutorial. If you have spare time during this course, look at the
tutorial to see some of the advanced features of info.
>> Start the tutorial with the info command.
>> $ info
>> q

Other Documentation
-14. Make a listing of al1 directories in the /usr/share/doc directory. Browse some of these
directories to see what sort of information is available.
>> $ cd lusrlshareldoc
>> $ Is
>> Browse some directories and see what documentation is available.
>> $ cd
- 15. If the classroom systems have an lnternet connection, then take a look at the
http:l/www.tldp.org Web site. This is the main documentation Web site for Linux.

O Copyright IBM Corp. 2001,2005 Exercise 6. Linux Documentation 6-5


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

Note that in come classrooms some additional configuration of your Web browser
might be needed because the classroom is behind a socks or proxy-based firewall.
In this case, your instructor gives you additional instructions.

END OF EXERCISE

6-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise 7. A Tour through Linux


What This Exercise Is About
This exercise gives you an idea about the filesystem strilcture that is
common in most Linux distributions.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Describe the way the Linux filesystem is set up
Mount and unmount CD-ROMs and floppy disks

O Copyright IBM Corp. 2001,2005 Exercise 7. A Tour through Linux 7-1


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Exercises

Exercise lnstructions
Touring the Filesystem
- 1. On tty3, log in as root again.
-2. Make a list of the directories which are present in the root of your filesystem. Now
perform steps 3 and 4 for each of these directories.
-3. Run the du command on each directory. The du command displays the amount of
disk space the directory and al1 its subdirectories use (in kilobytes). Which directory
contains the most data? Why?
-4. cd to each directory and list its contents. If there are important subdirectories, list
their contents too. However, don't get carried away by trying to list everything. Try to
figure out what kind of files you find in that directory.

Accessing your floppy and CD-ROM


-5. View the contents of the Ietclfstab file. At which locations are your floppy and
CD-ROM going to be mounted?
-6. List the current contents of the directories that are going to be used as mountpoint
for your floppy and CD-ROM.
-7. Insert a CD in the CD-ROM drive and mount it. Then view the contents of the
mountpoint again.
Note: In some situations, the CD-ROM is automatically mounted. This is because
some distributions are configured to run the autorun service when a user is logged
in in a graphical environment (VT 7). This autorun service imitates the behavior of
MS Windows: It checks the CD-ROM drive every second, mounts a CD if one is
inserted, and tries to run the "autorun" executable if it is present on the CD. We don't
want that behavior right now, so make sure no user is logged in on VT 7.
-8. Try to eject the CD-ROM. Does this work? Unmount the CD-ROM, then try to eject
again. Does it work now?
-9. Switch to ttyl and log in as tuxl if you are not logged in already. Try to mount the
CD-ROM from here. Does this work? Why? Afterwards, unmount, eject and remove
the CD.

END OF EXERCISE

7-2 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Exercises

Exercise lnstructions With Hints


Touring the Filesystem
-1 . On tty3, log in as root again.
>> ~Ctrl-Alt-F3>
>> Login: root
>> Password: ibmlnx
-2. Make a list of the directories which are present in the root of your filesystem. Now
perform steps 3 and 4 for each of these directories.

-3. Run the du command on each directory. The du command displays the amount of
disk space the directory and al1 its subdirectories use (in kilobytes). Which directory
contains the most data? Why?
>> # du lbin
>> # du Iboot
>> etc.
-4. cd to each directory and list its contents. If there are important subdirectories, list
their contents too. However, don't get carried away by trying to list everything. Try to
figure out what kind of files you find in that directory.
>> # cd lbin
>> # Is -1
>> # cd Iboot
>> # Is -1
>> etc.

Accessing your floppy and CD-ROM


-5. View the contents of the Ietclfstab file. At which locations are your floppy and
CD-ROM going to be mounted?
>> # cat Ietclfstab
-6. List the current contents of the directories that are going to be used as mountpoint
for your floppy and CD-ROM.
,, Is Imedialfloppy
,, Is Imedialcdrom
-7. lnsert a CD in the CD-ROM drive and mount it. Then view the contents of the
mountpoint again.
Note: In some situations, the CD-ROM is automatically mounted. This is because
some distributions are configured to run the autorun service when a user is logged
in in a graphical environment (VT 7). This autorun service imitates the behavior of

O Copyright IBM Corp. 2001,2005 Exercise 7. A Tour thraugh Linux 7-3


Course rnaterials rnay not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

MS Windows: It checks the CD-ROM drive every second, mounts a CD if one ¡S


inserted, and tries to run the "autorun" executable if it is present on the CD. We don't
want that behavior right now, so make sure no user is logged in on VT 7.
» # mount lmedialcdrom
>> # cd lmedialcdrom
>> # Is -1
-8. Try to eject the CD-ROM. Does this work? Unmount the CD-ROM, then try to eject
again. Does it work now?
>> Press the eject button
>> # cd
>> # umount 1media1cdrom
>> Press the eject button again
-9. Switch to ttyl and log in as tuxl if you are not logged in already. Try to mount the
CD-ROM from here. Does this work? Why? Afterwards, unmount, eject and remove
the CD.
>> ~Ctrl-Alt-F1>
>> # mount lmedialcdrom
>> # umount Imedialcdrom
>> $ eject

END OF EXERClSE

7-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise 8. Editing Files


What This Exercise Is About
The purpose of this exercise is to give the students the opportunity to
create and edit files using the most common UNlX editor, vi, and to try
out a number of other editors that might be available.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Use vi to create and edit files
List a few other editors that are available on your system

--

O Copyright IBM Corp. 2001,2005 Exercise 8. Editing Files 8-1


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

Exercise lnstructions
Working with vi
1. If you aren't already logged in as t u x l at t t y l , log in now.
-2. Ensure that you are in your home directory. Create a file in your home directory
named vitest using vi.
Type the following text and the marine alphabet into the vitest file. Adding the
alphabet is an easy way to fill a couple of screens of information needed for later
use. This is a training session about the usage of the vi editor. We need come more
lines to learn the most common commands of the editor.
a alpha
b bravo
c charlie
. ..
(the rest of the marine alphabet)
x x-ray
y yankee
z zulu
-3. Return to command mode. Write and quit the file. Notice that as soon as you press
the colon (:), it appears below the last line of your input area. Once the buffer is
empty and the file is closed, you see a message giving the number of lines and
characters in the file.

Cursor Movement Keys


-4. Open vitest file again. Notice that the bottom line of the screen indicates the name
of the file and number of characters.
-5. Using the <h>, <j>, <k>, and <I> keys, practice moving the through the file.
-6. Use the appropriate vi commands to move through the text:
Move forward one page
Move back one page
Move the cursor to the first line on the screen
Move the cursor to the last line in the file
Move the cursor to the first line in the file
Move the cursor to line 5 of the file
Move the cursor to the end of the line
Move the cursor to the beginning of the line
-7. Change the file vitest so that after each letter of the alphabet a common first name is
added that starts with that letter. Make sure you use different methods for switching
from command mode to insert mode.

8-2 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Exercises

-8. Practice some more with al1 the commands that are listed on your cheat sheet.
-9. Save the file but do not exit vi.

Using set To Customize The Editing Session


- 10. Turn online numbering and set your tab stop to four.

Global search and replace


-11. Replace al1 spaces in your file with tabs.
- 12. Save your file.

Working with other editors


y 13. Your system has various other text mode and graphical editors available as well.
Start some of these to get acquainted with them.
Note: Not al1 editors listed in the course material may be available or installed on
your distribution.

END OF EXERCISE

O Copyright IBM Corp. 2001,2005 Exercise 8. Editing Files 8-3


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

Exercise lnstructions With Hints


Working with vi
- 1. If you aren't already logged in as t u x l at t t y l , log in now.
>> ~Ctrl-Alt-F1>
>> Login: t u x l
>> Password: penguinl
-2. Ensure that you are in your home directory. Create a file in your home directory
named vitest using vi.
Type the following text and the marine alphabet into the vitest file. Adding the
alphabet is an easy way to fill a couple of screens of information needed for later
use. This is a training session about the usage of the vi editor. We need some more
lines to learn the most common commands of the editor.
a alpha
b bravo
c charlie
s..

(the rest o£ the marine alphabet)


x x-ray
Y yankee
z zulu
>> $ c d
>> $ pwd
>> $ vi vitest
>> First type an <i> to enter input mode. Remember that vi starts in command
mode.
>> Then type the contents of the file.

-3. Return to command mode. Write and quit the file. Notice that as soon as you press
the colon (:), it appears below the last line of your input area. Once the buffer is
empty and the file is closed, you see a message giving the number of lines and
characters in the file.
>> Use the eesc> key to go from input mode to command mode.
>> Saving the file and closing vi can be done with one of these commands:
:wq or :x or ZZ

Cursor Movement Keys


-4. Open vitest file again. Notice that the bottom line of the screen indicates the name
of the file and number of characters.
>> $ vi vitest
-5. Using the ch>, <j>, ck>, and el> keys, practice moving the through the file.

8-4 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

» j down one line


>> k up one line
>> h left one character
>> I right one character
-6. Use the appropriate vi commands to move through the text:
Move forward one page
Move back one page
Move the cursor to the first line on the screen
Move the cursor to the last line in the file
Move the cursor to the first line in the file
Move the curcor to line 5 of the file
Move the cursor to the end of the line
Move the cursor to the beginning of the line
>> ~Ctrl-f>- Move forward one page
>> ~Ctrl-b>- Move back one page
>> H - Move the curcor to the first line on the screen
>> G - Move curcor to last line in the file
>> 1G or :1 and <enter> - Move cursor to first line in file
>> 5G or :5 and <enter> - Move cursor to line 5
>> $ - Move cursor to end of line
>> O (zero) or n - Move curcor to beginning of line
-7. Change the file vitest so that after each letter of the alphabet a commo'nfirst name is
added that starts with that letter. Make sure you use different methods for switching
from command mode to insert mode.
>> Use vi commands to add the words. Be cure to try the i, 1, a arid A
commands. The file should look like this afterwards:
a alpha Anne
b bravo Brad
c charlie Charles

-8. Practice some more with al1 the commands that are listed on your cheat sheet.
-9. Save the file but do not exit vi.

Using set to Customize the Editing Session


- 10. Turn online numbering and set your tab stop to four.
>> :set number
>> :set tabstop=4

O Copyright IBM Corp. 2001,2005 Exercise 8. Editing Files 8-5


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

Global search and replace


- 11. Replace al1 spaces in your file with tabs.
>> :%S / /<TAB>/g
(Where <TAB> is the TAB key. This shows up as "1 when you type it.)
- 12. Save your file.

Working with other editors


- 13. Your system has various other text mode and graphical editors available as well.
Start some of these to get acquainted with them.
Note: Not al1 editors listed in the course material may be available or installed on
your distribution.
>> $ pico vitest
>> $ mcedit vitest
>> $ hexedit vitest
>> ~Ctrl-Alt-F7>
>> $ gedit vitest
>> $ kedit vitest

END OF EXERCISE

8-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise 9. Shell Basics


What This Exercise Is About
This exercise provides an opportunity to get to know the basic features
of the Linux shell (bash).

What You Should Be Able to Do


At the end of the lab, you should be able to:
Use wildcards for file name expansion
Redirect standard in, standard out and standard error
Use pipes to provide the output of one process as input to another
process
Perform command grouping and line continuation

O Copyright IBM Corp. 2001,2005 Exercise 9. Shell Basics 9-1


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

Exercise lnstructions
Wildcards
- 1. If you are not logged in as tuxl at ttyl, log in now.
-2. Go to the letc directory and make a list of al1 files here.
-3. Use Is with wildcards to list file names:
That end with conf
That begin with a d or D
That contain an o in the fifth position
That contain the word tab (in any combination with capitals and lowercase
characters)
That end with a number
That do not end with a number
(Note that wildcard expansion is done by the shell. If one of the filenames that
matches is a directory name, then Is by default lists the contents of that directory,
instead of the filename itself. To prevent this, use the -d option.)
-4. What happens if you execute the command Is -d ?[!y]*[e-f]? What would the
shortest filename be that can match? Execute this command to verify your answer.
-5. Return to your home directory.

Redirection
-6. Use the cat command and redirection to create a file called junk containing a few
lines of text. When you have typed a few lines, end your input to the cat command
and return to the shell prompt. Then view the contents of the file you just created.
-7. Append more lines to the junk file using redirection. Then view the contents of the
file junk and check if al1 the lines you saved in this file are there.

Pipes, Tees, and Filters


-8. Count the number of files in your current directory. Use a pipe, do not count the files
manually.
-9. Does Is > tempfile ; wc -1 tempfile ; rm tempfile do the same thing as the pipe you
made in the previous command? Why or why not?
- 10. Use the Is command and save the output in a file called tempfile2 before you count
the files.
- 11. Use the sed command to alter the output of the Is -1 letcl command, so that it looks
like you own al1 files in Jetc. Execute this both with and without the "global" option.
What is the difference?

9-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

-12. Use the awk command to display the first and ninth column of the output of the Is -1
/etc/ command.
-13. Use the tac command to display the output of the Is command in revei'se order.
- 14. Use the nl command to number the lines of tempfile.
-15. Use the pr command to format tempfile for the printer.
-16. Combine al1 usersfile parts from exercise 4 into one big file, called usersfile5. Check
to see if this file is identical to the original usersfile.

Command Grouping
y 17. On the same command line, display the current system date and al1 the users that
are logged in, together with some explaining comments, and cave al1 this to one file
after numbering the lines. Check your output.

Process Environment
- 18. Display al1 your variables that are defined in your current process environment. Also
display al1 variables that are currently exported.
- 19. Create a variable x and set its value to 10. Check the value of the variable. Again,
display al1 your current variables.
-20. Create a subshell. Check to see what value variable x holds in the subshell. What is
the value of x? List the subshell's current variables. Do you see a listing for
x?
-21. Set the value of x to 500 and go back to your parent process. What is the current
value of x? W hy?
-22. Make sure that child processes inherit the variable x. Verify this by creating a
subshell and checking the value of variable x. After this, exit your subshell.

EN0 OF EXERCISE

O Copyright IBM Corp. 2001,2005 Exercise 9. Shell Basics 9-3


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Exercises

Exercise lnstructions With Hints

- 1. If you are not logged in as tuxl at ttyl, log in now.


>>~Ctrl-Alt-F1>
>>Login: tuxl
,>Password: penguinl (the password does not appear on the screen)
-2. Go to the Ietc directory and make a list of al1 files here.

-3. Use Is with wildcards to list file names:


that end with conf
that begin with a d or D
that contain an o in the fifth position
that contain the word tab (in any combination with capitals and lowercase
characters)
that end with a number
that do not end with a number
(Note that wildcard expansion is done by the shell. If one of the filenames that
matches is a directory name, then Is by default lists the contents of that directory,
instead of the filename itself. To prevent this, use the -d option.)

-4. What happens if you execute the command Is -d ?[!y]*[e-f]? What would the
shortest filename be that can match? Execute this command to verify your answer.

-5. Return to your home directory.

Redirection
-6. Use the cat command and redirection to create a file called junk containing a few
lines of text. When you have typed a few lines, end your input to the cat command
and return to the shell prompt. Then view the contents of the file you just created.
>> $ cat > junk

9-4 Linux Power User O Copyright IBM Corp. 2001,2005


Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
!3tudent Exercises

>> Type some lines of information


>> ~Ctrl-D>(At the beginning of a new line)
>> $ cat junk
-7. Append more lines to the junk file using redirection. Then view the contents of the
file junk and check if al1 the lines you saved in this file are there.
>> $ cat >> junk
>> Type some lines of information
>> ~Ctrl-D>(At the beginning of a new line)
>> $ cat junk

Pipes, Tees, and Filters


-8. Count the number of files in your current directory. Use a pipe, do not count the files
manually.

-9. Does Is > tempfile ; wc -1 tempfile ; rm tempfile do the same thing as the pipe you
made in the previous command? Why or why not?
>> Almost, but it counts tempfile too, so it counts one file too many.
>> $ Is > tempfile
>> $ more tempfile
-10. Use the Is command and save the output in a file called tempfile2 before you count
the files.
>> $ Is 1 tee tempfile2 1 wc -1
- 11. Use the sed command to alter the output of the Is -1 letcl command, so that it looks
like you own al1 files in Ietc. Execute this both with and without the "global" option.
What is the difference?
>> $ Is -1 letc 1 sed slroot/tuxll
>> $ Is -1 letc 1 sed slrootltuxllg
- 12. Use the awk command to display the first and ninth column of the output of the Is -1
letcl command.
>> $ Is -1 Ietc 1 awk '{print $1 " " $9)'
- 13. Use the tac command to display the output of the Is command in reverse order.
>> $ Is 1 tac
- 14. Use the nl command to number the lines of tempfile.
>> $ nl tempfile
- 15. Use the pr command to format tempfile for the printer.
>> $ pr tempfile

O Copyright IBM Corp. 2001,2005 Exercise 9. Shell Basics 9-5


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

- 16. Combine al1 usersfile parts from exercise 4 into one big file, called usersfile5. Check
to see if this file is identical to the original usersfile.
>> - -
$ SU <username> where <username> is your username
>> $ cat usersfile.* > usersfile5
>> $ diff usersfile usersfile5

Command Grouping
- 17. On the same command line, display the current system date and al1 the users that
are logged in, together with some explaining comments, and save al1 this to one file
after numbering the lines. Check your output.
>> $ ( date ; who ) 1 nl > users
>> $ cat users

Process Environment
- 18. Display al1 your variables that are defined in your current process environment. Also
display al1 variables that are currently exported.
>> $ set 1 less
>> $ env 1 less
- 19. Create a variable x and set its value to 10. Check the value of the variable. Again,
display al1 your current variables.
>> $ x=10
>> $ echo $x
>> $ set 1 less
>> $ env ( less
-20. Create a subshell. Check to see what value variable x holds in the subshell. What is
the value of x? List the subshell's current variables. Do you see a listing for
x?
>> $ bash
>> $ echo $x
>> You should see no output, only an empty line.
>> $ set 1 less
>> You should not see a listing for x.
-21. Set the value of x to 500 and go back to your parent process. What is the current
value of x? W hy?-
>> $ x=500
>> $ exit
>> $ echo $x

9-6 Linux Power User O Copyright IBM Corp. 2001,2005


Course materials rnay not be reproduced in whole or in part
without the prior written permission of IBM.
!Student Exercises

-22. Make sure that child processes inherit the variable x. Verify this by creating a
subshell and checking the value of variable x. After this, exit your subshell.
>> $ export x
>> $ env ) less
>> $ bash
>> $ echo $x
$ exit

EN0 OF EXERCISE

O Copyright IBM Corp. 2001,2005 Exercise 9. Shell Basics 9-7


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

9-8 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Exercises

Exercise 10. Working with Processes

What This Exercise Is About


This exercise familiarizes the students with process mariipulation and
process control.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Monitor processes
Change and understand the process environment
Control jobs
Terminate processes

O Copyright IBM Corp. 2001,2005 Exercise 10. Working with Processes 10-1
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Exercises

Exercise lnstructions
Listing Processes
- 1. Log in at ttyl as tuxl.
-2. Check the pid of your log in environment and then create a subshell by entering
bash. What is the process ID of the subshell? Is it different from your login process?

-3. Enter the command Is -R 1 >outfile 2>/dev/null& and then show the processes that
you are running in the system. Which processes are running?
Note: This command is explained in full in the next units.

-4. While the Is command is still running, run the pstree command. (It might be
necessary to restart the Is command.)
-5. Log in as tux2 on tty2 and run vi tux2-file.
-6. Go back to ttyl and show al1 the processes in your system. If necessary, look in the
man pages and info to find the correct options to show al1 processes running in your
system.
Look for your own processes as well as the processes of tux2.
-7. Again run the Is -R / >outfile 2>/dev/null & command and then exit your current
process. List the processes you are running. What happens to processes if you kill
their parent process?

Job Control
-8. Using vi or another editor, create the file named myclock in your bin directory with
the following contents:
while true
do
date
sleep 1 0
done
Make the script executable.
-9. Run the script myclock. Run this script in the foreground.
- 10. Suspend the job you just started.

10-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

-11. List al1 the jobs that you are running on the system and restart the above job in the
background.
-12. List al1 users that are logged in. Bring the job back to the foreground, wait until you
get a timestamp, and then exit the job.

Terminating a Process
- 13. Execute the myclock script again, this time in the background.
-14. List al1 your processes and kill the sleep process. What happened?
-15. Now stop the shell script myclock.

END OF EXERCISE

O Copyright IBM Corp. 2001,2005 Exercise 10. Working with Processes 10-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Sfudent Exercises

Exercise lnstructions With Hints


Listing Processes
- 1. Log in at ttyl as tuxl.
>> ~Ctrl-Alt-F1>
>> Login: tuxl
>> Password: penguinl (The password does not appear on screen)
-2. Check the pid of your log in environment and then create a subshell by entering
bash. What is the process ID of the subshell? Is it different from your login process?

>> $ echo $$
>> $ bash
>> $echo $$
>> Yes, al1 processes in your system have a unique process ID (PID). So the PID
of your login shell and your subshell have to be different. If they are equal you
really have a problem ;-).
Enter the command Is -R 1 >outfile 2>ldevlnull& and then show the processes that
you are running in the system. Which processes are running?
Note: This command is explained in full in the next units.

>> $ Is -R 1 > outfile 2>/dev/null &


>> $ ps
-0R-
$ ps -aux (for more information about your processes)
-4. While the Is command is still running, run the pstree command. (It might be
necessary to restart the Is command.)
>> $ pstree
-5. Log in as tux2 on tty2 and run vi tux2-file.
>> ~Alt-F2>
>> Login: tux2
>> Password: penguin2 (the password does not appear on the screen)
>> $ vi tux2-file
-6. Go back to ttyl and show al1 the processes in your system. If necessary, look in the
man pages and info to find the correct options to show al1 processes running in your
system.
Look for your own processes as well as the processes of tux2.

10-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

>> ~Alt-F1>
>> $ ps -aux 1 less
-7. Again run the Is -R 1 >outfile 2>ldev/null & command and then exit your current
process. List the processes you are running. What happens to processes if you kill
their parent process?
-

>> $ Is -R / >outfile 2>/dev/null &


>> $ exit
>> $ ps -aux
>> $ pstree
>> If the parent process dies, the child processes are transferred to a new parent
process, init.

Job Control
-8. Using vi or another editor, create the file named myclock in your bin directory with
the following contents:
while true
do
date
sleep 10
done
Make the script executable.
>,$ cd -1bin
>> $ vi myclock
>> $ chmod +x myclock
-9. Run the script myclock. Run this script in the foreground.
>> $ myclock
- 10. Suspend the job you just started.
>> <Ctrl-Z>
- 11. List al1 the jobs that you are running on the system and restart the above job in the
background.
>> $ jobs
>> $ bg %1
- 12. List al1 users that are logged in. Bring the job back to the foreground, wait until you
get a timestamp, and then exit the job.
>> $ who
>> $ fg %1
>> ~Ctrl-C>

O Copyright IBM Corp. 2001,2005 Exercise 10. Working with Processes 10-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Terminating a Process
-13. Execute the myclock script again, this time in the background.
>> $ myclock &
- 14. List al1 your processes and kill the sleep process. What happened?
>> $ ps
>> $ kill cPID>
Where <PID> is the process ID of the sleep command.
>> You received a new timestamp immediately after the kill command ran.
>> myclock is a shell script that displays a timestamp every 10 seconds. When
you kill the sleep process, there is no process to wait for. The script c:ontinues
and shows you another timestamp.
>> Killing processes started from a shell script does not kill the shell script itself.
- 15. Now stop the shell script myclock.
>> $ kill cPID>
Where PID is the process ID of the process that runs the myclock script.
(hint: look for a second instance of bash)

END OF EXERCISE

10-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise 11. Linux Utilities


What This Exercise Is About
The purpose of this exercise is to become familiar with come of the
many helpful tools available with Linux.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Search for files that meet specific criteria
List specific columns of a file
Search text files for lines that match a pattern
Sort lines in a file
Display the first or last few lines of a file
Find out where executables are located
Compress files and decompress them

O Copyright IBM Corp. 2001,2005 Exercise 11. Linux Utilities 11-1


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

Exercise lnstructions
Working with find and locate
- 1. Log in as tuxl at ttyl, if you aren't already.
-2. Find and display al1 files and directories in your home directory.
-3. Find al1 files in your system that begin with the string abc and have Is -1
automatically executed on each file name found. Discard al1 errors.
-4. Repeat the previous command but interactively prompt the user to display the long
listing on each file. Do not discard errors, since stderr is used to display the prompt.
-5. Find al1 files starting from Iusr that are owned by the user Ip.
-6. Modify the last command to count the number of files on the whole system owned by
Ip. Now alter the command so that you don't get error messages on your screen.
-7. Find al1 directories in your system and cave this list in the file all.directories. The
error message can be sent to the bit bucket. Execute this command in the
background.
-8. FedoraIRed Hat only: Use the locate command to locate al1 files that match the
string "passwd".
Note: SuSE does not install the locate command by default. You learn how to do this
in Exercise 15 - Basic System Configuration.

Working with cut


-9. Display the contents of the Ietclpasswd file.
- 10. Only show the user name and the home directory of the users listed in /etc/passwd.
- 11. Show the name and the members of al1 groups listed in Ietclgroup.
- 12. List only the type, size and name of files in the current directory.

Working with grep


- 13. Find al1 lines in the letclpasswd that begin with the letter s.
- 14. Repeat the search in the previous instruction, but this time display only the number
of lines that contain the pattern.
- 15. Find al1 processes running on the system, owned by user tuxl or tux2.

Working with sort


- 16. Display the contents of the /etc/passwd file in alphabetical order

11-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

-17. Display the contents of /etc/passwd again, but now sorted on the home directory
field.

Working with head and tail


- 18. Display the first 10 lines of the /etc/passwd file.
- 19. Display the last 6 lines of the /etc/passwd file.
-20. The tail command is also handy for stripping out header information from the output
of a command. First, list the processes currently running on your system. Notice the
headings. Next, display the processes running on your system excluding the header
information.

Working with type, which and whereis


-21. Find out where the passwd command is stored. Locate the manual pages and
source code for this command.

Working with gzip, gunzip and zcat


-22. Create a big file named big in your home directory, for instance by capturing the
output of the 1s -IR 1 command. What is the size of big?
-23. Make the file twice as large.
-24. Note the size of big.
Compress the big file. What is the new size of the file and what ¡S its inew name?

-25. Look at the contents of the big.gz file.


-26. Restore the old big file. What is the size of big and what is its name?

END OF EXERCISE

O Copyright IBM Corp. 2001,2005 Exercise 11. Linux Utilities 11-3


Course materials rnay not be reproduced in whole or in part
without the prior written permission of IBM.
Sfudent Exercises

Exercise lnstructions With Hints


Working with find and locate
1. Log in as tuxl at ttyl, if you aren't already.
>> ~Alt-F1>
>> Login: tuxl
>> Password: penguinl (the password does not appear on the screen)
-2. Find and display al1 files and directories in your home directory.
>> $ find $HOME
-0R-
$ cd ; find.
-3. Find al1 files in your system that begin with the string abc and have Is -1
automatically executed on each file name found. Discard al1 errors.
>> touch abcdef
>> $ find 1 -name 'abc*' -exec Is -1 {) \; 2>ldevlnull
-4. Repeat the previous command but interactively prompt the user to display the long
listing on each file. Do not discard errors, since stderr is used to display the prompt.
>) $ find 1 name 'abc*' -ok Is -1 {) \;
-5. Find al1 files starting from lusr that are owned by the user root.
)) $ find lusr -user root
-6. Modify the last command to count the number of files on the whole system owned by
root. Now alter the command so that you don't get error messages on your screen.
>> $ find 1-user root 1 wc -1
>> $ find 1-user root 2>/dev/null 1 wc -1
-7. Find al1 directories in your system and save this list in the file all.directories. The
error message can be sent to the bit bucket. Execute this command in the
background.
>> $ find 1 -type d >all.directories 2>/dev/null &
-8. FedoraIRed Hat only: Use the locate command to locate al1 files that match the
string "passwd".
Note: SuSE does not install the locate command by default. You learn how to do this
in Exercise 15 - Basic System Configuration.
>> $ locate passwd

Working with cut


-9. Display the contents of the Ietclpasswd file.

11-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

>> $ cat Ietclpasswd


-10. Only show the user name and the home directory of the users listed in letclpasswd.
>> $ cut -f1,6 -d: Ietclpasswd
- 11. Show the name and the members of al1 groups listed in letclgroup.
>> $ cut -f1,4 -d: letclgroup
- 12. List only the type, size and name of files in the current directory.
>> $ IS -1 1 C U -cl-1,31-42,49-
~

Working with grep


- 13. Find al1 lines in the letclpasswd that begin with the letter s.
>> $ grep Asletclpasswd
- 14. Repeat the search in the previous instruction, but this time display only the number
of lines that contain the pattern.
>> $ grep -c As Ietclpasswd
- 15. Find al1 processes running on the system, owned by user tuxl or tux2.
>> $ ps aux ( egrep "tuxl ( t u x 2

Working with sort


- 16. Display the contents of the Ietclpasswd file in alphabetical order.
)) $ sort letclpasswd
-17. Display the contents of letclpasswd again, but now sorted on the horne directory
field.
>> $ sort -t: +5 letclpasswd

Working with head and tail


- 18. Display the first 10 lines of the letclpasswd file.
>> $ head Ietclpasswd
-19. Display the last 6 lines of the letclpasswd file.
>> $ tail -6 letclpasswd
-20. The tail command is also handy for stripping out header information from the output
of a command. First, list the processes currently running on your system. Notice the
headings. Next, display the processes running on your system excluding the header
information.

O Copyright IBM Corp. 2001,2005 Exercise 11. Linux Utilities 11-5


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

>> $ ps
>> $ ps 1 tail +2

Working with type, which and whereis


-21. Find out where the passwd command is stored. Locate the manual pages and
source code for this command.
>> $ type passwd
>> - OR -

>> $ which passwd


>> - OR -

,>$ whereis passwd

Working with gzip, gunzip and zcat


-22. Create a big file named big in your home directory, for instance by capturirig the
output of the Is -IR / command. What is the size of big?
>> $ Is -IR 1 > big 2>&1
>> $ Is -1 big
-23. Make the file twice as large.
>> $ cp big big2
>> $ cat big2 >> big
>> $ rm big2
-24. Note the size of big.
Compress the big file. What is the new size of the file and what ¡S its new iiame?

>> $ IS -1 big
>> $ gzip big
,>$ Is -1 big*
>> The new name is big.gz.

-25. Look at the contents of the big.gz file.


>> $ zcat big
-26. Restore the old big file. What is the size of big and what is its name?
>> $ gunzip big
>> $ Is -1 big*
>> The name is big again.

END OF EXERCISE

11-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise 12. Shell Scripting


What This Exercise Is About
After you have been using Linux for a while, you find certain
characteristics of your environment that you would like to customize
along with some tasks that you execute regularly that you would like to
automate.
This exercise introduces you to some of the more common constructs
used to help you write shell scripts in order to customize and automate
your computing environment.

What You Should Be Able to Do


At the end of the lab, you should be able to:
List common constructs used in writing shell scripts
Create and execute simple shell scripts

lntroduction
You need no programming experience to perform this exercise. Refer
to the unit in the Student Notebook for help with the syntax of
constructs when creating the shell scripts in this exercise.

O Copyright IBM Corp. 2001,2005 Exercise 12. Shell Scripting 12-1


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

Exercise lnstructions
Working with Positional Parameters
- 1. If you are not logged in as tuxl at ttyl, log in now.
-2. Create a shell script named parameters that echoes the five parameters that follow
using predefined special variables set by the shell to fill in the blanks. Execute the
script using the positional parameters 10 100 1000.

Conditional Execution
-3. Using conditional execution, create a shell script named checkfile that checks to
see if the file named parameters exists in your directory. If it exists, use a command
to show the contents of the file. Execute the script.
-4. Modify the checkfile script and change the name of the file from parameters to
noname (check to ensure that you do NOT have a file by this name in your current
directory). Also, using conditional execution, if the Is command was NOT
successful, display the error message, "The file was not found". Execute the script.
-5. Modify the checkfile script to accept a single parameter from the command line as
input to the Is and cat commands. Execute the script twice, once using the file
named parameters and again using the file named noname.
-6. Execute the checkfile script again, but this time with no parameters. What
happens? Modify the script so that this does not appear again.

Loops
-7. Using the for loop, modify the checkfile script to accept multiple files as input from
the command line instead of just one. If the files are found, display al1 of them. If the
files are not found, display an error message showing al1 file names that were not
found. Look in your directory and note a few valid file names that you can use as
input. Execute the script using valid and invalid file names.
-8. Now do the same thing, but use a while loop in combination with the shift
command.

Arithmetic
-9. From the command line, display the results of multiplying 5 times 6.
- 10. Now create a shell script named math to multiply any two numbers when entered as
input from the command line. Execute the script multiplying 5 times 6. Experiment
with any other two numbers.

12-2 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Exercises

lntegration Exercise
-11. Use the knowledge you gained in this course to write a script that accepts a
directory name as a parameter and calculate the total size of the files in this
directory.

END OF EXERCISE

O Copyright IBM Corp. 2001,2005 Exercise 12. Shell Scripting 12-3


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

Exercise lnstructions With Hints


Working with Positional Parameters
- 1. If you are not logged in as tuxl at ttyl, log in now.
>> ~Ctrl-Alt-F1>
>> Login: tuxl
>> Password: penguinl
-2. Create a shell script named parameters that echoes the five parameters ttiat follow
using predefined special variables set by the shell to fill in the blanks. Execute the
script using the positional parameters 10 100 1000.
>> $ vi parameters
echo The name of this shell script is $0.
echo The first parameter passed is number $1.
echo The second parameter passed is number $2.
echo The third parameter passed is number $3.
echo Altogether there were $# parameters passed.
>> $ chmod +x parameters
>> $ Jparameters 10 100 1000

Conditional Execution
-3. Using conditional execution, create a shell script named checkfile that checks to
see if the file named parameters exists in your directory. If it exists, use a command
to show the contents of the file. Execute the script.
>> $ vi checkfile
[ -f parameters 1 && cat parameters
>> $ chmod +x checkfile
>> $ ./checkfile
-4. Modify the checkfile script and change the name of the file from parameters to
noname (check to ensure that you do NOT have a file by this name in your current
directory). Also, using conditional execution, if the Is command was NOT
successful, display the error message, "The file was not found". Execute the script.
>> $ vi checkfile
[ -f nofile 1 && cat nofile 1 1 echo "The file was not faund1I
>> $ ./checkfile
-5. Modify the checkfile script to accept a single parameter from the command line as
input to the Is and cat commands. Execute the script twice, once using the file
named parameters and again using the file named noname.
>> $ vi checkfile
[ -f $1 1 && cat $1 1 1 echo $1 was not found
>> $ ./checkfile parameters

12-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

>> $ ./checkf ile noname


-6. Execute the checkfile script again, but this time with no parameters. What
happens? Modify the script so that this does not appear again.
>> $ ./checkfile
)) $ vi checkfile
[ -f 11$111 1 && cat 11$1"1 1 echo "$1 was not foundu
,, $ ./checkfile

Loops
-7. Using the for loop, modify the checkfile script to accept multiple files as input from
the command line instead of just one. If the files are found, display al1 of them. If the
files are not found, display an error message showing al1 file names that were not
found. Look in your directory and note a few valid file names that you can use as
input. Execute the script using valid and invalid file names.
,, $ vi checkfile
for x in $*
do
[ - f "$xl1 1 && cat I1$xu1 1 echo "$x was not foundu
done
>,$ Is
>> $ ./checkfile filename filename filename

(Where filename is replaced by valid and invalid file names from your
directory)
-8. Now do the same thing, but use a while loop in combination with the shift
command.
,, $ vi checkfile
while [ ! - z "$111 1
do
1 1 echo "$1 was not foundN
[ -f "$1" 1 && cat 11$111
shift
done

A rithmetic
-9. From the command line, display the results of multiplying 5 times 6.
>,$ echo $(( 5 * 6 ))
- 10. Now create a shell script named math to multiply any two numbers when entered as
input from the command line. Execute the script multiplying 5 times 6. Experiment
with any other two numbers.

O Copyright IBM Corp. 2001,2005 Exercise 12. Shell Scripting 12-5


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

>> $ vi math
echo $ ( ( $1* $2 ))
>> $ chmod +x math
,>$ .Imath 5 6

lntegration Exercise
- 11. Use the knowledge you gained in this course to write a script that accepts a
directory name as a parameter and calculate the total size of the files in this
directory.
>> $ vi sum
if [ -d "$1"1

sm=o
f o r i i n $ ( l s -1 "$1" 1 cut -c32-42)
do
sm='exprfl$sumll + H $ i H '

done
echo "The total s i z e of files i n $1 i s $sm."

>> $ ./sum ltmp

END OF EXERCISE

12-6 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise 13. The Linux GUI


What This Exercise Is About
This exercise provides an opportunity to get acquainted with the two
main Linux desktop environments: KDE and GNOME.

What You Should Be Able to Do


At the end of this exercise, students should be able to:
Start X
Work with GNOME
Work with KDE
List and compare various applications within GNOME and KDE

O Copyright IBM Corp. 2001,2005 Exercise 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 Exercises

Exercise lnstructions
Starting the GUI
-1 . Log in as root on tty4.
-2. Edit the Ietclinittab file and make sure the default runlevel is 3.
-3. Reboot your system. Does the graphical environment get started?
-4. Log in as tuxl on ttyl and start X with the startx command.
-5. End your X environment, then log out and log in as root.
-6. Edit the Ietclinittab file again and set the default runlevel to 5. Then reboot the
system again. Did the graphical environment start?

Working with GNOME and KDE


-7. Login in the graphical environment using your own name.
-8. Both the GNOME and KDE project have delivered various applications sucti as word
processors, file managers, text editors and so forth as standard part of the
codebase. These applications are typically direct competitors of the corresponding
applications on an MS-Windows platform.
A default Linux installation installs a lot of these applications, and you can download
more from the GNOME andlor KDE Web site.
Browse around in both the GNOME and KDE desktop environments and try to
identify the name of the application that fulfills a certain function. (You can retrieve
the name of the application by opening a terminal window and executing ttie ps
command.) Some names have already been filled in as an example.
To switch between KDE and GNOME, use your display managers (login prompt)
menu.

1 Function 1 GNOME 1 KDE I


Window manager
File manager
Text editor(s)
sawfish, metacity
nautilus
kwin
konqueror 4
lnternet dialer
Email client
Web browser
CD Player
I
13-2 Linux Power User O Copyright IBM Corp. 2001,2005
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Exercises

MP3 Player 7
Sound mixer
I I

7
Word processor 7
Spreadsheet
1 Presentation package
7
1 Photolbitmap editor
- -

Vector oriented graphics


editor
Clipboard
-9. In both desktop environments, explore the themes capabilities. After setting a theme
in KDE, start a GNOME application, and vice versa. Does this work?
- 10. In KDE, try to start a GNOME application and vice versa. Does this work? Try to cut
and paste between KDE and GNOME applications. Does this work?

END OF EXERCISE

O Copyright IBM Corp. 2001,2005 Exercise 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 Exercises

Exercise lnstructions With Hints


Starting the GUI
- 1. Log in as root on tty4.
>> cCtrl-Alt-F4>
>> Login: root
>> Password: ibmlnx
-2. Edit the Ietclinittab file and make sure the default runlevel is 3.
>> # vi Ietclinittab
>> Make cure the initdefault line looks like this:
id:3:initdefault:
-3. Reboot your system. Does the graphical environment get started?
>> # reboot
-4. Log in as tuxl on ttyl and start X with the startx command.
>> Login: tuxl
>> Password: penguinl
>> $ startx
-5. End your X environment, then log out and log in as root.
,>cCtrl-Alt-Backspace>
,>$ logout
>> Login: root
>> Password: ibmlnx
-6. Edit the Ietclinittab file again and set the default runlevel to 5. Then reboot the
system again. Did the graphical environment start?
>> # vi Ietclinittab
>> Make sure the initdefault line looks like this:
id:5:initdefault:
>> # reboot

Working with GNOME and KDE


-7. Login in the graphical environment using your own name.
-8. Both the GNOME and KDE project have delivered various applications sucti as word
processors, file managers, text editors and so forth as standard part of the
codebase. These applications are typically direct competitors of the corresponding
applications on an MS-Windows platform.
A default Linux installation installs a lot of these applications, and you can clownload
more from the GNOME andlor KDE Web site.

13-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

Browse around in both the GNOME and KDE desktop environments and try to
identify the name of the application that fulfills a certain function. (You can retrieve
the name of the application by opening a terminal window and executing the ps
command.) Some names have already been filled in as an example.
To switch between KDE and GNOME, use your display managers (login prompt)
menu.

Function 1 GNOME 1 KDE


Window manager 1 sawfish, metacity 1 kwin
File manager 1 nautilus 1 konqueror
Text editor(s)
-

lnternet dialer
1
Email client
Web browser
1
CD Player
MP3 Player
Sound mixer 1
Word processor
Spreadsheet
Presentation package
Phototbitmap editor
Vector oriented graphics
editor
Clipboard
2
-9. In both desktop environments, explore the themes capabilities. After setting a theme
in KDE, start a GNOME application, and vice versa. Does this work?
- 10. In KDE, try to start a GNOME application and vice versa. Does this work? Try to cut
and paste between KDE and GNOME applications. Does this work?

O Copyright IBM Corp. 2001,2005 Exercise 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 Exercises

13-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise 14. Customizing the User Environment


What This Exercise Is About
When users log in, they generally prefer their environment to be
customized to meet their specific needs. In this exercise, the students
customize their environment with some very useful functions that are
invoked every time they log in.

What You Should Be Able to Do


At the end of the lab, you should be able to:
Customize the .bashjrofile and .bashrc files
Set alias definitions
Alter umask values

O Copyright IBM Corp. 2001,2005 Exercise 14. Custornizing the User Environment 14-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise lnstructions
Customizing the shell environment
- 1. If you are not logged in, log in as t u x l at t t y l .
-2. Change the appropriate file to change your environment each time you log in. Make
sure that you have the following functions when you log in:
Change the primary prompt to show you the complete path of the current
directory.
Display a message stating your login name and the date you logged in.
Define an alias num that shows you how many users are logged in at that
moment.
Set the variable cheese to gouda.
-3. Log out and log in again. Check if the functions you defined in step one are
activated.
Does your prompt show complete path of the current directory?
Did your message display?
Can you use the num command?
Is the variable cheese set to gouda?
-4. If al1 the questions above are answered with yes, continue with step 5; else try step
2 and 3 again to fix the problems.
-5. Start a subshell and answer the following questions.
Does your prompt show the complete path of the current directory?
Did your message display?
Can you use the num command?
Can you use the command history with vi?
1s the variable cheese set to gouda?
-6. If the settings are also available in subshells, continue with step 9, otherwise
continue with step 7.
-7. Most settings, with the exception of system variables, only apply to the current
environment and are not passed to subshells (child processes). There is a
configuration file in your system that makes settings available in subprocesses too.
Which file is this?
-8. Edit the .bashjrofile and .bashrc files so that the correct settings are in ,the
correct configuration file. What settings should be in .bash_profile and what
settings should be in .bashrc?

14-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

-9. Log out and log in again and see if your settings are set in your login environment.
Also check if the settings are set in a subshell.
- 10. In the previous steps, you altered configuration files and then logged out and in to
activate the new settings. What could you do to activate settings in an altered
customization file without logging out and in again?
-11. If you are not in your login shell, return there now.
-12. Remove the num alias from your environment without editing the .bashrc or
.bash_profile file. Then display the list of aliases currently set and try to execute the
num alias.
- 13. Add the num alias to your environment and check if num is there again.

Customizing the X environment


-14. Switch to virtual terminal 7 and log in using your own name. Open a few
applications, change some themes and log out. While logging out, check the box
next to "cave session". Then log in again. Do your applications and settings appear
again?

END OF EXERCISE

-- - -

O Copyright IBM Corp. 2001,2005 Exercise 14. Customizing the User Environment 14-3
Course materials rnay not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise lnstructions With Hints


Customizing the shell environment
- 1. If you are not logged in, log in as tuxl at ttyl.
>> ~Ctrl-Alt-F1>
>> Login: tuxl
>> Password: penguinl
-2. Change the appropriate file to change your environment each time you log in. Make
sure that you have the following functions when you log in:
Change the primary prompt to show you the complete path of the current
directory.
Display a message stating your login name and the date you loggecl in.
Define an alias num that shows you how many users are logged in at that
moment.
Set the variable cheese to gouda.
,, $ vi .bash_profile
PSl='$PwD $ '
echo User $LOGNAME logged in at $(date)
alias nurn="who 1 wc - 1"
cheese=gouda
-3. Log out and log in again. Check if the functions you defined in step one are
activated.
Does your prompt show complete path of the current directory?
Did your message display?
Can you use the num command?
Is the variable cheese set to gouda?
>, $ exit
>> Login: tuxl
>> Password: penguinl
>> $ num
>> $ echo $cheese
-4. If al1 the questions above are answered with yes, continue with step 5; else try step
2 and 3 again to fix the problems.
-5. Start a subshell and answer the following questions.
Does your prompt show the complete path of the current directory?
Did your message display?
Can you use the num command?

14-4 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Exercises

Can you use the command history with vi?


Is the variable cheese set to gouda?
>> $ bash
>> $ num
>> $ echo $cheese
-6. If the settings are also available in subshells, continue with step 9, otherwise
continue with step 7.
-7. Most settings, with the exception of system variables, only apply to the current
environment and are not passed to subshells (child processes). There is a
configuration file in your system that makes settings available in subprocesses too.
Which file is this?
-8. Edit the .bashjrofile and .bashrc files so that the correct settings are in the
correct configuration file. What settings should be in .bash_profile and what
settings should be in .bashrc?

>> $ vi .bash_profile
PSl='$PWD $ '
cheese=gouda
export PS1 cheese (and any other variable already exported)
echo User $LOGNAME logged in at $(date)
>> $ vi .bashrc
alias n~m=~lwho 1 wc - 1"
-9. Log out and log in again and see if your settings are set in your login environment.
Also check if the settings are set in a subshell.
>> $ exit
>> Login: tuxl
>> Password: penguinl
>> $ num
>> $ echo $cheese
>> $ bash
>> $ num
>> $ echo $cheese
- 10. In the previous steps, you altered configuration files and then logged out and in to
activate the new settings. What could you do to activate settings in an altered
customization file without logging out and in again?

- 11. If you are not in your login shell, return there now.

O Copyright IBM Corp. 2001,2005 Exercise 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 Exercises

>> $ ps
>> $ exit
- 12. Remove the num alias from your environment without editing the .bashrc or
.bash_profile file. Then display the list of aliases currently set and try to execute the
nurn alias.
>> $ unalias nurn
>> $ alias
>> $ nurn
- 13. Add the num alias to your environment and check if num is there again.
>> $ . .bashrc
>> $ nurn

Customizing the X environment


- 14. Switch to virtual terminal 7 and log in using your own name. Open a few
applications, change some themes and log out. While logging out, check the box
next to "save session". Then log in again. Do your applications and settings appear
again?

END OF EXERCISE

14-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise 15. Basic System Conf iguration


What This Exercise Is About
This exercise provides an opportunity to become familiar with basic
system configuration that might be needed on a workstation.

What You Should Be Able to Do


At the end of this exercise, students should be able to:
Insta11 and deinstall RPMs
Configure a printer
Configure a sound card
Configure the network interface

Required Materials
A set of installation CDs for your distribution

O Copyright IBM Corp. 2001,2005 Exercise 15. Basic System Configuration 15-1
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Exercises

Exercise lnstructions
The RPM Package Manager
- 1. Log in as root in your graphical environment. Open a terminal window.
-2. Make a list of al1 packages that are installed on the system.
-3. List the information of the bash package.
-4. List al1 files in the bash package.
-5. List al1 the package files that are available on the distribution CD-ROMs or Network
lnstall Server.
-6. Remember the vlock command that we tried to use in exercise 3? We couild not do
that exercise because vlock was not installed. Now that you know how to install an
RPM, install the vlock RPM, and try to perform that particular exercise once more.
Before you install the vlock RPM, list the information of the RPM, and list iall files in
the RPM.
vlock is on Fedora Core 3 CD 3, Red Hat Enterprise Linux CD 2, and SuSE 9.3 CD
2.
-7. Verify that the application vlock is indeed installed by performing the exercises from
exercise 3.
-8. Uninstall vlock and verify that it indeed is no longer available.

Configuring a printer (optional)


If a printer is available in your classroom (either locally attached to your system or remotely
via the network), then your instructor provides you with the information about this printer. If
no printer is available then you have to skip this exercise.
-9. Use your browser to configure your printer.
- 10. Print the /etc/passwd file.

Configuring a Sound Card (optional)


- 11. Use the sound card configuration tool that came with your distribution and configure
your sound card. Then try to play some audio.

Configuringyour network (optional)


In most classrooms it is not possible to alter the network configuration, since this nlight lead
to network problems which may also affect other classes that are currently running. If it is
safe to play with network settings, your instructor gives you additional exercises to perform.
- 12. Browse the files where the network configuration for your system is stored.

15-2 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Sfudent Exercises

- 13. If the classroom uses DHCP to configure your network card, then take a look at the
current configuration with the ifconfig and route commands.
- 14. Ask your instructor for permission to modify the current network settings. This is a
safety issue since a wrong network configuration may lead to problems for other
students - even students in other classrooms! If you obtained permission, start the
configuration tool that is appropriate for your distribution and configure static
networking, using the IP address, netmask and default gateway you saw in the
previous exercise.

END OF EXERCISE

O Copyright IBM Corp. 2001,2005 Exercise 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 Exercises

Exercise lnstructions With Hints


The RPM Package Manager
- 1. Log in as root in your graphical environment. Open a terminal window.
-2. Make a list of al1 packages that are installed on the system.
>> # rpm -q -a
-3. List the information of the bash package.
>> # rpm -q -i bash
-4. List al1 files in the bash package.
>> # rpm -q -1 bash
-5. List al1 the package files that are available on the distribution CD-ROMs or Network
lnstall Server.
>> If you did a CD-based install:
# mount lmedialcdrom
If you did a network (NFS) based install:
# mount <server>:<dir> /rnedia/cdrom
>> # cd Imedialcdrom
>> # find . mame "*.rpmW
>> # cd
>> # umount lmedialcdrom
>> If you did a CD-based install, do this for al1 CDs.
-6. Remember the vlock command that we tried to use in exercise 3? We could not do
that exercise because vlock was not installed. Now that you know how to install an
RPM, install the vlock RPM, and try to perform that particular exercise once more.
Before you install the vlock RPM, list the information of the RPM, and list iall files in
the RPM.
vlock is on Fedora Core 3 CD 3, Red Hat Enterprise Linux CD 2, and SuSE 9.3 CD

>> # rpm -q -i vlock


You should get an error: package vlock is not installed.
>> If you did a CD-based install:
# mount Imedialcdrom
If you did a network (NFS) based install:
# mount <server>:<dir> Imedialcdrom
>> fedora# cd lmedialcdromlFedoralRPMS
redhati# cd ImedialcdromlRedHatlRPMS
suse# cd lmedialcdrom/suse/i586
>> # rpm -qip vlock-version.rpm

15-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

>> # rprn -qlp vlock-version.rpm


>> # rprn -ivhh vlock-version.rpm
>> # rprn -qi vlock
>> # rprn -ql vlock
>> # cd
>> # umount /media/cdrom
-7. Verify that the application vlock is indeed installed by performing the exercises from
exercise 3.
» ~Ctrl-Alt-F1>
>> $ vlock
>> $ vlock -a
-8. Uninstall vlock and verify that it indeed is no longer available.
» <Alt-F7>
>> # rprn -e vlock
>> ~Ctrl-Alt-F1>
>> $ vlock

Configuring a printer (optional)


If a printer is available in your classroom (either locally attached to your system or remotely
via the network), then your instructor provides you with the information about this printer. If
no printer is available then you have to skip this exercise.
-9. Use your browser to configure your printer.
>> Start your browser and use http:lllocalhost:631 as URL.
-10. Print the /etc/passwd file.
>> # Ipr /etc/passwd

Configuring a Sound Card (optional)


-11. Use the sound card configuration tool that came with your distribution and configure
your sound card. Then try to play come audio.
>> fedoralredhat# system-conf ig-soundcard
suse# yast
>> # xmms
(if xmms is not installed on your system by default, then install it via rpm)

Configuring your network (optional)

O Copyright IBM Corp. 2001,2005 Exercise 15. Basic System Configuration 15-5
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Sfudent Exercises

In most classrooms it is not possible to alter the network configuration, since this might lead
to network problems which may also affect other classes that are currently running. If it is
safe to play with network settings, your instructor gives you additional exercises to perform.
- 12. Browse the files where the network configuration for your system is stored.
>> fedora/redhat# cat letclsysconfiglnetwork-scriptslifcfg-*
suse# cat letclsysconfiglnetworWifcfg-*
- 13. If the classroom uses DHCP to configure your network card, then take a look at the
current configuration with the ifconfig and route commands.
>> $ ifconfig
>> $ route
- 14. Ask your instructor for permission to modify the current network settings. This is a
safety issue since a wrong network configuration may lead to problems for other
students - even students in other classrooms! If you obtained permission, start the
configuration tool that is appropriate for your distribution and configure sta'tic
networking, using the IP address, netmask and default gateway you saw iii the
previous exercise.
>> fedora/redhat# system-config-network
>> suse# yast

END OF EXERCISE

--

15-6 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise 16. Securing a Linux Workstation


What This Exercise Is About
This exercise provides an opportunity to apply the techniques that can
be used to secure a Linux workstation.

What You Should Be Able to Do


At the end of this exercise, students should be able to:
Make a list of open ports
Figure out which services are responsible for the open ports
Disable unnecessary services

O Copyright IBM Corp. 2001,2005 Exercise 16. Securing a Linux Workstation 16-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise lnstructions
Figuring out which services have ports open
- 1. Log in as root. If you log in using a graphical environment, open a termina.1window.
-2. Make a list of al1 open ports on the system. ldentify al1 ports that are in the "listen"
state.
-3. For each of the ports of the previous step, find out which PID opened that port. Then
find out what the process name is for that PID.
-4. Consult the manual page and the information of the RPM for that process and
determine whether you want that service running or not.

Disabling unneeded services


-5 . Disable any unneeded services using chkconfig.
-6. Reboot your system and check that al1 unneeded cervices did not start.

END OF EXERCISE

16-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise lnstructions With Hints


Figuring out which services have ports open
-1. Log in as root. If you log in using a graphical environment, open a terminal window.
-2. Make a list of al1 open ports on the system. ldentify al1 ports that are in the "listen"
state.
>> # netstat -anut
-3. For each of the ports of the previous step, find out which PID opened that port. Then
find out what the process name is for that PID.
>> # fuser -n tcp <portnumber>
>> # fuser -n udp <portnumber>
>> # ps ax 1 grep <PID>
-4. Consult the manual page and the information of the RPM for that process and
determine whether you want that service running or not.
>> # man <programname>
>> # rpm -qif 'which <programname>'

Disabling unneeded services


-5. Disable any unneeded cervices using chkconfig.
>> # chkconfig <service> off
-6. Reboot your system and check that al1 unneeded services did not start.
» # reboot
>> # netstat -anut
>> # ps ax

END OF EXERCISE

O Copyright IBM Corp. 2001,2005 Exercise 16. Securing a Linux Workstation 16-3
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Exercises

16-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise 17. lntegrating Linux in a Windows


Environment

What This Exercise Is About


This exercise provides an opportunity to become familiar with the
different options when integrating Linux in a Windows environment.

What You Should Be Able to Do


At the end of this exercise, students should be able to:
Access Windows filesystems
Access Windows servers
Notice: Because VMWare and Win4Lin require commercial licenses,
they cannot be demonstrated in this class.
WlNE requires extensive configuration and is therefore not included in
the exercises.
Because Bochs is typically not included in a distribution, but needs to
be installed from source, it cannot be demonstrated either.

Required Materials
The NetBlOS name of a Windows server, and the name and
password of a user account/home directory on that server.

O Copyright IBM Corp. 2001,2005 Exercise 17. lntegrating Linux in a Windows Environment 17-1
Course rnaterials rnay not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise lnstructions
Accessing Windows filesystems
Note: At the time of this writing, the Linux kernel was only able to mount an NTFS
filesystem read-only. Read-write support was under development, but far from reliable. As
a result of this, some distribution manufacturers decided not to include NTFS in the
precompiled distribution kernel at all. So if your partition type is NTFS, you might not be
able to mount it without a kernel recompile. Kernel compiles are beyond the scope of this
course.
At the time of this writing, Fedora and Red Hat do not include NTFS support in their
distribution, but SuSE does.
- 1. Make a list of al1 partitions that exist on your system with the fdisk -1 Idevlhda (IDE)
or fdisk -1 Idevlsda (SCSI) command.
-2. List al1 filesystems that are currently mounted with the mount command. Compare
this list with the output of the previous command. This should give you a list of
Windows filesystems that are not mounted yet.
-3. Create mountpoints under Imnt for al1 Windows filesystems that you want Ito mount.
Then, mount these filesystems manually, using the mount command. Verify that the
filesystem was indeed mounted and list the contents of the filesystem.
-4. Add a line to the Ietclfstab file so that this filesystem is mounted automatically when
the system boots, and reboot the system to verify that this worked.
-5. Ask your instructor for a blank floppy disk. Format this disk using the mformat
command. Try to access the floppy disk, both using the mtools and by mounting it.

WlNE (optional)
Note: you can only perform this exercise if:
You have a Microsoft Office CD, and a valid license for this product.
You have a valid Codeweavers CrossOver Office license (a 30-day trial license can be
requested on the Web site)
We are using CrossOver Office because we're not just running Microsoft Office, but
we're installing it as well. CrossOver Office makes this process extremely easy although
it can be done without CrossOver Office.
Due to licensing issues, one or both of the conditions above might not have been satisfied
in class. In that case, you cannot perform this exercise.
-6. Go to the Web page and download the CrossOver Office installation shell script as
instructed in the e-mail in which your license (either trial or commercial) was
delivered to you.
-7. As root, start the CrossOver Office installation shell script.

17-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

-8. As a regular user, start the CrossOver Setup Program (Start; CrossOver; Office
Setup). Work through the menus to install Microsoft Office.
-9. Start one of the MS Office applications using the Start; Windows Applications;
Programs menu.

Win4Lin (optional)
Note: You can only perform this exercise if:
You have a valid Win4Lin license
You have an MS-Windows 95/98/ME installation CD, and a valid license key
You have a fairly fast lnternet connection: The Win4Lin installer downloads Win4Lin
over the lnternet during installation, and this may be a download of 20 MB, depending
on the distribution you use, and the options you choose.
Due to licensing issues, one or both of the first two conditions above might not have been
satisfied in class. In that case, you cannot perform this exercise.
- 10. Check with your instructor to see whether he or she already downloaded the
Win4Lin installer, and what the license key is. Copy over or download the Win4Lin
installer to /root.
-11. Unpack the Win4Lin installer
- 12. Start the Win4Lin installer
- 13. Work through the screens of the Win4Lin installer. Provide the license information
when asked for, and reboot your system when a Win4Lin capable kernel has been
installed.
- 14. Log in as root and start the Win4Lin installer again.
- 15. When the system-wide installation has finished, log out and log in as yourself. Then
start the Win4Lin installer again.
-16. Work through the screens again. Eventually, a new windows open in which the
Windows installer runs. This should be familiar... Enter the Windows license key
when required.
- 17. Once the Windows install is finished, play with it. Also chut down Windows and try to
start it again. From a command prompt, this is done with the win command. In
certain distributions and desktop environments, a Win4Lin entry is also added to
your start menu.

VMWare (optional)
Note: You can only perform this exercise if:
You have a valid VMWare Workstation license, or obtained a demo (30-day) license

O Copyright IBM Corp. 2001,2005 Exercise 17. lntegrating Linux in a Windows Environment 17-3
Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnissionof IBM.
Student Exercises

You have an MS-Windows installation CD, or a preinstalled MS-Windows VMWare


image available, and a valid license for MS-Windows.
Due to licensing issues, one or both of the conditions above might not have been satisfied
in class. In that case, you cannot perform this exercise.
- 18. Check with your instructor if the VMWare license, the VMWare RPM and the
Windows CD or images are available, and what their location is.
- 19. Download and install the VMWare RPM.
-20. Run the VMWare configuration script and configure VMWare for your situation.
Usually, the defaults are OK.
-21. If you have a VMWare license file, then create the directory .vmware in your home
directory, and copy the license file into this directory. Alternatively, start vmware and
enter the license information in the Help; Enter Serial Number popup screen.
-22. If your instructor has a preinstalled Windows VMWare image available, then unpack
this image. Start VMWare, open the image configuration file (*.vmx) and start the
virtual machine.
-23. If your instructor has a Windows CD available, then start VMWare, create a new
virtual machine with the New Virtual Machine Wizard. Insert the CD and start the
virtual machine.

Accessing Windows servers


Your instructor configures a Windows server or a Samba server so that you can access this
using the Samba client software which is part of Linux. He or she provides you with the
following information about this server:
Netbios name
Share name
User name

-24. Use the smbclient program to retrieve information from the Windows or Samba
server. Then use it to access the share "ftp-style". Upload and download the
/etc/passwd file to test if things are working.
-25. Create a mount point for this Windows share called /mnt/share.
-26. Mount the share on this mountpoint using the smbmount command. Verify that the
mount succeeded.
-27. Edit the /etc/fstab file and add an entry for this share. Then reboot the system and
verify that the share was mounted after the reboot.

17-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

OpenOffice
-28. Start OpenOffice and try to create and save various types of documents: text
documents, presentations, spreadsheets and so forth. Try to save them in
Microsoft-compatible formats.
-29. Start an lnternet browser and use Google to search for and obtain various
documents in Microsoft formats (search, for instante, for test.doc, test.ppt and
test.xls). See if you can open, modify and save these files.

END OF EXERCISE

O Copyright IBM Corp. 2001,2005 Exercise 17. lntegrating 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 Exercises

Exercise lnstructions With Hints


Accessing Windows filesystems
Note: At the time of this writing, the Linux kernel was only able to mount an NTFS
filesystem read-only. Read-write support was under development, but far from reliable. As
a result of this, some distribution manufacturers decided not to include NTFS in the
precompiled distribution kernel at all. So if your partition type is NTFS, you might not be
able to mount it without a kernel recompile. Kernel compiles are beyond the scope of this
course.
At the time of this writing, Fedora and Red Hat do not include NTFS support in their
distribution, but SuSE does.
- 1. Make a list of al1 partitions that exist on your system with the fdisk -1 Idevlhda (IDE)
or fdisk -1 Idevlsda (SCSI) command.
>> # fdisk -1 Idevlhda
- OR -
# fdisk -1 Idevlsda
-2. List al1 filesystems that are currently mounted with the mount command. Compare
this list with the output of the previous command. This should give you a list of
Windows filesystems that are not mounted yet.
» # mount
-3. Create mountpoints under /mnt for al1 Windows filesystems that you want to mount.
Then, mount these filesystems manually, using the mount command. Verify that the
filesystem was indeed mounted and list the contents of the filesystem.
>> # mkdir lmntlwin95
>> # mount -t vfat Idevlhdal lmntlwin95
>> # mount
>> # Is -1 lmntlwin95
-4. Add a line to the /etc/fstab file so that this filesystem is mounted automatically when
the system boots, and reboot the system to verify that this worked.
>> # vi Ietclfstab
>> Add the following line:
/dev/hdal /mt/win95 vfat de£aults O O
>> # reboot
>> After reboot, log in as root.
>> # mount
-5. Ask your instructor for a blank floppy disk. Format this disk using the mformat
command. Try to access the floppy disk, both using the mtools and by mounting it.
>> # mformat a:
>> # mdir a:
>> # mcopy Ietclpasswd a:

17-6 Linux Power User O Copyright IBM Corp. 2001,2005


Course rnaterials rnay not be reproduced in whole or in part
without the prior written perrnission of IBM.
Student Exercises

>> # mdir a:
>> # mount lmedialfloppy
>> # Is Imedialfloppy
>> # cat Imedialfloppy
>> # umount Imedialfloppy

WlNE (optional)
Note: you can only perform this exercise if:
You have a Microsoft Office CD, and a valid license for this product.
You have a valid Codeweavers CrossOver Office license (a 30-day trial license can be
requested on the Web cite)
We are using CrossOver Off ice because we're not just running Microsoft Office, but
we're installing it as well. CrossOver Office makes this process extremely easy although
it can be done without CrossOver Office.
Due to licensing issues, one or both of the conditions above might not have been satisfied
in class. In that case, you cannot perform this exercise.
-6. Go to the Web page and download the CrossOver Office installation shell script as
instructed in the e-mail in which your license (either trial or commercial) was
delivered to you.
-7. As root, start the CrossOver Office installation shell script.

-8. As a regular user, start the CrossOver Setup Program (Start; CrossOver; Office
Setup). Work through the menus to install Microsoft Office.
-9. Start one of the MS Office applications using the Start; Windows Applications;
Programs menu.

Win4Lin (optional)
Note: You can only perform this exercise if:
You have a valid Win4Lin license
You have an MS-Windows 95/98/ME installation CD, and a valid license key
You have a fairly fast lnternet connection: The Win4Lin installer downloads Win4Lin
over the lnternet during installation, and this may be a download of 20 MB, depending
on the distribution you use, and the options you choose.
Due to licensing issues, one or both of the first two conditions above might not have been
satisfied in class. In that case, you cannot perform this exercise.

O Copyright IBM Corp. 2001,2005 Exercise 17. lntegrating 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 Exercises

- 10. Check with your instructor to see whether he or she already downloaded the
Win4Lin installer, and what the license key is. Copy over or download the Win4Lin
installer to Iroot.
- 11. Unpack the Win4Lin installer
>> # tar -zxvf netraverse-installer5.tgz
- 12. Start the Win4Lin installer
>> # cd netraverse-installer
>> # .Iwin4lin-install
- 13. Work through the screens of the Win4Lin installer. Provide the license information
when asked for, and reboot your system when a Win4Lin capable kernel has been
installed.
- 14. Log in as root and start the Win4Lin installer again.
>> # cd netraverse-installer
>> # ./win4lin-install
- 15. When the system-wide installation has finished, log out and log in as yourself. Then
start the Win4Lin installer again.

- 16. Work through the screens again. Eventually, a new window opens in which the
Windows installer runs. This should be familiar... Enter the Windows license key
when required.
- 17. Once the Windows install is finished, play with it. Also shut down Windows and try to
start it again. From a command prompt, this is done with the win command. In
certain distributions and desktop environments, a Win4Lin entry is also added to
your start menu.

VMWare (optional)
Note: You can only perform this exercise if:
You have a valid VMWare Workstation license, or obtained a demo (30-day) license
You have an MS-Windows installation CD, or a preinstalled MS-Windows VMWare
image available, and a valid license for MS-Windows.
Due to licensing issues, one or both of the conditions above might not have been satisfied
in class. In that case, you cannot perform this exercise.
- 18. Check with your instructor if the VMWare license, the VMWare RPM and the
Windows CD or images are available, and what their location is.
- 19. Download and install the VMWare RPM.
D # rpm -ivh VMware-Workstation-version.i386.rpm

17-8 Linux Power User O Copyright IBM Corp. 2001,2005


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

-20. Run the VMWare configuration script and configure VMWare for your situation.
Usually, the defaults are OK.

-21. If you have a VMWare license file, then create the directory .vmware in your home
directory, and copy the license file into this directory. Alternatively, start vmware and
enter the license information in the Help; Enter Serial Number popup screen.
» #cd
>> # mkdir .vmware
>> # cp 1somewherellicense.ws.version .vmwarel
-22. If your instructor has a preinstalled Windows VMWare image available, then unpack
this image. Start VMWare, open the image configuration file (*.vmx) and start the
virtual machine.
-23. If your instructor has a Windows CD available, then start VMWare, create a new
virtual machine with the New Virtual Machine Wizard. lnsert the CD and start the
virtual machine.

Accessing Windows servers


Your instructor configures a Windows server or a Samba server so that you can access this
using the Samba client software which is part of Linux. He or she provides you with the
following information about this server:
Netbios name
Share name
User name

-24. Use the smbclient program to retrieve information from the Windows or Samba
server. Then use it to access the share "ftp-style". Upload and download the
/etc/passwd file to test if things are working.
>> #smbclient -L winserver -N
>> #smbclient -L winserver -U username
>> #smbclient -L winserver -U username%password
>> #smbclient llwinserverlshare -U username%password
>> smb> put letclpasswd passwd
>> smb> get passwd myjasswd
>> smb> quit
-25. Create a mount point for this Windows share called /mnt/share.
>) # mkdir Imntlshare
-26. Mount the share on this mountpoint using the smbmount command. Verify that the
mount succeeded.

O Copyright IBM Corp. 2001,2005 Exercise 17. lntegrating 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 Exercises

>> # smbmount Ilwinserverlshare Imntlshare -o


username=username%password
>> # mount
>> # Is Imntlshare
-27. Edit the Ietclfstab file and add an entry for this share. Then reboot the system and
verify that the share was mounted after the reboot.
>> # vi letclfstab
>> Add the following line:

>> # reboot
>> After reboot, log in as root.
>) # mount

OpenOffice
-28. Start OpenOffice and try to create and save various types of documents: text
documents, presentations, spreadsheets and so forth. Try to save them in
Microsoft-compatibleformats.
-29. Start an lnternet browser and use Google to search for and obtain various
documents in Microsoft formats (search, for instance, for test.doc, test.ppt and
test.xls). See if you can open, modify and save these files.

END OF EXERCISE

17-10 Linux Power User O Copyright IBM Corp. 2001,2005


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

Exercise 18. End-of-course Challenge Exercise

What This Exercise Is About


This (optional) exercise provides an opportunity to apply al1 concepts
and techniques learned in this course in a single, real-life scenario.

What You Should Be Able to Do


At the end of this exercise, students should be able to apply al1
concepts and techniques learned in this course in a real-life scenario.

O Copyright IBM Corp. 2001,2005 Exercise 18. End-of-course Challenge Exercise 18-1
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

Exercise lnstructions
You have decided to start using Linux on your home PC, and you have convinced the other
members of your family (who also use this PC) to give it a try as well. They are not
convinced that they want to get rid of the current MS-Windows installation though.
Together with your family members you have created a list of requirements regarding the
Linux installation:
1. The PC should have a dual-boot installation, where a boot menu allows you ta boot the
current, MS-Windows OS, and the new Linux installation. The default OS should be
Linux.
2. The partitioning scheme should include the current Windows partition, a /boot partition,
a / partition, a swap partition and a data partition. The data partition should be a FAT
filesystem, so that it is accessible from Windows as D:-drive, and should be mounted
under Linux as /mnt/data. The mount permissions of Imntídata should be set so that
everybody can access al1 files. (Note that a FAT filesystem does not support
permissions, so you have to work with mount options to achieve this. Consult the
manual page of mount for the correct options.)
3. When Linux boots, it should come up with a graphical login prompt. Because of disk
space considerations, only install KDE, not GNOME.
4. Each member of your family should have its own user account. You should create these
user accounts, and set the password identical to the username. Your family members
change their passwords later. Obviously, you should also create a user account for
yourself.
5. All unnecessary services should be switched off. For al1 cervices that are running, go to
your distributions Web site and download and install al1 available updates.
6. The relevant parts of the documentation that came with your distribution should be
copied to disk, in a suitable location.
7. The household printer (if available) should be configured.
8. The sound card (if available) should be configured.
9. The network adapter (if available) should be configured with a dynamic (DHCP) IP
address.
10.Your youngest daughter is two years old and has problems with her hand-eye
coordination. When she logs in (with help), she should find a desktop full of simple
applications that help her train her hand-eye coordination, such as xeyes, xbill and
SameGnome.
11. In order to maintain the system, you need two shell scripts, which should be executable
by root only:
A script which checks al1 filesystems (including the Windows and the data
filesystem), and warns you if the utilization of one of them gets above 90%.

18-2 Linux Power User O Copyright IBM Corp. 2001,2005


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

A script which prints the amount of data in each users home directory, sorted
by disk usage.
lmplement al1 requirements listed above as well as possible, using your student guide and
any documentation you can find as a reference. A few requirements are not fully covered in
the course. In this case, use the manual pages and other documentation to find out the
correct commands andlor options.
There are no hints for this exercise, but you can consult your instructor if you have
problems fulfilling a requirement.
END OF EXERCISE

O Copyright IBM Corp. 2001,2005 Exercise 18. End-of-course Challenge Exercise 18-3
Course materials may not be reproduced in whole or in part
without the prior written permission of IBM.
Student Exercises

18-4 Linux Power User O Copyright IBM Corp. 2001,2005


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

Vous aimerez peut-être aussi