Académique Documents
Professionnel Documents
Culture Documents
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
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:
Contents
Trademarks .......................................................xi
Course Description ................................................xiii
...
Agenda .......................................................... xv
.
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 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 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
.
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
.
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
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:
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
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
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)
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.
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
Notes:
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.
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.
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.
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
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.
-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
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
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.
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.
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.
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.
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
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.
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
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).
Checkpoint
Notes:
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
Notes:
Unit Objectives
After completing this unit, you should be able to:
Prepare a system for installation
lnstall Linux from CD-ROM
Notes:
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.
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.
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
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.
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.
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
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.
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.
PartitionMagic
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.
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
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:
C:\> d:
D :\> cd images
D:\IMAGES> dir
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.)
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
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.
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.
lnstall Class
Most distributions have default installation "classes" for typical users
- Workstation
- Laptop
- Server
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.
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
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
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.
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.
--
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.
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
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.
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).
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).
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
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
laptops suffer from this occasionally. In that case, there's always a possibility to skip X
configuration altogether.
- Printer configuration
- Firewall configuration
- Sound card configuration
- Modem configuration
- Time Zone configuration
Usually straightforward
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.
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
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.
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.
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
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.
Checkpoint
Notes:
Unit Summary
Preparing a system for installation
Booting the installation program
lnstalling Linux and basic configuration
Notes:
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
Notes:
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:
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.
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)
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'.
Notes:
The visual shows a text mode login session.
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.
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
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.
GNOME:
SUSE:
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.
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"
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.
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.
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
Notes:
Notes:
In the next few visuals, we are going to look at the commands listed in the visual.
$ passwd
Changing password for tuxl
Old password:
New password:
Retype new password:
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.
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.
$ date
Fri Jun 6 11:15:10 CET 2003
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.
$ 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
$
Notes:
With the cal command you can look at the calendar of a given year or a given month in a
year.
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
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.
$ 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.
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.
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.
JOHN FRED
O Copyright IBM Corporation 2005
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.
$ mesg n
User t w 2 al tty2:
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.
- - -
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
Notes:
Several keyboard shortcuts help you correct mistakes that you typed, and can stop and
resume scrolling output.
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
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.
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
Notes:
You can also view al1 commands that are stored in the history with the history command.
$ wc .bash_profile
16 23 238
Redo previous:
$ 1-1
wc .bashjrof ile
16 23 238
01":
$ !!
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.
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.
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
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.
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:
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.
Checkpoint
Notes:
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.
Notes:
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
Notes:
A File
A file is:
\n = newline character
- = space character
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
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.
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.
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
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.
I I
tuxl tux3
I I
I I I I
- .bash-profile
test doc c rP c Pgms
-- manuals
- test1 suba
- mon-report -a
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:
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.
--
$ cd doc (relative)
$ cd /home/tuxl/doc (full)
$ cd -tuxl/doc ( home )
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
$ cd /home/tuxl
$ mkdir doc (relative pathname)
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.
Removing Directories
With the rmdír (remove directory) command:
$ rmdir dir-name
$ pwd
/horne/tuxl
$ rmdir doc test
rmdir: doc: Directory not empty
$
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
$ mkdir - p dirl/dir2/dir3
$ m d i r - p dirl/dir2/dir3
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.
$ 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
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
$ 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
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.
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
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.
Copying Files (2 of 2)
cp can recursively copy directories with the -R flag
$ cp - R /home/tuxl/doc /tmp
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
To rename a file:
$ mv doc documents
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.
To move a directory:
$ mv ./test /tmp
mv is recursive by default
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
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
$ 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
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
$ 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
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.
Removing Files
With the rm command:
$ rm test/rob
$ 1s test/rob
1s: rob: No such file or directory
I
O Copyright IBM Corporation 2005
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
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.
File Managers
Linux also offers different graphical file managers
- Nautilus (GNOME)
- Konqueror (KDE)
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
- c.
d.
lvarltmpl.secret.doc
Ihomel..lhome/tuxllone+one
Notes:
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
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
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
Notes:
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
Km\tk\ .
1. the owner'Gf a ffe
2. the members of the group the file is assigned to
3. al1 other users
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
1 1 1 1
File type owner size name
v 1 1
permissions grouP mtime
t (modification time)
link counter
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
directories:
r contents of directory can be listed (1s)
w contents can be modified (addldelete files)
x change into directory is possible (cd)
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!
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!!!
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.
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:
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
Changing Permissions (2 of 2)
Calculating numeric (octal) mode:
MIX r-x
T
+0+1=0/
4+2+1=\[
mode is 750
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
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
directories:
default permissions rwxrwxrwx 777
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
Notes:
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
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
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
Notes:
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
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.
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,
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.
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
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.
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)
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.
next node
previous node
q quit info
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
Previous node
Go to up node
To top of node
To end of node
info E x a m ~ l e
# i n f o pwd
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.
Welcome to Info version 4.2. Type C-h for help, m for menu item.
O Copyright IBM Corporation 2005
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.
$ who --help
Usage: who [OPTION] ... [ FILE 1 ARGl ARG2 ]
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.
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
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.
HOWTO Example
$ less /usr/share/doc/~O~~O/~Free86-HOWTO
The Linux XFree86 HOWTO
by Eric S. Raymond
v5.8, 16 August 1998
Table of Contents
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.
Other Documentation
Certain programs also offer other kinds of documentation
- HTML
- PostScript
- Plain Text
Usually stored in /usr/share/doc/~programname>
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.
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
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.
Checkpoint
Notes:
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.
Notes:
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
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:, ...
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.
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.
lboot
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).
ldev
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.
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.
letc
&! í h ,blb
iq
l Contains &tem-wide configuration files
<OS? y clii
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.
lhome
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.
lmnt
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.
lproc
.Virtual filesystem
Represents kernel and process information
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
lroot
Notes:
lroot is the home directory of the root user.
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.
lusr
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
/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.
lvar
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.
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.
Other Directories in 1
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.
ldevlhda2 is the
1 "root filesystem"
this directory
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".
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.
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.
Qin llib I s b i n d
O Copyright IBM Corporation 2005
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:
# umount /dev/hda5
- OR -
# umount /usr
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.
# 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
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
As rnentioned before, SUSE uses Imedidfloppy and Imedidcdrorn instead of Irnntífloppy and Imntícdrorn.
$ whoami
tuxl
$ mount /media/cdrom
$ mount
1 $ unount /media/cdrom
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:
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.
Checkpoint
Figure 7-22.Checkpoint
Notes:
Unit Summary
Structure of the filesystem
- Ibin, Ilib, Isbin
- lboot
- Ietc
- Ihome, Iroot
- Itmp
- Iusr
- Ivar
Special filesystems
- Iproc
- lmnt
Special files
- Idev
Notes:
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
Notes:
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
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.
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.
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.
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
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
ex mode
I T
Allows you to execute
complex commands
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.
Starting vi
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.
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!
command mode
Notes:
To execute one of the illustrated commands, you must be in command mode.
There are several different ways to perform the delete functions.
l iAam-
Command mode Edit mode
ESC
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.
line 3. S
line 3.
The last line is line 5.
N
L*
L*
- - INSERT - - 3,8 Al 1
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 --".
3,8 ~ 1 1
vi can also search for patterns. This is done with the 1 (slash) command. To repeat a
previous search, use the n command.
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.
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.
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.
ne 4 follows line 3.
e last line is line 5.
d that for example is line 3.
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.
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.
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
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)
Exiting vi
To save and exit in command mode ZZ
To save in ex mode :W
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.
- - -- --
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
Notes:
You can use this page as a quick reference for some of the most used commands in vi.
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
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!)
Checkpoint
TIF 1. You need to learn vi because vi ¡Sthe best editor
for any job. F
Notes:
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
Notes:
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
Notes:
The Shell
The "shell" is the user interface to Linux
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.
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)
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).
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'.
$ 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
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
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.
$ 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
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.
File Descriptors
Standard in (O)
Standard In STDlN c O
Standard Error STDERR 2> 2 standard out (1) 4 standard error (2)
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.
lnput Redirection -
$ cat
Ams terdam
Aas terdam
Utrecht
Utrecht
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:
Output Redirection
Default Standard Out~ut: Idevlttv
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:
Using ordinary redirection overwrites an existing file. To avoid this, use the >> (no space
between them) to append output to an existing file.
Error Redirection
Default Standard Error: /dev/tty
$ cat filea
cat: filea: No such file sr disectory
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:
10 1I keyboard 1I keyboard
1 screen screen
2 screen error.file
and for the second:
Combined Redirection
Combined redirects
Association
This redirects stderr to where stdout is redirected:
A
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".
Pipes
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.
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
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.
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
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.
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.
Split Output
$ 1s ( tee 1s.save 1 wc - 1
3
$ cat 1s.save
filel
f ile2
file3
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.
Command Substitution
Command Substitution allows you to use the output of a command
as arguments for another command.
Use backticks (') or $0 notation:
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.
Command Grouping
Multiple commands can be entered on the same line, separated by
a semicolon (;)
$ date ; p w d
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.
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
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.
$ echo $VARl
Hello class
$ echo $ V A R ~
2
Notes:
To reference a variable, use the $variable expression.
$ export x=4
$ bash
9: echa $x
4
$ x-100
$ echo $ x
108
$ exit
$ echo $x
4
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.
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.
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.
$ whoami
tuxl
$ echo $ ?
o
$ cat filea
cat: filea: No such file or directory
$ echo $ ?
1
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 $?.
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 (\)
$ 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.
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
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.
Aliases
The alias command allows you to set up aliases for often-used
commands
Examples:
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.
Checkpoint
Notes:
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
Notes:
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
Notes:
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:
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
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.
Linux System
isbinlmingetty
...forks lbinlbash
-bash (login shell)
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
$ 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
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.
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
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
$ 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
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.
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
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
Background Processes
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.
--
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
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.
Job Control E x a m ~ l e
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:
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".
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
_I
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.
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.
$ 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
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
$ 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
. ..
...
...
Notes:
When you want to change the priority of a process which is already running, use ttie renice
command.
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
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.
Checkpoint
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
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
Notes:
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
Notes:
Syntax:
$ find path expression
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>
blues
phone
phonel
phone2
Notes:
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
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.
$ 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
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
{3 \;
< rm ... ./color/blue > ? y
< rm ... ./color/brown > 3 y
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.
/*
Additional find Options G/ i l nc
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.
find Examples
$ find .
-perm 777
./size/little
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.
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
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.
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.
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
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.
This syntax can only be used correctly if the file is divided into columns that are separated
with a special delimiter character.
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
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.
Syntax
grep [options] pattern [filel ...1
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.
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
Notes:
This foil shows the sample files used to illustrate the examples that follows.
$ 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
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.
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.
Regular Expression
greP phonel
phone 1
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
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~~'
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
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.
$ cat animals
dog - 2
$ sort animals
cat.4
dog .2
penguin.10
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.
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
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.
$ 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)
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
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.
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
executable in /bin. The problem is that when you issue the echo command the built-in is
run and not the executable in /bin.
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'
$ 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
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.
Depending on what packages you installed, the following commands may also be
available:
zgrep
zless
zmore
$ 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
Notes:
The join and paste commands allow you to merge files together. They're never used,
except for the most complicated shell scripts.
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"
Notes:
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
Notes:
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
Notes:
$ pwd
$ date
$ 1s - 1
$ cat scriptl
pwd
date
1s - 1
$
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.
$ cat scriptl
date
$ bash s c r i p t l
Start of subshell
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.
$ chmod 7 5 5 ./scriptl
$ ./scriptl
Start of subshell
1
f date
............................
........................................................ ...............--.
1
O Copyright IBM Corporation 2005
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.
$ .
scriptl
$ source s c r i p t l
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.
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.
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.
$ 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
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 ..."
Complex Redirection
To redirect fixed text into a command use << END
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,
xargs has a large number of options that determine how the final command(s) are actually
formatted. For more information, see its manual page.
Conditional Execution
The return code from a command or group of commands can be
used to determine whether to start the next command.
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.
$ test - f myfile.txt 1
1 $ echo $1
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.
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
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:
commandl
a&&d command2
if (commandl successful) then do (command2)
lo(
commandl 1 1 command2
if (commandl not successful) then do (command2)
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.
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
$
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.
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
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
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
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
$ cat make-backup
while [ $ # -gt O 1
do
cp $1 $l.bak
shift-?\.,\ric. mr\\ario , brtir$nJ~\c
done
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
$ 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
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.
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
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
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.
$ 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
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.
w command
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.
Checkpoint (1 of 2)
else
echo You donlt have a TERM variable set!
Notes:
Checkpoint (2 of 2)
2. Write a script that will multiply any two numbers together.
Notes:
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
Notes:
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
Notes:
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
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.
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
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.
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)
- ...
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)
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.
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)
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.
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.
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
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.
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:
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.
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
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.
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?
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
Notes:
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
Notes:
$HOMEl.bash-logout
O Copyright IBM Corporation 2005
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
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).
$HOME/.bash-profile
$HOME/.bashrc
export BASH-ENV=$HOME/.bashrc
letclbashrc
$HOME/.bash-logout
O Copyright IBM Corporation 2005
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.
$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.
KDE Customization
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
m
Windaws
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.
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
Notes:
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
Notes:
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
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.
/
$ 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
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
1
I
# 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
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
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
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)
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
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
...checks your
modules s. coa
Sound Card support requires correct loading of
kernel modules!
O Copyright IBM Corporation 2005
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.
- -
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
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.
Checkpoint
TIF 1. When you configure your system as a DHCP
client, you don't need to configure IP addresses
and so forth yourselves.
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
Notes:
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
Notes:
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.
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
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
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).
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)
A
lnternet
3
O Copyright IBM Corporation 2005
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.
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
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.
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
Linux workstation
with built-in
ethernet ada~ter DHCP
ISP server I
Cable
modem
jppjsGT&-E-g
"L
O Copyright IBM Corporation 2005
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.)
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
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
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.
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
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.
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.
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.
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.
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
Notes:
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
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
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
Notes:
WWL-J
bin nib lshare lX11R lkde lgnome letc fln luxl flux2 flux3 11~x4
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.
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
drive a: file=fl/dev/fdO1n
exclusive 1.44m mformat-only
drive c: file=w/dev/hdalm
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
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
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!
- -
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
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
VMWare Screenshot
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
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
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
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.
WlNE Screenshot
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
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
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
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.
smbmount Examples
To mount a share as an filesystem:
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
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.
$ file mytext.doc
mytext.doc: Microsoft Office Document
$ swriter mytext.doc
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
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.
Checkpoint
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
Notes:
echo $(( $1 * $2 ))
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.
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
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
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
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
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
Student Exercises
ERC 4.0
Contents
Trademarks ....................................................... v
Exercises Description .............................................. vii
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:
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.
--
Required Materials
A set of installation CDs for your distribution
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
-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.
- 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.
-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.
-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.
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
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.
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.
Logging off
-30. Log off al1 users that are logged in at any TTY.
>) 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>
-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>
-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.
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
-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 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.
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
-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
-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.
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
END OF EXERCISE
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.
- 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
-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
>> $ 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
- 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
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
- 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
- -
-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
-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.
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
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.
END OF EXERCISE
-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.
END OF EXERClSE
--
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.
-8. Practice some more with al1 the commands that are listed on your cheat sheet.
-9. Save the file but do not exit vi.
END OF EXERCISE
-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
-8. Practice some more with al1 the commands that are listed on your cheat sheet.
-9. Save the file but do not exit vi.
END OF EXERCISE
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.
-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
-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.
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. 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
- 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
-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 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.
-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
>> $ 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.
>> ~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?
-
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
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.
-17. Display the contents of /etc/passwd again, but now sorted on the home directory
field.
END OF EXERCISE
>> $ ps
>> $ ps 1 tail +2
>> $ IS -1 big
>> $ gzip big
,>$ Is -1 big*
>> The new name is big.gz.
END OF EXERCISE
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.
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.
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
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
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.
>> $ 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."
END OF EXERCISE
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?
MP3 Player 7
Sound mixer
I I
7
Word processor 7
Spreadsheet
1 Presentation package
7
1 Photolbitmap editor
- -
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
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.
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
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?
-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.
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
>> $ 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
END OF EXERCISE
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.
- 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
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
--
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.
END OF EXERCISE
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
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.
-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
-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.
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
>> # 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
-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.
-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
>> # 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
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%.
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