Professional Documents
Culture Documents
Linux – Course Material
v1.3
Udruženje Linux korisnika
(c) 2005, 2006, 2007.
Material from www.linux.org site
with permission from author
1
Table of Contents
Lesson One.......................................................................................................................4
Course objectives.........................................................................................................4
What is Linux?.............................................................................................................4
Lesson Two.......................................................................................................................9
Installing Linux...........................................................................................................9
An actual install.........................................................................................................11
Debian GNU/Linux...................................................................................................12
Installation of Debian GNU/Linux............................................................................15
Lesson Three...................................................................................................................24
Creating your routine in Linux..................................................................................24
Virtual Terminals.......................................................................................................25
Shells in Linux...........................................................................................................27
The Linux directory tree............................................................................................28
In Linux, everything is a file.....................................................................................32
Shutdown and restart.................................................................................................36
Lesson Four....................................................................................................................39
Text Editors in Linux.................................................................................................39
The text editor 'vi'......................................................................................................40
'pico' and 'joe'.............................................................................................................41
Vi for budding power users.......................................................................................42
Lesson Five ....................................................................................................................45
Frequently Used Shell Commands............................................................................45
How to get more information with Linux.................................................................53
Lesson Six.......................................................................................................................56
Plumbing with “pipes” in Linux...............................................................................56
Redirections...............................................................................................................57
Locating files on your system...................................................................................58
Other useful commands.............................................................................................61
Lesson Seven...................................................................................................................63
Becoming A Power User...........................................................................................63
An introduction to aliases..........................................................................................68
Lesson Eight...................................................................................................................70
Another Look at Users..............................................................................................70
File permissions in Linux..........................................................................................73
'chmod' explained.......................................................................................................75
Using chown..............................................................................................................78
Lesson Nine....................................................................................................................80
Acquiring root privileges in a safe manner...............................................................80
Becoming a super user..............................................................................................83
Commands to control programs on your system......................................................85
Assigning and controling jobs...................................................................................88
2
'top'.............................................................................................................................90
Lesson Ten......................................................................................................................92
File Systems in Linux................................................................................................92
Mounting file systems...............................................................................................94
/etc/fstab.....................................................................................................................98
Formatting disks under Linux...................................................................................98
Lesson Eleven...............................................................................................................100
About daemons........................................................................................................100
Monitoring log files.................................................................................................102
Lesson Twelwe – Shell Scripting...................................................................................103
Writing shell scripts.................................................................................................103
The '.bashrc' file.......................................................................................................103
Automation of Tasks on Linux................................................................................104
Lesson Thirteen Backing up your files.......................................................................110
Untarring and unzipping files..................................................................................111
Other compression tools..........................................................................................112
Lesson Fourteen Installing New Programs.................................................................114
Debian Updates........................................................................................................116
Installing new programs on Slackware....................................................................118
Lesson Fifteen Networking.........................................................................................120
Other config files.....................................................................................................120
Lesson Twenty...............................................................................................................123
Compiling kernel.....................................................................................................123
LILO and GRUB......................................................................................................127
3
Lesson One
Course objectives
We have developed this course for one basic reason: To bring the newcomer to Linux
to the point where you can do everything that you do with MS Windows, in Linux and
much more. Due to the fact that Microsoft, enjoying an illegal monopoly, has its
operating system installed on 90% of the world's computers, this course is mainly
aimed at people who want to migrate to Linux from Microsoft products.
The simple fact that you are getting this course off the Internet presupposes that you
know how to use a PC. The course should be oriented towards people migrating from
other OSes and in particular, MS Windows 9x, ME, 2000 and XP.
Our objectives are:
1. To explain the differences between working with Linux and working with
other popular OSes.
2. To stress that the somewhat steeper learning curve in Linux will pay back in
the amount of stability and flexibility.
3. To show you that by using Linux, you have opened up a whole new world of
computing. That is to say, you the Linux user are not just a passive subject
reacting to what the OS lets you do but is an active "developer" and can mold
the OS to what you want.
What is Linux?
Linux is an operating system that evolved from a kernel1 created by Linus Torvalds
when he was a student at the University of Helsinki. Generally, it is obvious to most
people what Linux is, however, both for political and practical reasons, it needs to be
explained further. To say that Linux is an operating system means that it's meant to be
used as an alternative to other operating systems like MSDOS, the various versions
of MS Windows, Mac OS, Solaris and others. Linux is not a program like a word
processor and is not a set of programs like an office suite.
A brief history of Linux
1 Kernel – the core or nucleus of an operating system. Basically, it provides a way for software and
other parts of the operating system to communicate with a computer's hardware.
4
When Linus Torvalds was studying at the University of Helsinki, he was using a
version of the UNIX operating system called 'Minix'. Linus and other users sent
requests for modifications and improvements to Minix's creator, Andrew Tanenbaum,
but he felt that they weren't necessary. That's when Linus decided to create his own
operating system that would take into account users' comments and suggestions for
improvements.
Free Software preLinux
The kernel
We should point out here that the focal point of any operating system is its 'kernel'.
Without going into great detail, the kernel is what tells the big chip that controls your
computer to do what you want the program that you're using to do. To use a metaphor,
if you go to your favourite Italian restaurant and order 'Spaghetti alla Bolognese', this
dish is like your operating system. There are a lot of things that go into making that
dish like pasta, tomato sauce, meatballs and cheese. Well, the kernel is like the pasta.
Without pasta, that dish doesn't exist. You might as well find some bread and make a
sandwich. A plate of just pasta is fairly unappetizing. Without a kernel, an operating
system doesn't exist. Without programs, a kernel is useless.
1991, a fateful year
In 1991, ideal conditions existed that would create Linux. In essence, Linus Torvalds
had a kernel but no programs of his own, Richard Stallman and GNU had programs
but no working kernel. Read the two men's own words about this:
2 GNU project part of Richard M. Stallman's Free Software Foundation, it was founded in 1984 with
the goal of creating a totally "free" operating system in which the source code was available to all
who were interested. This was both a technical and political aim. The first Linux kernel (see above)
was complied by the GNU C programming language compiler, gcc. Many of the first programs to be
bound into the fledgling Linux operating system were from the GNU project. For this reason,
Stallman insists that the operating system be called "GNU/Linux". The distribution Debian
GNU/Linux follows this convention, for example, but most do not. Public use and custom has evolved
as such so that most simply call it Linux.
5
Linus: “Sadly, a kernel by itself gets you nowhere. To get a working
system you need a shell, compilers, a library etc.”
RMS: “The GNU Hurd is not ready for production use. Fortunately,
another kernel is available. [It is called] Linux.”
Linux is introduced
Late in 1991, Linus Torvalds had his kernel and a few GNU programs wrapped around
it so it would work well enough to show other people what he had done. And that's
what he did. The first people to see Linux knew that Linus was on to something. At
this point, though, he needed more people to help him. Here's what Linus had to say
back in 1991.
"Are you without a nice project and dying to cut your teeth on an OS
you can try to modify for your needs?... This post might just be for
you."
People all over the world decided to take him up on it. At first, only people with
extensive computer programming knowledge would be able to do anything with that
early public version of Linux. These people started to offer their help. The version
numbers of Linux were getting higher and higher. People began writing programs
specifically to be run under Linux. Developers began writing drivers so different
video cards, sound cards and other gadgets inside and outside your computer could
use Linux. Nevertheless, throughout most of first part of the 1990's Linux did not get
out of the 'guru' stage. Guru is a term that has evolved to mean anyone who has special
expertise in a particular subject. That is, you had to have special expertise in how
computers worked to be able to install Linux in those days.
Linux, at first, not for everybody
Other popular software companies sold you a CD or a set of floppies and a brief
instruction booklet and in probably less than a half an hour, you could install a fully
working operating system on your PC. The only ability you needed was knowing how
to read. Those companies had that intention when they actually sat down and
developed their operating systems. Linus Torvalds didn't have that in mind when he
developed Linux. It was just a hobby for him. Later on, companies like Red Hat made
it their goal to bring Linux to the point where it could be installed just like any other
6
operating system; by anyone who can follow a set of simple instructions, and they
have succeeded. For some reason, though, Linux hasn't shaken off completely that
'gurus only' image that it took on at the beginning. That is mostly the result of articles
in the popular, quasitechnical press whose experience with Linux has been quite
limited.
Linux Today
Today, Linux is enjoying a favourable press for the most part. This comes from the
fact that Linux has proven to be a tremendously stable and versatile operating system,
particularly as a network server. When Linux is deployed as a web server or in
corporate networks, its downtime is almost negligible. There have been cases when
Linux servers have been running for more than a year without rebooting and then
only taken down for a brief period for routine maintenance. Its cost effectiveness has
sold it more than anything else. Linux can be installed on a home PC as well as a
network server for a fraction of the cost of other companies' software packages. More
reliability and less cost it's ideal.
If you're reading this, you're obviously here to learn how to use Linux. Any learning
experience means opening up to new ideas and new ways of doing things. As
mentioned before, Linux is in the UNIX family of operating systems. UNIX is
primarily designed to be used by professionals. You will have to learn some UNIX
concepts in this lesson, but that doesn't mean that Linux is a professionalsonly
operating system. Quite the contrary. Most major versions of Linux are designed to be
as userfriendly and as easy to install as any other operating system on the market
today.
Now that you know what Linux is and how good it is, there's one more thing we have
to do install Linux!
7
Lesson Two
Installing Linux
Some preliminary considerations
There are many different versions of Linux. Unlike other commercial operating
systems that are controlled by one company, Linux is free to distribute and use. So, in
the Linux world, there is a situation unlike what occurs in the proprietary operating
system world: a number of companies, organizations and individuals have developed
their own "versions" of the Linux operating system, known as distributions.3 There are
versions of Linux that were developed to be installed on computers that receive heavy
traffic, so to speak, like web page servers. Some were developed to be used in
networks where security is a priority; where sensitive information should only be
accessed by a privileged few. There are versions of Linux that are meant to be
installed on top of an existing operating system like Windows so people can try out
Linux under familiar conditions. There are versions of Linux that are designed to be
installed on platforms like Macintosh. There are versions of Linux with funny names
like "Chainsaw Linux" (no kidding) and "TuttiFrutti Linux" (yes, it's a joke).
What Linux is right for me?
Most PC users probably just need the everyday version. This kind of Linux has been
widely available for some time now. Unfortunately Microsoft Corp., who makes its
living selling people “ordinary” operating systems, have a lot to lose if Linux ever got
3 Distribution – an operating system based around Linus Torvalds's Linux kernel. They come in all
“shapes and sizes”. Many are meant to be installed and used by professionals on public Internet
servers or on graphics rendering farms and other environments. Others are meant to be installed by
the general public, as an alternative to proprietary operating systems. Each distribution reflects either
the needs of its target market (in the case of the commercial distributions) or the wishes of its
developers, as is the case with distributions created by individuals or nonprofit organizations.
Distributions are frequently called distros.
8
popular with the masses. For this reason they have done everything in their power to
“warn” the public that Linux is something that you probably don't want and don't
need. But in reality, Linux is just as easily installed and supports just as wide a range
of hardware as Microsoft Windows does. The PR department at Microsoft is coming
up with fewer and fewer reasons not to use Linux. Add to this the fact that in the
recently several major distributions have emerged that cater specifically to the non
technical user and you can see that Linux has truly achieved the goal of being all
things for all people.
Linux on PCs containing Intelbased CPUs
It would be impossible to cover all of the different types of Linux so this course will
only deal with standard versions of Linux that are meant to be installed on PCs with
Intelbased CPUs. You may have heard of some of the companies and organizations
that have created distributions for this platform, like Debian, Mandrake, Red Hat and
SuSE. There are others as well. There are even versions of Linux that offer
documentation and install programs in languages other than English. We should say
here that it is not our intention to endorse the products of the companies we have
mentioned here nor do we want to slight those companies that we haven't mentioned.
Linux Online maintains a list of all kinds of distributions.4 We invite you to consult
that list before deciding on installing any version of Linux.
Prepare your manuals
As we mentioned before, the major versions of Linux have perfected their products to
such a degree that they are very easy to install. Well designed programs will take you
through the process of installation step by step so that you will be able to get Linux up
and running in a relatively short period of time without any headaches. But even
commercial operating systems that are billed as being the most user friendly in the
world can't guarantee a 100% problemfree installation.
The best thing to do before attempting to install Linux is to get the manuals that came
with your PC out of the closet and dust them off. Major distributions of Linux have
taken into account most standard hardware such as video cards, modems and sound
cards, but as we said before, nobody can guarantee a problemfree installation for any
operating system. Though you probably won't need them, they may help to track down
a problem or prevent a future one. Now, go get those manuals, and we'll meet you in
the next lesson!
An actual install
4 http://www.linux.org/dist/ however, a more comprehensive list can today be found on
www.distrowatch.com.
9
Most reputable PC resellers will hand you a stack of manuals when you buy your
machine. But let's imagine that you got a handmedown PC from your big brother or
sister or you picked up your PC at a garage sale or you got the PC from some other
source that we really don't want to know about. You may be luckier than you thought.
Linux will actually install more easily on older PCs than on some newer ones. Then
again, it depends on how old it is. Don't try to install Linux on one of those old PCs
with a monochrome monitor where everything comes out a yucky green color. That's
TOO old!
Do you want a 'Dualboot' system?
OK, with or without manuals, now it's time to install Linux. You've got your version
of Linux and you just can't wait to use it. But there are a couple of questions you need
to ask yourself.
1. Do you have another operating system installed?
2. Do you want to continue to use it?
If you want to keep an existing operating system, and install Linux as well, you will
have what is known as a “dualboot” system. That means that you have a PC that can
use two different operating systems. I think that I should pause here and say that
everything that you can do with your garden variety operating system, you can do with
Linux. That means word processing, databases, spreadsheets, Internet browsers, e
mail, photo touchups, MP3, CD Players, cameras and then there are a lot of things
that Linux has to offer on top of all that that other operating systems don't. The
important thing is that you have the option to have both. Now, back to the install.
Downloading Linux
One of the most misunderstood concepts of Linux is that it is widely spoken of not so
much as a "free" operating system but as a "freebie" operating system. 'What's the
difference?' you may ask. The "free" ideally refers to the source code of Linux.
Microsoft won't give you the source code to their products so you can make
improvements (and we all know how much they need them), but the majority of Linux
distributions come with the source code or at least for the programs that aren't
proprietary.
The "free" that most people think of is the free of "freebie" or "handout". This is
somewhat fictitious. The truth is that there is nothing in this world that comes at zero
cost. If you happen to have a fast Internet connection and a CD burner, you may
download ISO5 images of the Linux distribution you have chosen (and that lets you
have them free of charge), but it will cost you money for the CDs and your time (the
5 ISO image – a file specifically created to be eventually burned into (ie. copied to) CDs. A Linux
distribution (see note no. 3) can be obtained by downloading the ISO images offered by companies
and organizations and burning them to CDs.
10
costliest thing of all). Linux really should never be touted as a zero cost option, but
better as an operating system that can be obtained and maintained at a very low cost.
If you don't happen to have a fast connection and a CD burner, you can still get Linux,
though, at a very little cost. You can pick up a nice boxed set from the makers of
commercial distributions. Personal PC users can pick up a nice operating system for
home use for around 3050 US dollars. These usually come with 90 days of tech
support, via email, in most cases. You can also get Linux from PC magazines that will
often provide CDs of the major Linux distributions and some basic installation
instructions for just the cost of the magazine.
Our pick for an example walkthrough installation and setup with be Debian
GNU/Linux.
Debian GNU/Linux
As it would be impossible in this course to talk about and give installation instructions
for all of the Linux distributions, we have chosen Debian GNU/Linux for an example
install. Why have we chosen this distribution?
It is:
1. A solid, quality Linux distribution with a long history (in Linux terms)
2. Nonprofit and noncommercial (which lets us off the hook on a lot of issues!)
3. Applicable to a wide range of uses and users, from newcomer to seasoned IT
professional.
4. Easily obtained and updated.
About Debian
The Debian project was founded by Ian Murdock in 1993. Its name comes from
Debra, his wife and his name (DebIan: ergo, Debian). One of the Linux world's most
illustrious people has been a primary developer of Debian, namely Bruce Perens. He
was one of the founders of Pixar, the company that created animated films such as Toy
Story, Monsters, Inc. and other popular films produced by Walt Disney Pictures.
Debian has no company behind it. The Debian project is sponsored by Software in the
Public Interest, a nonprofit organization dedicated to helping produce opensource
software and hardware. Despite its notforprofit status, Debian can and is being used
from anything from a Pentium you can surf the web with to the mission critical server
that has to be up 24/7 that you get the content from. We can also add a lot in between.
Though the installation procedure is not as easy as some commercial distributions, it
cannot be described as difficult either. We will go over this in more detail shortly. The
major advantage to Debian is that it can be updated easily via their much lauded apt
get system.
11
Getting Debian GNU/Linux
If you have a broadband connection (cable, xDSL or better), you can easily obtain this
distribution and install it. There are two major ways to do this. The most popular is to
burn the Debian ISO images to CDs and install. If you have a CD burner, this is an
ideal option. The second is to obtain a minimal ISO image especially designed for an
install over the Internet (i.e., downloading the files as the installer needs them). This
can also be done by downloading floppy disk image files instead of CD images. More
information on these methods can be found at http://www.debian.org/distrib/
If you don't happen to have a broadband connection, downloading Debian would be an
extremely frustrating experience. You may want to consider contacting a local
distributor of Debian CDs. Consult this page for further information about distributors
in your area: http://www.debian.org/CD/vendors/
Installation from CD
This is probably going to be the most common way of installing Debian, so we go
over installation using this method.
Preliminary considerations
You may be wondering if you can keep another operation system (i.e. MS Windows
which other one is there?) on your computer. You can.
Are we going to explain how to do it? Not in great detail. Why? There are a couple of
reasons:
• Lack of experience with the newer Microsoft products
The author must admit that he's installed a great number of Linux distributions
side by side with Windows 9x products. He hasn't done it with any of the more
recent ones, so advice on doing it would be of dubious quality.
• There's nothing you can do with Microsoft products that Linux won't let
you do as well
Enough said there. Please, before you flame the poor author: He did not say
that it would be easier with Linux. Sometimes it is, as a matter of fact.
• We don't work for Microsoft
We advocate alternatives to Microsoft products and not the continued use of
them, even in a “second fiddle” role.
What we can say about dualbooting
If you happen to have MS Windows 9x you must repartition your hard drive to make
room for Linux. You can either erase the drive and repartition a blank drive or you can
attempt to repartition a working hard drive. Ideally, what was done in the "old" days
was to install Windows in C: and D: partitions. This is relatively easy to deal with. As
12
a matter of fact, my first install of Slackware Linux was on the D: partition of my
Windows workstation.
If you've got one partition with Windows on it, there are some supposedly non
destructive resizing tools. They always tell you to back up your data before
proceeding, so I always figure what's the use in resizing when you can start clean
from scratch. You may decide you want to throw away Windows all together!
Summing up, I recommend Linux only installations. Linux has become quite "mature"
as an enduser operating system, so I find these stories about being "weaned" off
Windows to be ridiculous (the exception, supposedly, being those who run the
financial software 'Quicken'). If you've bought a new car, you don't have to be
"weaned" off that. You just trade in the old one and start driving the new one. The
graphic user interfaces available plus the ever growing numbers of productivity
applications (office suites, browsers, email applications, etc.) make it such that a MS
Windows user could have his/her workstation switched with a Linux machine
overnight and they would barely break a sweat getting used to it. Everything works
very much in the same way.
Installation of Debian GNU/Linux
Booting from a CD
Chances are, if your PC is less than 10 years old, you can start a Linux installation
right from the CDROM drive. The way to find out is to look at your computer's
BIOS. There's really no need here to go into what your BIOS is or what it does. Let's
just say that it's there and you need it for your computer to work. When you turn on
your computer, there's a little message that says 'Press DEL to enter setup'. Anything
that mentions the word DEL usually scares people. It shouldn't. Pressing DEL when
your computer boots up will just get you into the BIOS setup tools. It won't get you
into trouble, unless of course you start pressing buttons randomly. You'll see a blue
screen pop up with some menu items. What you need to select is the item 'BIOS
FEATURES SETUP' You'll see some more menu items. There's one that says 'Boot
sequence'. That's the one you want. If you use the page up/ page down keys, you can
set this item so that it says CDROM first. That just means that it will look for the disk
in your CDROM drive first when the computer boots. Press ESC and then choose the
item 'SAVE AND EXIT SETUP'. Don't forget to set it back to 'C' when you're finished
installing Linux. We'll remind you later.
If you can't boot from your CD there's an option to create a boot floppy. In your
machine's BIOS, you might just see A,C C,A and there's no CDROM mentioned
there. Don't panic. You can make a boot floppy. They often come with boxed sets, but
if you yours didn't come with one, we'll cover how to create one further along.
13
Partitioning
Your hard disk is like a pie. You can divide it into sections. Unlike a pie, after you've
divided it, you can't give a piece to the dog. My dog did try to eat my hard disk once
and he really relishes the floppies I leave lying around, but alas, I digress. For
example, if you had two partitions, popular operating systems would generally call
them C and D. You can call them Ginger and Fred, or Ginger and Marianne or even
the Professor and Marianne if you like. I just use these bad jokes as a way of saying
that C and D are naming conventions that belong to other operating systems. Linux
doesn't use them. Linux may call them hda3 and hda5 for example. We'll get to that in
a minute. Then you will need another partition known as a 'swap' partition. This 'swap'
partition is just a way that Linux uses to get more memory so that you don't run out of
it.
The classic way of partitioning your hard disk is with a program called 'fdisk'. The
program comes with a lot of whistles and buzzers and flashing messages that say
"Danger, Will Robinson". There's a version for Linux too, but it doesn't mention Will
Robinson. We want to say here that this is the SWAT team method of doing it – the
scorchedearth policy of partitioning. If you have that important term paper on your
hard disk, or pictures of that dream vacation to Hawaii that you haven't shown to your
Aunt Betty yet or your best DOOM scores, you'll need to make backup copies of
them. The repartitioning using this method will get rid of them – forever! [cue
ominous organ music].
But installing Linux isn't dangerous and if you choose to install you may not need
such a drastic solution to your partition problem. As we mentioned before, If you're
fortunate enough to have a hard drive with more than one partition (the old C: and D:
routine), then it may be just a question of moving some files around. Unfortunately
this lesson can't take into account everybody's individual circumstances.
There's a tool called FIPS that comes with major Linux versions. This will rearrange
your hard drive so you can install Linux. There are also other commercial products
that will do the same. That may be an option for you, unless you've got a hard drive
that's bursting at the seams. You should know that any decent working Linux system –
and by decent, I mean, having the programs that will let you do anything you did with
your Windows system – will take at least 2 gigabytes. Please keep that in mind. And if
you want those photos of Hawaii on there, I'd plan for a bit more.
To talk about where Linux and other operating systems should go. In any situation
where you've got two things sharing the same space, like two people sharing the same
apartment, one person will always exert his rights over the other. Other operating
systems usually want to be the only ones in the computer, so even though it's really
not going to be this way, you have to install them in the first 'primary' partition, and
that way it thinks it's the only one there. That means installing it in hda1 in Linux
speak. So remember, if you've chosen to go the fdisk route, the other operating system
14
should be reinstalled first. When you've got that reinstalled, you are free to install
Linux in what's left. Once you've installed Linux, you can actually see the other
system's partition, sort of like those phony mirrors at the supermarket. We'll talk more
about that in another lesson.
Plunk that CD in the drive
Okay. Now is the moment of truth. We've got the CD in the drive, and we're ready to
go. Restart the computer. This should now boot the Linux kernel located on your CD
ROM.
What you'll have to do first is partition the hard drive. There is an easy way to do this.
You can dedicate the whole hard disk or nonWindows partition (depending on the
type of install you're doing). There is a better alternative. That is to partition your hard
disk even further and put "parts" of Linux on separate partitions. For example, this is
the scheme that works for me:
Let's take a 10 gigabyte hard drive as an example. First, you should see how much
RAM you have. From this figure, you create what's known as a SWAP partition. This
is simply a way that Linux uses to get an extra memory boost. Custom dictates that
your swap partition be double your ram memory. So if you've got 256 megabytes of
RAM, the feel free to make a 500 megabyte swap partition. Then my partition scheme
ends up looking like this:
Assign partitions to look like this. Don't worry about the /usr and /home parts. That
will come after. You must indicate here that you want / to be the bootable partition.
/usr will contain most of the programs that will run on your machine. /home will
contain your personal files. This kind of a partition scheme may come in handy if you
have problems with your hard disk. You may be able to save information if it's located
in different partitions easier than if it were only one big partition.
Before we actually assign the other partitions their places and functions, we need to
initialize and activate a the swap partition. Do this now.
Now you should initialize the / partition the one that will boot the Linux kernel.
15
Now, there is what I consider a little glitch in the Debian install. It doesn't really take
into account that you want to initialize /usr and /home partitions. Don't go to the next
step yet. You should go back and initialize these partitions now before proceeding.
Sundry installation tasks
At this point you should have your hard drive partitioned and these partitions assigned
to what areas they'll be housing.
At this point, you'll have to choose a 'hostname' or name for your computer. Use
whatever naming scheme is comfortable for you. After, you should choose a 'domain'
name. Even if your not running an Internet server and even if you don't have a network
you should choose a name as if you had one. Normally if you were in fact a server
providing Internet services, you would choose a name and append .com, .net etc on
the end. I would, of course, be a name registered with an official domain name
registry. In the case of a single machine or a network that's connected to the outside
only by way of a dialup connection, you should choose a single name without the dot
extension.
Now you should enter your ISP's domain name server IPs. Each block (the four
numbered set separated by periods) should be separated by a space.
Now, as we're installing from a CD, you should choose 'CDRom' for the instalation
procedure. You should also choose the settings 'make system bootable'.
Your hard disk is basically a piece of metal with a metal disk flying around in it at
incredible speeds. It essentially does nothing unless you tell it to do. At this point,
we're going to tell it to boot up the Linux operating system. If you're contemplating a
dualboot system, you can also tell it to ask you to choose from different operating
systems at boot. Debian uses a program called 'LILO' to do this. Later, you can
actually make alternative versions of the Linux kernel and have LILO boot them.
Right now, your safest bet is to install LILO in the 'master boot record' when the
install program asks you. The "MBR" is a little slice of the hard disk pie reserved for
moments like this!
The program will now ask you to create a rescue floppy. These will come in handy.
For example, I have often made the fatal mistake of *not* correctly configuring LILO
when I have made a new Linux kernel (yes, you can make them from scratch!) and my
16
system has become unbootable. You can always rely on a rescue floppy to get you out
of this situation.
OK, now's the time to reboot the basic system that Debian has installed. You need to
remove the floppy and the CD from the drives. It might be a good idea now, as your
machine reboots, to go back into the BIOS and set it back for the machine to boot
from your hard drive first (instead of from your CD drive). But at least make sure to
remove the CD or else it will boot the CD again and start the install process again.
Reboot and basic configuration
Your new Debian GNU/Linux system is now rebooting. When that's finished, you'll
have to answer a few questions about configuration.
You'll now be asked if you want to use MD5 passwords. Without getting into a lot of
technical jargon, MD5 passwords are protected with an extra layer of security. You
should choose this if you think you'll be needing extra security. You'll have to evaluate
this on your own. If you don't choose this, you'll be asked if you want a 'shadow'
password system. Once again, without going into any technical jargon, this is another
Unix scheme for extra security. You should always answer 'yes' to this one because
without it, your password, especially if it's some dictionary word, would become very
easy to crack. By the way, you should never use a dictionary word as a password.
As we're on the subject of passwords, now it's time to enter the password for the
famous 'root' account. 'root' is the administrator of the system. It's also known as the
superuser account. We'll get into more detail on the duties and privileges of root later
on. Suffice it to say, you should now type in a password for the 'root' account. Please
choose one that's easy for you to remember but would be difficult to guess or "crack".
For example, if I were a Star Trek fan, I might be tempted to use Spock as a password.
Spock probably isn't in the dictionary, but it might be so well known now that it would
be found in any program that crackers use to get into systems. Therefore, I would
choose something a little less wellknown in Trek lore and modify it somewhat. Trek
fans will remember that mutant brat who once tried to take over the Enterprise,
Charlie X. Well, 'ch4rl13X' might be a good password. Taking the some letters and
replacing them with similar looking numbers. This is an acceptable password
procedure. The best is, of course, creating a random string of lower case and capital
letters and numbers and just remembering it. 'C2jl7y2B' is an excellent password. It is,
however, difficult to remember. In the end, everybody comes up with his/own own
scheme that works.
Now you should create an account to work with normally. What I mean by "normally"
is that Linux is a true multiuser system, so one machine can be used by hundreds of
users. When each logs in, he/she is restricted to modifying only the files owned by
him/her. This insures a lot of security and removes a lot of headaches. You should
never do routine work as root. This account should be only used to perform important
17
administrative tasks. Feel free to use your first name or the first letter of your name
and your last name as the login for this account. Follow the password convention
you're comfortable with.
Now, you'll be asked to remove PCMCIA from the system if yours doesn't use it. Feel
free to do so.
You will now be asked if you want to configure your system to use your ISP. If you
have a dialup connection, this is a good time to use it. If you connect by way of
broadband or better, you can skip this part.
At this point, we're ready to choose the rest of the packages that will make up our
Debian system.
Completing the install process
Now it's time to begin inserting each one of the CDs you have. They will be scanned
for available packages for install. There is a maximum of 8 in the set. Insert each one
and wait until you are asked for another.
When you have completed the scanning process, you will be asked to choose another
'apt' source. With Debian, you can download and update packages automatically right
off this Internet with the 'apt' system. We will configure this later, right now it's best
not to choose another apt source besides the CDs.
At this point, if you are connected to the Internet by way of broadband for example
and the install program can make a connection to Debian's security site, it will now
start searching that site for security updates. From the time the ISO images are
released to the point where you are installing, security flaws may have been found in
certain programs included with Debian. For this reason a check is made and any
programs with flaws are marked and updated copies downloaded and installed.
After the security updates are finished, you will be presented with the possibility of
doing a simple install with The Debian Task Installer. This will install programs after
you have indicated your general preferences from a menu.
If you are more adventurous, you may choose the more advanced install process by
way of dselect. Here you will choose packages "by hand" from a list of hundreds.
Though the dselect interface is not visually appealing and may appear daunting to
newcomers, it is fairly straight forward and is actually quite user friendly in the sense
that it is almost impossible to run into trouble with the packages you want to install. If
you were to choose a package that conflicted with something else, you are notified.
That way, you can either choose to keep the package that Debian recommends or "un
select" the package so your own choice can be installed.
18
At the fork(s) in the road
Here we reach the end of the install section. You will have to do some more work in
this department, but due to the fact that the packages each person might choose and
the hardware in his/her machine, we can't really document accurately what's going to
go on from here. Our install road has reached a plethora of forks in it. Some simple
advice: just answer the questions as accurately as you can and you should be fine.
Post Install
We'll assume that you've got a working Debian system now. If you've got a broadband
or better connection to the Internet, you should now configure the aptget system
which will allow you to update your system quickly and painlessly. It will also allow
you to get new programs by downloading and installing them automatically.
mv sources.list sources.list.old
This renames the file sources.list to sources.list.old. sources.list is what told the
'dselect' and 'apt' programs where to get the packages to be installed. Now we're going
to change things a bit. We'll tell them to get packages off the Internet directly. We
need to create a new sources.list file and add our new package sources to it. Do this
first:
vi sources.list
This brings up the text editor 'vi'. There are people who love this program so much,
they will challenge you to a pistol duel at 20 paces if you tell them you think it's lousy.
If you have zero experience with Linux or Unix, 'vi' is probably *not* the text editor
for you at this point, but with a few simple strokes of the keyboard, we can do what
we want for now.
Hit the escape (ESC) key and the letter 'i' and your ready to insert the following.
You may want to go to Debian's homepage and look up suitable mirror sites nearer to
you. I'm sure the people who maintain the Debian website would appreciate it too!
19
Now, to save the file, hit ESC again and ':' the type 'wq' (meaning writequit) and your
file is saved.
Now you're ready to keep your Debian system in shape. We'll give you a refresher
later on in the course, but you will probably be making use of these commands while
you use Debian.
20
Lesson Three
Creating your routine in Linux
When you work as root
You have now installed Linux and the first thing you did was login as 'root'. Then you
provided a password so that you and ONLY you could login to the system as 'root'.
When you decide to work as root, you had better go into a phone booth first and
change into a blue suit with a big 'S' on the front because 'root' is known as the
'superuser' (you can skip the red tights if you want).
That's really not meant to be just a witty reference to the Man of Steel. Actually, it is
much more glamourous to be 'Superman' but root is actually more like the 'janitor' of
the Linux system. Root has the keys to everything, he can shut off the lights, shut off
the heat, lock you out of the building; he has to clean up the system and in the end
make sure everything runs. And the most important thing about being a janitor he
sees everything.
'root' is not for routine work
As I mentioned, Linux makes your computer a true multiuser system, that means that
besides root, you can and should work as another person. I say 'should' because doing
routine work as 'root' could be hazardous to your health. When I first started using
Linux myself, information was not all that readily available and I still had that 'one
computer one user' concept in my brain. It was after I had trashed all of the files and
programs that make Linux run that I realized that working regularly as root wasn't a
good idea.
Working as another user
Well, then how do you do your day to day work with Linux? Easy, working as a user
other than root. You may pick the name you like. Try your name. If your name is
"Bob" then you could create a user account for 'bob'. By the way, if Prince Charles is
reading this, Charles Philip Arthur George is a bit too long and has spaces, which
Linux doesn't like he should try 'charlie'. One thing I find EXTREMELY helpful is
that with Linux, I can work as different people. It should not be inferred here that I
have splitpersonality disorder. I am just a guy with a couple of different jobs. This
way I can organize my work a lot better and backups are easier this way too.
21
Adding a new user
Well, Bob, now it's time to create your account. If your name is Hrothgar, substitute
'bob' for 'Hrothgar' or 'Hrothie' for the remainder of the lesson.
Now 'root' has to do this stuff. Yes, I know I just warned you about working as root,
but this is where you have to exert your authority. Most major distributions have tools
to do this. SuSE, for example, has a nice tool called YAST which lets you add users
painlessly. You just fill in the correct information. Consult your Linux version for
information on their tools. There is also the getyourhandsdirty way of doing this.
Actually you won't get your hands dirty unless you're eating barbecued ribs at the
same time.
Using 'useradd' and 'passwd'
To add a new user, you can also use the command 'useradd'. Kind of a logical name,
isn't it?
Try this: useradd bob. You probably won't see any fireworks go off. You might not
see anything. That doesn't matter. Linux has been told that there's a new user and his
name's 'bob'.
Now you should give yourself a password.
Do this: passwd bob.
Linux will ask you for your password. Follow the same advice I gave previously about
passwords. Also, don't use your 'root' password. Like 'one man, one vote' it's 'one user
one password' You will be asked to repeat it.
Virtual Terminals
One of the coolest things that Linux has to offer is the concept of virtual terminals.
Back in the days of MSDOS, one program could only be run by one user at a time.
Linux in nongraphics mode may resemble MSDOS somewhat, but that's where the
similarities end. Linux is a true multitasking, multiuser system. Unlike MSDOS,
you can can work as more than one user with more than one program at a time.
The ALTF keys
Let's say, if you were working as a user, 'bob' for example, and you found that you
needed to do something as 'root'. You wouldn't have to shutdown the program you
were working with. You could just press ALTF2 and Linux will prompt you to login
as a different user, in this case, 'root'. You'd just type the root password and then you
can do stuff as 'root'. Pretty cool, wouldn't you say?
22
The combination of ALT plus the F keys will allow you to login as a different user, or
as the same user, but to run a different program. All you then need to do is type: 'exit'
when your finished, and then press ALTF1 again to get back to your original
terminal.
A preview of virtual terminals in Xwindow
It's true that the 1990's brought us the era of the graphic user interface, popularized by
Macintosh OSes and Microsoft Windows. This gave us the opportunity to have
various programs running at the same time. The Xwindow system of Linux will let
you do this as well, but then we can add the concept of multiuser to it.
If you've been experimenting with your windows manager already, you might want to
try one more thing. The combination CRLALTF6 will get you out of your windows
manager momentarily so you can login as a different user. Pressing ALTF7 will get
you back to your windows manager again. We'll mention this again in the lesson on X
window.
Note that to exit from Xwindow you also need to use the Control (CTRL) key to
change your virtual terminal.
What's on the screen?
So after logging in as our user 'hrothgar', we see something like this:
[hrothgar@mybox hrothgar]$
What does it mean?
Well first word is 'hrothgar' which tells us which user is currently logged in. Second
readable word is 'mybox'. This is the name of the computer that we're logged in with.
Remember that the '@' sign is pronounced as 'at', so it's “hrothgar at mybox”.
Then we see 'hrothgar' yet again – this is just a coincidence because the directory
we're in just happens to be named 'hrothgar' as well. When we go into directory 'stuff'
we'll see something like:
[hrothgar@mybox stuff]$
Finally, the dollar sign is important even if it doesn't mean money. It tells us that we're
just a plain, ordinary, user. When we were root before we could see the sign '#'
(pronounced as: hash). Working as root can be very dangerous, so before typing
something like 'please delete all my files and uninstall the system, please' it's good to
look at this character to the left and think about the consequences.
Shells in Linux
23
The Linux shell
When you're running Linux and start to type things on that black screen, you are using
a shell. Any operating system uses a shell to get commands from the keyboard to the
computer. It's a lot easier than punching holes in cards like they used to do in the old
days. There are actually programs for Linux where you talk through a microphone and
Linux will carry out commands that you've programmed in advance. It's really cool.
For now, though we'll concentrate on the keyboard.
The most popular shell used for Linux is the bash shell. bash means "Bourne Again
Shell". It is a free version of the Bourne shell and uses a little play on words, as you
can see. Our lessons will deal with that one. There are also: C Shell (csh), Korn Shell
(ksh), TC Shell (tcsh), Z Shell (zsh)... csh or tcsh is common on other UNIX systems,
such as BSD, Solaris etc.
Why you need to use a shell
The most common commands a computer receives are ones to copy files, move files
around, list files and delete files. Popular operating systems have perfected this to
such a degree that they have graphic interface programs to do all this for you just by
moving the mouse around and clicking on a few buttons. Linux has these programs
too, but anybody who's seriously thinking of using Linux on a daytoday basic should
be familiar with the commands that you type in by hand. Some people see this as a
throw back to the old days. I see it as a way to have more power over your computer
because even those operating systems that are billed as more 'user friendly' have
provided you with a shell, just in case you need it. And sometimes you do!
Usefulness of shell has been recognized even by Microsoft – a lot of focus recently
has been made on creating a better shell for their Windows operating system. MacOS
X also includes a bash shell. Even most games have a “console” that pops down from
upper edge of the screen to enable entering some advanced commands. If you intend
to just use Linux you probably don't need a shell – but if you want to be an
administrator, using shell is the basic and essential thing to know.
The Linux directory tree
Now's the time to learn a little bit about various directories in a Linux system. We'll
learn about where Linux puts it stuff, where to find stuff and a little bit about what
that stuff is.
The core document that describes the standard layout of directories in Linux is called
FHS (Filesystem Hierarchy Standard).6
6 http://www.pathname.com/fhs/
24
What's in your user's directory
When you create a new user, there is a directory created for that user in /home. To see
what's in this new directory, you have to do the following.
Go to the /home directory. typing:
cd /home
you can make sure you're in the /home directory by typing 'pwd' You'll see this:
/home
Now you need to type:
cd bob
MSDOS users will be familiar with that one.
You can type:
ls -a
to see what's in the directory. We'll go into more detail with the ls command later.
With the a option, you'll see some files that begin with a '.' (period/dot). Those would
normally be hidden from you if you didn't use the a. A two such special files are '.'
and '..' '.' means 'this directory' while '..' means 'the directory above this one'.
Now you can go to work as 'bob', or 'hrothgar' or whoever you happen to be.
Getting in and out of directories with 'cd'
We saw a few commands in the last lesson, but we didn't go into them much. We will
handle a lot of commands in more detail in later lessons. This lesson will cover those
commands which you will need to see what's under Linux's hood.
The first one we should look at is 'cd'. Again MSDOS users will be familiar with this.
cd will get you in and out of directories.
Try this one:
cd /
This will get you into the 'root' or main directory. It's the directory of directories, the
king of kings, your show of shows. It's name is a slash ('/'). The root directory
shouldn't be confused with root's directory. That is /root.
The basic directory structure in Linux
Now type this:
ls
You will probably see something like this:
cdrom home opt tmp
25
dev lib proc usr
bin etc lost+found root var
boot floppy mnt sbin
They will be blue in color. Those are directories.
The 'ls' command has many more interesting parameters besides 'a'. To get a list of
those parameters type:
ls --help
This list is a bit long – for now, you can hold down CTRL and press PageUp and
PageDown keys to scroll through this list.
In DOS, most parameters are prepended with a slash (/), but in Linux slash is used for
directories, and for parameters we use minus (). As a rule of thumb, there are two
type of parameters:
● minus and a single letter (such as 'a')
● two minuses and a word (such as 'help')
The first one is shorter, but second one gives you a better idea of what the command
will do. Many parameters come in both flavors, so you can try them out the way you
like.
Another cool rule is that most commands will give you a list of parameters by typing
one of these:
cmd --help
cmd -h
cmd
If you're just dying to see the list of parameters, just try it with these three. One will
surely work ;) Some command also take parameters without minuses, but we will
arrive to that later.
The /bin directory
Now type this:
cd bin
Type ls again.
This is the famous bin/ directory. You know, I have always felt this one was
misnamed. Like when people say, 'That's no good, throw it in the bin'. Actually, bin/ is
one of the most important directories in Linux. You'll find all of the most used
commands there. Right now you should be seeing a lot of red (or green, depending on
your version of Linux). Those are programs.
A basic thing about directories
26
When using commands such as 'cd' it's important to know exactly where we are. The
prompt is helping us with it by showing the current directory left of the $ or # sign. we
can line up several directories instead of typing 'cd' multiple times. For example, if
we're in root and wish to go to bobs home directory, we can type:
cd home
cd bob
or we could type this:
cd home/bob
Here the slash sign is used to separate directories.
Remember that we said that / is the name of the root directory. We can use it as well,
before other directories, such as this:
cd /home/bob
With this command it doesn't matter where we are, because it's clear that we are going
to a directory named 'home' that is below root, not to another directory that happens to
also be named 'home' but is below 'some/other/directory/made/to/confuse/us'.
In the former case we were tracing a path to some location from where we're right
now, but in the latter we were tracing it from root. Because of this they're called
relative and absolute paths. Notice that all the titles in this chapter are in fact absolute
paths.
The /etc directory
Now lets look at another directory. There's a long way and a short cut. First the long
way.
● 'cd ..' will get you out of bin/.
● 'cd etc' will get you into the etc/ directory.
● or you can just type 'cd /etc' in the bin/ directory and it will bring you to the
etc/ directory .
Anyway, you are now in the etc/ directory. This houses most of the configuration files
for Linux. lilo.conf, the file that tells you which OS to boot is in there.
If you type 'ls lilo.conf', you'll see: lilo.conf And you don't even have to type the whole
thing. You could just type 'ls li' and push the tab key. Linux will type the rest for you.
Isn't that cool!
Some more cool shortcuts
Try this one: type ls m push the tab key. Linux is going to beep a couple of times,
but you keep pushing. You will now see every file in the directory that begins with the
letter 'm'.
27
Now add an 'o' on to ls m so you get ls mo – now push the tab key. You should see
'motd'. This is a file that contains your startup message. SuSE has a famous one that
says 'Have a lot of fun!'. I like that one so I haven't changed it, but you can change it so
that Linux says anything you want when you log in.
Do you want to make sure that lilo.conf is still in there? You don't have to type
'lilo.conf' or even part of it and press the tab key anymore. You just have to press the
up arrow. Your last commands will appear when you do that.
Your commands are saved in a history file located in your home directory. The more
times you press the up button, the farther back in time you go. Pressing the down
button gets you back to your most recent commands. Just stop on the command you
want and press 'enter'. You can even type the command history and all of the last
400 or so commands you've typed will be presented. As you get more proficient in
Linux, you'll will find that this really comes in handy. You can often find out the
answer to the question: How did I do that? by consulting your shell history.
... (!! !xyz etc.)
The /usr directory
Let's talk about using some options with commands.
For example, typing: ls -l will give you more detailed information about the
contents of a directory.
In Linux, everything is a file
Yes, not only is that digital photo of The Eiffel Tower a file but your monitor is a file
too! How can that be? Let's try to explain it.
The /dev directory
If you do cd /dev and then ls, you'll see a lot of yellow outlined in black. These are
the devices that your system uses or can use. Everything is considered a file in Linux,
so your hard disk is kept track of as a file that sits there. If you're using an IDE hard
drive (as opposed to SCSI), your hard drive will be known as /dev/hda. Don't delete
that, because your hard disk will spin around, come jumping out of your computer,
28
land on the floor and spill out ooze all over the place. No, not really. You will
probably not have to look in /dev very much, so don't worry about that.
The /boot directory
Doing: cd /boot will get you into the /boot directory. You will not find any boots
or shoes or footwear of any kind there. That's where the Linux kernel usually is.
Power users may change the location of the kernel for reasons of their own (they may
prefer /shoe), but it is normally placed there on most systems. You will eventually
have to use this directory, because you may need to use two or more different types of
kernels in the future. That will be taken up in a more advanced lesson.
The /proc directory
root's directory /root
The /sbin directory
/sbin is another one of those offlimits directories. You may look, but you can't
touch. This directory is like /bin in that it has frequently used programs in it, but
they're only meant to be used by root. 'shutdown' is in there. Only root can shut down
the system. If a user other than root tried to shut down the system, he or she would get
a message saying that only root can do that. Then that person would be followed by
the secret police for three months.
The /tmp directory
/tmp is a directory that is used to store temporary files, as the name may suggest.
You will find later on that when you use a windowing system with Linux (for example
KDE), this window manager will create files there for temporary use. When you
double click on an icon of a photo, the photo comes up for you to see but a temporary
file is created while you're looking at the photo. The temporary file is deleted when
29
you close the KDE image program. It's mainly the programs that work under a
window manager that take advantage of this directory.
The /var directory
/var is a directory for certain files that may change their size (i.e. variable size) For
example, there are a few excellent databases for Linux. One is called MySQL.
Normally, MySQL keeps its data in a subdirectory of /var called /var/mysql/. If I had
an ecommerce website, I would have a database to register purchases. That database
would obviously grow in size. And if it didn't then I'd be in trouble. It is also the
normal place where email servers store their incoming mail. Again, email varies in
size as well.
The /lib directory
/lib is for library files, which is where its name comes from. Programs may use
libraries to carry out their functions. Different programs use the same libraries, so
Linux will store them here so that every program knows where to find them. You will
probably not have to worry about this directory much unless you start getting
messages like 'can't find shared library...'. That will sometimes happens when you've
downloaded some program and had to compile it yourself from source and even
then, getting what are known as "dependency" problems are quite rare. Most
programs, even when compiled from source, usually have a preconfiguration program
that make sure they can find what libraries they "depend" on to run. If they don't,
they'll tell you you can't install the program.
The /usr directory
/usr is not a directory for users (that would be /home). It's a sort of a copy of root (/)
– its subdirectories include bin, etc, lib (the full name of these directories is: /usr/bin,
/usr/etc, /usr/lib) and some other directories. Well this directory is the closest to the
thing that is called “Program Files” in Windows. /bin doesn't contain all programs,
only the important system components. Separately installed programs such as a web
browser or a word processing program installs under /usr. Its program files are in
/usr/bin, libraries are in /usr/lib etc.
Sometimes multiple programs share the same files, such as icons or wallpapers. These
files can be found under /usr/share.
There is also yet another subtree: /usr/local. This is used for programs which are not
installed by system “program installer” but are manually compiled and installed by
user.
The FHS and differences between distributions
30
There are several directories described in FHS that aren't actually used by any
distribution that I know of except SuSE. This course attempts to teach you to use all
and any Linux distros, so we will dedicate quite some space to describing the
differences among various distros.
/opt is yet another subtree that in SuSE is used for really large packages, such as
KDE, GNOME and OpenOffice. So you'll see something like /opt/kde, /opt/gnome,
/opt/openoffice. Each of these will then contain subdirectories such as bin, etc, lib and
share.
The /floppy, /cdrom and /mnt directories
Most installations of Linux will also provide these directories:
/mnt
/cdrom
/floppy
These shouldn't contain anything. Later on, we'll explain in more detail what these are
for. Let's just say that in Linux, if you want to see what's on a floppy disk or a CD,
you're not going to be able to just click on an 'a:' icon or a 'd:' icon. You're going to do
cd /floppy or cd /cdrom .7
If you try that now you probably won't see anything. As I said, more on these
directories later in the course.
Home Sweet Home
We talked about /home before. This a directory for storing users' personal files. All of
us have certain preferences for using programs. These preferences are usually
included in configuration files which are also stored in users' home directories. Most
of these files start with a '.' (period/dot).
If you go to your home directory, 'cd /home/[username]' and type:
ls -a
you will see these files.
There are two shorcuts for going to home no matter how you're logged in. One is this:
cd ~
7 In RedHat, Mandrake or Debian, you should look for /mnt/cdrom and /mnt/floppy. In recent versions
of SuSE it's /media/cdrom and /media/floppy.
31
In general, everywhere that you need to enter your home directory, you can just type
the tilde character (~). It will be substituted with /home/username – where username
is replaced by the login of user typing this. But with the 'cd' command you can also
just type:
cd
with no parameters. That should take you straight to home. There is a number of other
useful shortcuts that we won't mention right now.
Well, we've looked under Linux's hood, so to speak. In the next lesson, we'll take her
for a little spin.
Shutdown and restart
Shutting down Linux
At this point you should have installed Linux, and you've looked around at what you
have. And then when you're finished you'll have to shut off your computer.
Actually, there are computers that are never shut off. Imagine if your ISP shut off the
computer every night! The Internet is a 24/7 business so that wouldn't be practical.
There are also people who probably just shut off their monitor. As you probably get
some sleep occasionally, so we should maybe let our machine have a rest too once in a
while. For this, we'll use the shutdown command.
The importance of the 'shutdown' command
Shutdown for a single computer
The most common way of shutting down a single user Linux system is for you as root
to issue the command:
shutdown -h now
32
You use the 'now' parameter when you plan on shutting your computer off at that
moment, as opposed to some later time.
You'll see a message like:
Linux is going for system halt NOW
It will start to shut off programs that are still running on your computer and you'll see
it all happening. That's because Linux is a transparent system. It lets you see
everything it's doing. It won't give you a simple message telling you to wait and then
another one telling you you can shut it off now. If something is causing a problem, it
will tell you about it when it starts up and when it shuts down. That way, if you are
having a problem, you may be able to track it down. If you don't know how to solve it,
you can tell another person what you saw and he or she may be able to help you.
Rebooting the computer
The other command that you will probably use is:
shutdown -r now
If you have installed a dualboot system and you want to use the other operating
system (why would you want to do that?), you would use this command. You will get
a similar message as with the h (halt) option that will say something like:
System going for reboot NOW
The basic reason behind all of these messages is that Linux was conceived to be a
networked operating system. You have people at workstations on the network busily
doing their work. The last part of the shutdown command now is fine for a singleuser
home PC, but on a network system this would be changed to indicate a time. That way
people would have a chance to finish what they were doing before the system went
down for maintenence. Using 'now', in a network, would probably be hazardous to the
health of the person who sent that command.
The next time you shutdown your system, you may want to try using some time
options instead of just now. For example, you may want to try shutting down the
computer at a given time.
shutdown -h 20:01
Which will shutdown the computer at 8:01 PM. You could also try:
shutdown -h +5
That shuts down the computer in 5 minutes time.
Now you know the correct way to shutdown your Linux system. In the next lesson
we'll talk using the system again.
33
Lesson Four
Text Editors in Linux
If I were to choose one of the main reason why people use PCs, I would definitely say
for writing. With a computer and a word processing program, cross outs, white out
and crumpled up paper has disappeared forever. All those old SmithCoronas got put
away.
Linux is just as well suited for word processing as any other operating system. There
are several excellent word processing programs for Linux like AbiWord, Kword (part
of the KOffice suite) and the OpenOffice.org suite's word processor – Writer. We'll
talk about these kinds of programs in a later lesson. First, we should talk about the
terminal mode text editors that are available for Linux.
Why use a text editor?
A text editor is just like a word processor without a lot of features. All operating
systems come with a basic text editor. Linux comes with several. The main use of a
text editor is for writing something in plain text with no formatting so that another
program can read it. Based on the information it gets from that file, the program will
run one way or another.
In Windows most system configuration is stored in the socalled registry. Registry is
encrypted and so can be modified only through a special program called Registry
Editor. The best thing that can be said of this program is that it's cryptic. Many times
I've suffered registry corruption where system needs to be repaired and sometimes
even reinstalled. Many a crash was caused by registryrelated problems. And what if I
want to fix this registry from other OS or other computer, or carry it around on a
floppy? Impossible!
With Linux it's different – each program stores its configuration in its own file. These
files, as we remember, are stored in /etc directory. Most of these files are plain text,
and so can be modified with any editor you like, even with Notepad! The cool thing
about these files is that they contain “comments” which explain what's going on and
also examples of proper configuration. This makes configuring Linux a lot easier than
stumbling around Windows registry.
The text editor 'vi'
34
The most popular text editor for Linux is called vi. This is a program that comes from
UNIX. There is a more recent version called vim which means 'vi improved'. The
problem with 'vi' or 'vim' is that a lot of people don't like it. You have to remember a
lot of key combinations to do stuff that other text editors will do for you more easily.
We should go through some basic 'vi' commands, because I have found that 'vi' is
good if I want to get into a text file quickly and change something or I want to write a
short note to myself. Also, 'vi' is the only editor that you can count on being there on
every kind of *nix, even on those old Unices from early 80ies. I generally do not use
'vi' for anything that requires more than about 30 seconds of work, but there are
people who swear by 'vi' and do all kinds of things with it like designing entire
websites.
Working with 'vi'
Let's make a text file. Type:
vi tryvi
You'll see a line of tildes down the left side and the name 'tryvi' at the bottom and
[new file].
To write something, you have to press ESC and the 'i' key (i for insert). Even if you
don't press 'ESCi' it usually gets the idea that you want to type something and lets you
do it after a few keystrokes. You should get used to the 'ESCi' keys so you don't end
up writing 'ar John' instead of 'Dear John'.
Press ESC + 'i' then type:
hello vi
If you wrote “jello vi” or “jello bi” or something I don't want to know about, you can
always erase your mistakes with the backspace key.
To save this file, you would press ESC then the colon key ':' then 'w' (write)
To save the file and quit vi, you would press ESC, the colon key ':' then wq (write,
quit)
To quit without saving, press ESC, ':' then 'q'. Vi may protest if you've written
something and you don't want to save it. If you press ESC ':' 'q!' with an exclamation
point, vi will accept it and not save your changes.
That's vi in a nutshell, or more like a sesame seed. There are a lot of commands in vi
and you may explore those on your own at a later date, on your own terms and in the
privacy of your own home.
'pico' and 'joe'
35
'pico' and 'joe' sounds like a comic strip. Actually, they are two other text editors that
I like and I think are a little easier to manage. They're like 'vi' in that you use them to
create and edit nonformatted text, but they're a little more userfriendly.
Using 'joe'
'joe' was created by Joseph Allen, so that's why it's called Joe. I suppose if his name
had been Hrothgar Allen, it would have been called 'hroth'.
To use 'joe', you could type:
joe tryjoe
You won't see the tildes like with 'vi'. It looks a little friendlier. The majority of joe's
commands are based on the CTRLK keys and a third key. The most important of
these is CTRLKH which gets you 'help'. Help shows you the key combinations to
use with 'joe'.
The most important thing about 'joe' is the logical concept that you can just start
writing if you want. Try writing anything you want.
To save it, press CTRLKD. To save and quit, CTRLKX.
To quit without saving, CTRLC, (without the K).
If you want to see the other features of 'joe', press CTRLKH, as I mentioned before.
My favorite little added feature of 'joe' is that if you edit a file again, it will save the
previous file with a tilde on the end, like 'tryjoe~' That little tilde file has saved my
life a couple of times. Well, maybe not my life, but it has saved me a lot of work. I've
made some changes to a file and then found out that wasn't a good idea. I could always
fall back on the tilde file, which is a copy of your previous edit.
'joe' is a very good option for writing those short text files that you'll need.
Using 'pico'
'pico' is another friendly text editor.8 If you type:
pico trypico
You'll see the commands you need in 'pico' specified at the bottom. You can just start
writing anything you want.
To save the file, press CTRLo. To save and quit or to just quit, press CTRLx
8 Actually, most distributions now don't have 'pico' but 'nano'. GNU/nano (as it is properly called) is the
next version of pico. Original pico authors were very lazy with adding new features to this editor, but
also gave it a license which prevented others to add those features themselves. Thus, nano was made
from scratch. For this reason I prefer nano, but regardless of politics it's just a better version of pico. If
you're too used to typing 'pico something' just alias pico='nano' :) Isn't Linux great?
36
Pico will always ask you if you want to do what you're doing. That's good. Questions
like that will keep you from sending a file into nonexistence without wanting to. All
the other commands you'll need are at the bottom of the page.
Well, this is our little overview of the main text editors available for Linux. In our next
lesson, we're going to need to use one in order to make our work in Linux a little bit
safer and easier.
Vi for budding power users
Again, my aim is not to do a treatise on vi, but here are a few more commands that
you might need to do a little more heavy lifting.
Removing Lines
You may find that you need to remove an entire line from a file. Just place the cursor
at the beginning of the line and type:
ESC + d
(d for delete)
Changing your mind
Sometimes you wish you hadn't done something. With vi, you can undo what you just
did.
ESC + u
(u for undo)
Changing your mind (again)
Again, you have second thoughts. With vi, there are no regrets.
ESC + q!
(q! for quit and I *really* mean it!)
The exclamation point (!) is used in vi to override default settings. If you make
changes to a file, vi is going to ask you if you want to save them. 'q!' means that you
want to quit without saving.
Where did I put that word?
Did you misplace a word in your file. You can find it easily with vi
ESC + /[word]
slash for umm.. slash, I guess.)
37
If you're looking for the word nonplussed in your text (as in: 'vi is so easy I am
nonplussed') you would type:
ESC /nonplussed
and it will find every instance of the word nonplussed.
Can I change that word?
Maybe you don't want to use the word nonplussed. Perhaps it's better to use a more
wellknown word. You can use vi to change the word. First you could use the
/nonplussed
to look for that word. When you find it, you would then type
ESC : s/nonplussed/amazed/
to replace the word on that line.
If you were sure that you wanted to replace all instances of that word in the whole
text, you could type this
ESC :%s/nonplussed/amazed/g
and nonplussed would be changed to amazed throughout the text.
If you want to get some control over what you replace that is you want to used both
nonplussed and amazed, then you would add gc to the end:
ESC :%s/nonplussed/amazed/gc
Vi will now ask you for confirmation.
Vi configuration settings
There are some basic vi configuration setting that you should be aware of if you want
to use this text editor comfortably.
Word Wrapping
If you don't want your words running off the page into oblivion, you can set the word
wrapping feature in vi
ESC : set wm=30
This is a good wrap for me personally. It sets the wrap to 30 spaces from the right so it
makes it tight. This means that the bigger the number, the sooner you get a line break.
If you send something via email, then this tight wrap ensures that it will get there
without the lines being broken into stairsteps.
Vi as an email editor
What did you say? Vi and email? Yes! You can use vi as an email editor. This is most
commonly done with the email client mutt .
More Vi
38
This just scratches the surface of what you can do with vi. Here I've tried to show you
what might be the most useful features and setting of vi. It should be enough to get
some basic work done with this ubiquitous editor for Linux.
More info:
http://start.linux.org.ba/Vi
39
Lesson Five
Frequently Used Shell Commands
If you install a window manager like KDE, you can copy, delete, move and rename
files by way of a graphic user interface like Konqueror. But as I mentioned before,
shell commands are pretty standard in Linux, so we're going to teach you the ones that
you're most likely to use. You can use them both in text mode or in your xterminal
when you're in graphics mode.
The 'cd' command
The first command you'll use is 'cd'. We talked about this in a previous lesson, so let's
review the basics.
'cd' means 'change directory'.
Typing: cd /[directory name] will get you into one of the main directories in Linux.
Typing cd .. will get you out of it.
Typing cd without the / and a subdirectory name will get into that subdirectory.
Remember, you don't have to type the whole name. Typing: 'cd' and the first letter or
letters of a directory and the TAB key will complete it for you. Then all you have to
do is press enter.
If you type just: 'cd' you'll go back to your home directory
The 'ls' command
To show the student the various variations of the 'ls' command 'ls' is another command
that we've discussed a bit before. Let's go into some more detail.
Typing 'ls' will list the contents of a directory with just information about file names.
You can use 'ls a*' to list the names of all the files that begin with the letter 'a' and so
on down through the alphabet. Please do not use the cuneiform alphabet unless you're
from ancient Mesopotamia.
40
Normally we'll want to add on some parameters (those [letter] combinations) so that
we'll get some more detail.
Using 'ls l'
To show the student how to get some more detail with 'ls l' 'ls l' will get you a
detailed listing of the directory like this.
The first part, those letter, are file permissions. We'll go into that in a later lesson.
That basically shows what you and others are allowed to do with the file, like read it,
modify it or make nasty comments about it.
The next one shows that you've got 1 file. The next one that it belongs to you, 'bob'.
The next one represents that Linux, not only recognizes users, but also groups of
users. We'll go into that a few lessons later. The numbers are the size of the file in
bytes. You have the date and when it was created or modified or copied there. Lastly,
you have the name of the file, waikiki.jpg, which is obviously your important tax
records.
'ls l n' will give you a detailed listing in alphabetical order, starting with any file that
begins with a number, then any file that begins with a capital letter and then any
normal file that begins with a lowercase letter. So if you have a file '007_secrets.txt'
that'll be the first one you see.
Other parameters with 'ls'
Now let's add some more parameters on.
'ls l t' will give you a listing according to the time with the newest ones appearing
first in the list. You don't need to separate the parameters either. 'ls l t' and 'ls lt' are
the same thing. If you want the oldest to appear first, try:
ls -ltr
The 'r' is for reverse order.
There are a couple of parameters in capitals that you may want to use. 'ls lS' will list
your files from biggest to smallest. 'ls lSr' will reverse this order.
'ls lX' will list files according to type in alphabetical order. If you have any that end
in *.zip, then those will be last. If you want those to be first, now you know: 'ls lXr'
There is also a parameter that will help you if you want to find out more about these
commands or any others. 'ls help' will give you details of all the possible variations
for this command.
41
The 'cp' command
'cp' is for copying files from one place to another, or for making a duplicate of one file
under a different name.
Let's go back to Tony's 'stuff' file. For example, if you saved Tony's email attachment
to your main /home directory, /home/[your name], you may want to create a directory
to keep Tony's files You could make the directory for Tony tonyd (Tony's last name is
Dweebweiler)
mkdir tonyd
then you can do:
cp stuff tonyd
Remember use your TAB key to save time.
Now you're going to have TWO files named 'stuff' because you copied that file to the
directory 'tonyd/' you didn't move it there. You'll have the original 'stuff' in your
home directory and then the copy in /home/[your name]/tonyd/.
You'll be able to tell the difference between the two files because the copy of 'stuff' in
the directory 'tonyd' will show a different time. If you use the command ls l stuff on
both files, you'll see this.
More uses of the 'cp' command
To show you how to copy directories and create duplicates of files. Now let's talk
about two more basic uses of the cp command and some short cuts.
You can also copy entire directories to another place. As I mentioned in a previous
lesson, you may want to work as two different users for two different jobs. You may
be working as 'fred' and your directory 'tonyd' is in the directory /home/bob, where
you work as 'bob'
As 'fred', you can use the command:
cp -r /home/bob/tonyd/ /home/fred/
If you're in your home directory you can use this command
cp -r /home/bob/tonyd/ ./
to copy the directory 'tonyd' to your home directory.
You may also use the command
cp -r /home/bob/tonyd/ ~
42
with the tilde wherever you happen to be and that will automatically copy the
directory 'tonyd' to your other home directory.
The other use of 'cp' we talked about was to get a copy of a file with a different name.
For example, Tony's file 'stuff' is loaded with jokes. You may want to add some more
jokes and then pass it along to another person You could do this:
cp stuff stuff2
or choose a name that's meaningful for you other than 'stuff2'.
Now you have another file that you can add jokes to while you preserve the original
file. You can open it in 'pico' and start writing: "Why did the chicken cross the road..."
Always remember to use that TAB key and the up and down arrows to save yourself
some time.
A word about binaries and PATH
After we've learned a few useful parameters for 'ls' command, let's use it to view the
contents of 'bin' directory. (How do we do that?) This list is rather long, so you may
want to use CTRLPageUp and CTRLPageDown.
Remember that this directory contains programs that are a part of the system. Notice
that one of the entries is named 'ls'. This tells us that even 'ls' itself is a program in /bin
directory! Depending on your configuration there may be a few hints that 'ls' is not
just an ordinary file but a program; it could be listed in green color, or it could have a
small asterisk (*) behind its name.
When we type 'ls' the system knows that the file containing this program is located in
/bin. Actually, if it isn't, /usr/bin, /usr/local/bin and some other directories will also be
searched. The list of directories where programs are found is called PATH and is a
system variable (later we'll see how to set up these variables).
What if we have a program that isn't in one of PATH directories? For example, let's
copy 'ls' to our home directory. (How do we do that? There's more than one way to do
it!) How do we execute this instance of 'ls'? Well we just type the path leading to it –
for example, we may type
/bin/ls -l /etc
to call 'ls' from it's location. We can also use relative paths. So if we're in home and
want to run a copy of 'ls' placed where we are, we can type just
./ls
As '.' means 'this directory'.
The 'file' command
File is an interesting little command. MSDOS got us all used to the idea that a file
had to have an extension (file.extension like 'novel.txt') that told us what kind of a file
43
it was. In Linux, it's 50/50. You don't have to do that if you don't want. In MSDOS,
programs end in '.exe', in Linux, they don't have to and probably won't.
Linux is also color coded, as you know, so once you get used to the colors, you'll
know what the file is about. Let's say your friend Tony, the one with the magic
markers, sends you a file he says is really neat. It's attached to an email message and
it says 'stuff'. You can see what type of file it is by typing:
file stuff
You may see something like this:
stuff: ASCII text
This means that the file contains plain text. It's probably some jokes or his favorite
chili recipe.
If you don't know what some particular file contains and you're curious about it, you
can use this command to get some information about the file.
'cat'
In order to see the contents of a file, we can use the 'cat' command. Remember lilo?
Well if lilo was a mouse, we could send a cat to chase him:
cat /etc/lilo.conf
But sometimes this cat is too fast and runs off the screen! For example, if we type
cat /proc/pci
Fortunately there's a way to fix this – read on!
'more' and 'less'
'more' is a command that you can use to read, for example, what's written in that 'stuff'
file that Tony sent you.
You would type 'more stuff' to see the jokes. Press the 'q' key to stop viewing the file.
Remember that /proc/pci is too big to fit on screen? Well, just type 'more /proc/pci'.
It's useful for this, but not really ideal. We'll talk more about 'more' in this lesson
when we use it in combination with other commands
'less' is better for viewing files. You can scroll back up to see the whole text if you
want. You can't do that with 'more'. 'less' is more than 'more', if you get my meaning.
Type
less stuff
to see Tony's jokes again. Again, press the 'q' key to stop viewing the file.
Now we'll look at the command 'mv'.
The 'mv' command
44
'mv' is a command that we're going to use to move files around or to rename them.
'mv' sort of has a splitpersonality because it serves these two functions at the same
time.
'mv' command for renaming files
Let's go back yet again to Tony's file, 'stuff' again. 'stuff' is not a good name for a file
just as 'book' isn't a good name for a book. Just imagine: “The number one bestselling
book this week is 'Book' by John Author.”
You should probably rename this file to something meaningful. I would suggest
doing something like this:
mv stuff tonys_jokes
You may have noticed the underscore '_' in the title. It's there because Linux doesn't
really like spaces in the file names. You can do it and Linux will accept it but it will
put a \\ between the different words. Spaces are sort of 'faux pas' in Linux but not
'verboten'. It would be to your advantage to use '_' between words though.
Moving files with the 'mv' command
Now you can use the 'mv' command to move Tony's jokes into the directory you made
to keep his files.
mv tonys_jokes tonyd/
If you do cd tonyd and then ls to* you will see his file there along with 'toms_jokes'
and 'tomato_soup_recipe' (if you have another friend named Tom and you like to
cook).
You can also move entire directories with this command. You do not have to use the
'r' option as you did with 'cp'. You would just substitute the file name for a directory
name
mv tonyd/ my_friends/
would move the directory 'tonyd' to the directory 'my_friends'.
What? You don't have the directory 'my_friends'? Well, let's create it with another
command.
The 'mkdir' command
'mkdir' is the command for making directories. 'mkdir' may be familiar to MSDOS
users out there. As you have noticed, the people who wrote these programs tried to
give them names that described what they do more or less, not as long as
'makemeadirectoryplease' and not too cryptic like 'xr77b'.
To create the directory 'my_friends' that we talked about in the last lesson, you would
type:
45
mkdir my_friends
There are no whistles or buzzers. If you'd like some sort of acknowledgment, you
could type
mkdir --verbose my_friends
and it will tell you that you created the directory.
If you type ls l you'll see it there along with information about it.
Now you know how to use 'mkdir'. You can even use it to create a directory called
'my_enemies' if you're into that sort of thing.
The 'rmdir' command
'rmdir' is the opposite of 'mkdir' it gets rid of directories. It should be pointed out that
in order to use it, the directory has to be empty. If you copied or moved anything to
'my_friends' and you typed
rmdir my_friends/
Linux would politely tell you that you can't do that.
So, you have to use your 'rm' command on the files first to remove them or use 'mv' to
get them into another directory. Then you're free to use 'rmdir'. So, next we'll deal
with the 'rm' command.
The 'rm' command
'rm' is for removing or deleting files. That means, sending them into nonexistence,
oblivion, byebye.
So you have to be careful with 'rm'. That's why we put an entry into our '.bashrc' file:
alias rm='rm i' so that it asks you if that's what you really want to do.
If you created a file called 'bad_jokes' and you wanted to get rid of the file, you would
type rm bad_jokes, and because you made an alias, it will ask you.
rm: remove `bad_jokes'?:
You would press the the 'y' key unless of course you remembered that you have a real
good one in there and then you would answer: with the 'n' key. Actually, any key other
than 'y' is the same as responding with the 'n' key, so if you accidentally type 'w', don't
worry.
'rm' – some words of caution
You can also do stuff like rm b* with the asterisk, but I would use my best judgment
with that. You may get 'yitis' and just keep pressing the 'y' key. I have done that
before.
46
Occasionally, when I've used the text editor 'joe' a lot I end up with a lot of files that
end in a tilde (~). You get files like 'note_to_myself1' and if you've modified it,
another one 'note_to_myself1~' Then I decide that I don't want all of those ~ files
littering up my directory and I innocently type: 'rm note_to_myself*' and then 'y' 'y' 'y'
and then I realize too late and my brain types: 'Y did you do that!!" The problem is
that 'note_to_myself2' contained my important plans for taking over the world and
'note_to_myself3' contained a note about how much money I owe at the dry cleaners.
Maybe taking over the world can wait, but my dry cleaner's not going to give me my
suits the next time unless I pay him.
There's another case of 'rm' that's potentially more dangerous than the 'rm *' case.
That's adding the 'f' option on the end. If you do this, it will override the 'i' option
and won't ask you anything. It just goes ahead and deletes the files in question. For
example, if you were in a directory and typed 'rm * f' you would delete everything, no
questions asked. I generally use the 'f' option very sparingly, like when Valentine's
day falls on Friday during leap year and coincides with a full moon.
Also, please be very careful when you're using the 'rm' command as 'root'. You could
do some very serious system damage if you delete the wrong files. Wait until you have
some experience before you start removing files 'by hand' as 'root'. Use the
configuration tools provided in your version of Linux to uninstall programs that you
don't want.
How to get more information with Linux
Now we'll talk about some other commands that you will probably need in your day to
day work with Linux. They make your work a little easier and give you added
information about your system.
We already mentioned the first way to get information about commands! It's by typing
a help parameter after command, such as 'help' or 'h'. Most Linux commands
recognize either 'help' or 'h', or both. If neither works, usually you can just type the
command and press Enter (nothing more) to get at least a hint of available parameters.
'man' – manual pages in Linux
Another useful command is 'man'. This command will show the manual for a
command or program. The manual is a file that shows you how to use the command
and list the different options for the command in question. You would type:
man [the command]
For example, if you type
man mkdir
The manual file for 'mkdir' will come up and give you a detailed explanation of this
command.
47
Managing documentation in Linux
The manual file for 'mkdir' is actually one of the more straightforward ones. There
are a lot that I think we're written by Harry Bigbrains and they were meant to be seen
only by Richard Biggerbrain who's sitting in the cubicle next to him.
For example, this appears in the 'man' file for 'cp'
By default, sparse SOURCE files are detected by a crude heuristic and the
corresponding DEST file is made sparse as well. That is the behavior selected by
sparse=auto. Specify sparse=always to create a sparse DEST file whenever the
SOURCE file contains a long enough sequence of zero bytes. Use sparse=never to
inhibit creation of sparse files.
I don't know about you, but I'm going to call my lawyer. I've been assaulted by "a
crude heuristic".
If you use the command cp help, you'll get a nutshell version of the 'cp' command. If
you use your pipe cp help | less, it'll be a little easier to manage.
The 'info' format
Apropos
The word 'apropos' means pertinent to something else. There is a command that will
show you all of the man page that may shed some light on a certain command. For
example, if I typed:
apropos xterm
I would get something like this:
resize (1x) - set TERMCAP and terminal settings to current
xterm window size
xterm (1x) - terminal emulator for X
terms (5) - database of blessed terminals for xtermset.
xtermset (1) - change settings of an xterm
These are all man pages related to xterm. You would then just choose one of these and
type man terms for example.
Some versions of Linux that are made for languages other than English will give you
this documentation in its particular language. There are also websites that specialize in
48
documentation in other languages. You can use your favorite Internet search engine to
find Linux documentation in your own language.
49
Lesson Six
Plumbing with “pipes” in Linux
In this lesson, we're going to do a little plumbing. Plumbing with a computer? Well,
Linux is so flexible that it even allows you to do plumbing with it. Well... actually, it's
just a little witticism of mine because the command we're going to learn in this lesson
is called 'pipe', and plumbers work with pipes.
To use the pipe command, you don't type: pipe. You press the '|' key. The location will
vary on keyboards from country to country. This symbol is like two vertical slashes,
one on top of the other, but sometimes it's just a vertical line slightly longer then
capital I or lower case l.
This is the first time that we're going to see a command that's meant to be used with
other commands. That means that the pipe will separate two commands so that they
will be done one after the other. Let's try some plumbing.
For example, when we looked at all the parameters of 'ls' command with:
ls --help
it was too big to fit in one screen. We used CTRL and PageUp/PageDown, but a better
way is to type:
ls --help | more
Remember the 'more' command? We used 'more' to read long files. With the above
combination of 'ls' and 'more' we can read long output of 'ls' with 'more'. Simple, isn't
it? It's just as if the output of 'ls help' was a file and you used 'more' to display it. So
you can scroll down with the ENTER key and see it all.
You're probably going to end up using this a lot. You're personal directory in /home
will fill up and pretty soon 'ls -l' will overflow in your terminal or xterminal
window.
Standard input, output and error output
Here we saw that more and less have two ways of using them. One is to type
something like
more stuff
50
to see the contents of file named 'stuff'. The other one is inside a pipe
cat stuff | more
This command does the same thing as the one above. Here 'more' has no parameters.
However it takes the file contents from 'standard input'.
Under normal circumstances 'standard input' is keyboard, 'standard output' is screen,
and 'standard output for errors' is also the screen. This three are dubbed STDIN,
STDOUT and STDERR. With pipe we are actually redirecting the standard output of
one command into standard input of another one. So 'cat' was producing the contents
of 'stuff' to standard output. Then we feed that to the standard input of 'more' using
pipe.
If this is all Japanese to you, just remember that adding '| more' will enable you to
scroll through long stuff and read on. It will all fall into its place.
Redirections
The '>' command
The "greater than" symbol '>' will redirect standard output of a command to a file.
This means that whatever was supposed to show up on screen will be written to a file.
For example, you might want to write something like this
ls -l > directory_listing
to get a file with contents of current directory. If you've placed files in a directory to
be backed up, you could use this command to create a listing of that directory. You
could print out the file on a label and stick it to the disk, tape, zip cartridge or
whatever you used to make the backups.
To see what happened, just open file 'directory_listing' in your favourite editor.
If you're using the '>' command for the backups I described before, you may want to
put a date on the file. You can use this command:
date >> directory_listing
The command 'date' will enter the date and time in the file at the end. Remember to
use the >> option if you're going to write to that file a second time. If you don't you
will erase everything on the file in favor of whatever the second command was.
The '2>' command
This command, the number two (2) with the "greater than" symbol >, is used for
creating a file for an error message that you may get.
51
You will probably not be using it a lot because we all know how perfect Linux is and
how few errors there are when you're using it. But every once and a while you may
want to download some software from the Internet You install it and whoops!
there's some error. You may not have something installed that the the program needs
to run. You could just do something like this:
[program X that doesn't work] 2> program_X_error
You create a file with the error message. You could show it to someone who might
know what's missing or you could send it to the author of the program. He or she
would also like to know about it and will probably help you fix it.
tee
In the lesson on the pipe command, I mentioned plumbing with Linux. I think I'm
going to resist the temptation to make some sort of golf reference here in the lesson on
the command 'tee'.
'tee' creates an additional direction in the flow of data, just like a Tpiece in pipelines.
When you use the '>' command, you can't do anything with the output in the same
command. You need to use additional commands to manipulate file contents. When
you put a tee inside a pipe, you can redirect the current output to a file and still
continue processing it. It can be useful when you are debugging complex pipelines.
You might do something like this:
ls -l | tee directory_listing | less
to output listing of a directory to a file, and also display this listing on screen in a nice
form.
'tee' allows for some exceedingly complex commands such as this one
ls -l | tee listing | grep “Oct 31” | less
(the meaning of 'grep' will be explained shortly).
Locating files on your system
Finding things with the command 'find'
There's so much on a computer's hard drive, nobody could ever know from memory
where everything is. Perhaps the smart lad who won the spelling bee by spelling
'prestidigitator' might be able to, but most of us are going to have to find things now
and then.
If you use a window manager like KDE, you can use the find tool. It's very useful
because it has a lot of options and you can use them to modify your searches.
But if you're getting used to using command line stuff, just type in:
52
find -name *hawaii*
and find out where you put you pictures of you Hawaiian vacation. If you're in your
/home directory, it will go through every directory and find every file that has the
name 'hawaii' in it. The two asterisks make sure it does that. If they started with
'hawaii' you wouldn't need the first asterisk but you can leave it there if you want.
You may have created some file recently. For example, you may want to find some file
that you were working on, let's say from now up to 10 minutes ago, you could type.
find -mmin +0 -mmin -10
This will list the files that you created or modified within the last ten minutes. If you
choose to use a higher number for mmin ? you should probably use a pipe, for
example:
find -mmin +0 -mmin -120 | less
will find things that you created or modified up to 2 hours ago and the '| less' part will
make it easier to read.
The 'grep' command
In the last section we talked about the 'find' command which finds files. Now we'll
talk about the 'grep' command which finds words in files. Your windows manager may
have this incorporated into its find tool but then again, the beauty of Linux is having
alternatives.
'grep' is a Vulcan word that means "find". Actually it isn't, but it sort of looks like it,
doesn't it?
Kirk: "Find the solar system L10J, Mr. Spock."
Spock: "Grepping now, Captain." *
* Star Trek stuff copyright Paramount Pictures
Let's have a little practice session with 'grep'. The best way is learning by doing, so
let's do it.
With 'pico' or any Linux text editor, create a file called 'mary1.txt'
pico mary1.txt
Then type:
Mary had a little lamb
Press CTRLX in 'pico' (if you're using that) and it will prompt you to save.
Then create: mary2.txt and enter the text Mary had a little cow.
Save that and create the file: mary3.txt and type: Mary had a little too much to drink.
Now we know what Mary was doing when she wasn't watching her lambs! Now save
that file.
53
OK, now we're ready to try out 'grep', so phasers on stun and let's go. Type the
following command:
grep Mary mary*.txt
Let's explain this a little. 'grep' looks for the word "Mary" in any text file that is called
"mary(something).txt". You've created three files that start with 'mary', so the asterisk
makes sure that 'grep' will look for the word 'Mary' in all three.
You should get this output:
mary1.txt Mary had a little lamb
mary2.txt Mary had a little cow
mary3.txt Mary had a little too much to drink
The word 'Mary' is in all of those files, so you'll get this output.
If you type grep little mary*.txt you'll get the same output because the word "little" is
also in each of those files. But if you type the word "cow", you'll get this output:
mary2.txt: Mary had a little cow
because the word "cow" is only in mary2.txt.
Typing grep drink mary*.txt will get us more or less the same, only that mary3.txt
will show up instead of mary2.txt.
Well, there's 'grep' in a nutshell. It's been a pleasure 'grepping' with you!
Piping 'find' into 'grep'
As we've seen, 'find' is powerful – but for most people it's not powerful enough. For
example, it can find a file named hawaii, but it can't also find Hawaii and HAWAII.
Here's how we can combine the power of 'find' and 'grep'!!
find | grep -i hawaii
What happened here is that find just listed all the files in the current directory and all
subdirectories. You can test this by typing just
find
This is a standard output. Now we use the pipe operator (|) to take this standard output
and feed it into standard input of the command 'grep'. We've used 'grep' switch i
which means 'ignore case'. So now we should find all three files.
Now there's something useful, right?
Other useful commands
'nl'
54
'nl' command adds a line number to every line. It's useful cause it gives us a numbered
list, so we can quickly see how many lines are there and which is which. For example:
ls -nl | nl
will give us all the files in alphabetical order ('ls nl'), but numbered ('| nl'). So we can
see which file in current directory is fifth alphabetically.
To number a file type
cat phonebook | nl
But what if the phonebook is too long to fit on screen? (Answer this yourselves!
Remember to try it out before responding.)
'sort'
This will sort the output alphabetically, for example
ls | sort
Ofcourse, it was easier to type just
ls -n
'tail'
This gives the last 'n' lines of a file. If 'n' is not specified 10 is assumed. So:
tail phonebook
gives last 10 entries in the phonebook.
tail -5 phonebook
will give last 5 entries.
The backtick operator
A 'backtick' is an apostrophe turned the other side. It looks like this when printed:
`
On the US keyboard it's usually left of key with number 1, but you don't press Shift as
you would with tilde.
If you enter a command inside two backticks, it will be executed and then its standard
output (remember: what the command usually prints on screen!) will be inserted at
current position.
So for example:
grep `whoami` /etc/passwd
will give a line from /etc/passwd containing username of currently active user.
Command 'whoami' outputs your current username (try it!) While 'grep' will look for
this piece of text in the file named /etc/passwd.
Task: Copy the biggest file in current directory into a subdirectory named 'backup'.
55
Task 2: Find all the files whose name contains word 'hawaii' and themselves contain
the word 'vacation'.
56
Lesson Seven
Becoming A Power User
Here is a brief overview of some other commands that you may find interesting at
some point as you use Linux. They will help you to get all of the power out of Linux.
The command 'touch'
Now we're going to talk about a touchy subject. The command 'touch' which is used to
change the time and/or date of a file.
You can use 'touch' if your boss yells at you about not having a report ready at
lunchtime. You should quickly finish the report, then type:
touch -t 05070915 my_report.txt
and it makes it look like you did it at 9:15. The first four digits stand for May 7 (0507)
and the last four (0915) the time, 9:15 in the morning. Make sure your digits match
your story. You don't want to have it look like you did it in February. Of course, if you
punched in at 9:40, then you're in trouble.
'touch' can be used also to create an empty file. You would just enter touch [a file
name]. There may be times in the future when you need an empty file that will be
filled up later automatically by the workings of some program. We'll deal with the
uses of 'touch' in our later courses.
'who'
'who' is a command to find out who's working on your system. As you now know,
Linux is a multiuser system. Even if you're using one computer at your home, you
may be working as more than one person. For example, if you logged in as 'root' but
are working as 'bob'. You may see something like this:
root tty1 May 20 09:48
bob tty2 May 20 10:05
This is just Linux's way of saying that 'root' started working on terminal 1 on May 20
at 9:48 in the morning and bob started working on terminal 2 at 10:05. This is mainly
used in networked situations so the system administrator knows who's working. It can
be used by your boss to find out that you've come in late too. You may use it to find
out if you've opened more that one terminal so that you remember to log out.
As 'who' is used very often, there's a shortcut – type just 'w'.
57
'whoami'
whoami is a nice little program that tells you who you are, just in case you didn't
know already. You amnesia victims are in luck! Actually it tells you who you are in
terms of how Linux understands who you are, that is to say, your user name. So if
your user name is bob and you type whoami you'll get: bob . This comes in handy if
you switch terminals a lot and work as a different user. You may, in terms of computer
use anyway, forget who you are!
'whatis'
'whatis' is a command so you can find out what a program does. If you explore your
Linux system, you will find a lot of programs and you may not know what they do.
You would simply type: whatis grep for example, and you would get this:
grep (1) - print lines matching a pattern
Linux is good, but it's not allknowing, so if you type: whatis orange juice You will
get this message:
orange: nothing appropriate.
juice: nothing appropriate.
basically telling you that Linux has no idea what orange juice is.
'whereis'
whereis is a nice command for finding other commands or programs. If you decide to
download any program from the internet, that program may need other programs in
order to work. If you want to know whether or not you have it, you can type: whereis
[program name] and find out.
If you wanted to find out if you have the 'pico' editor and where it is, you would type:
whereis pico
and you may get this:
pico: /usr/bin/pico /usr/man/man1/pico.1.gz
It shows you where the command is as well as the location of its manual file. whereis
isn't designed to find people, so if you type
whereis Harry
Linux is just going to say Harry:
'which'
To show you another tool for locating programs 'which' is similar to 'whereis'. It will
give you the location of a program. At times, a program may not find another program
it needs to make it run. It will need to know its location or "path". For example, a
58
program may need Java to run it but thinks its in another place. You would simply
type:
which java
and Linux will inform you of its location
/usr/lib/java/bin/java
This is a handy command because some locations of programs vary from one version
of Linux to the next. A software developer may have designed his/her program to
access Java, for example, from a different location. As Open Source software will
always let you modify configuration files to get your program working according to
your needs, you can get the program to work for your system.
'echo'
To show you some uses of the 'echo' command 'echo' is a little command that repeats
anything you type. For example if you type echo hello Linux will display the word
'hello' .
There is really no need to do that under normal conditions. You may find 'echo' useful
in the future if you start writing "shell scripts" which are like little programs that you
could use to do a few commands at one time. You could use 'echo' in those scripts to
tell you what the script is doing at any given time, or to prompt you to do something,
like enter text. Shell scripts will be taken up in a later course.
There is a practical use for 'echo' in everyday life. I sometimes use it to write short
notes. If we use 'echo' along with 'pipe' (|) and 'tee', you've got a poorman's postit
note. For example:
echo remember to tell Bill Gates he owes me 5 bucks | tee -a
bill_gates.note
Will make you a nice reminder note about dear 'ole Bill. Just remember to read your
note. You could type:
echo remember to open Gates note | tee -a remember_gates.note
to make yourself a reminder for the other reminder note. Use less bill_gates.note or
less remember_gates.note to read your notes.
'wc'
People following this course from Europe may recognize this as the symbol for
'bathroom'. Unfortunately, if you type this in your terminal it will not show you the
way to the 'facilities'. Actually, this command will give you the number of lines, words
and letters (characters) in a file and in that order.
Let's go back to the file about the people I owe money. If I type:
wc people_I_owe_money.note
I will get this output:
59
439 6510 197120 wc people_I_owe.note
As you can see, there are 439 lines, so that means if each line represents one person,
then I owe 439 people money. There are 6510 words and a total of 197120 characters. I
might add that this is a good tool for people who write letters professionally and get
paid by the word.
'dir'
The people who traveled down the MSDOS road will know this one. Actually, dir=ls
l. It will give you the same result. If you do any downloading or uploading of files via
FTP by way of a nonGUI FTP program in your terminal, you may find this command
useful. I once ran into a case where the remote computer didn't recognize the ls l
command. I just typed in dir and that did the trick. Then I fired off a nasty email
asking why in the world they weren't using Linux!
'pwd'
The command pwd will show complete information on the directory you're working
in. For example, if you type pwd you may get something like this:
/home/bob/homework
which shows you that you're in the directory 'homework' in your user directory as
'bob', so you know exactly where you are.
'date'
Did you forget your wedding aniversary? Your boyfriend or girlfriend's birthday? Tax
day? (everyone wants to forget that one!) No need for that to happen anymore with
Linux. Just type:
date
You'll get this: (or something like it, actually. If you get the same thing as I do, then I'd
consider buying lottery tickets)
Thu Sep 7 20:34:13 CEST 2000
You probably get everything here. If you're living in central Europe, you will recogize
the 'CEST' part. That stands for 'Central European Standard Time'. Linux recognizes
world time zones and you set this up when you installed Linux. If you live on Mars,
you're out of luck, unfortunately.
There are other uses of the 'date' command. To see just the date, type:
date +%D
To see just the time, type:
date +%T
To see on what day Christmas falls this year (really, I'm not kidding!), type:
date --date 'Dec 25'
and you'll get the day that Christmas falls on this year. Substitute that for any date that
you'd like to see.
60
There are many other options. Consult your manual file ('man date') or ('info date').
'cal'
Typing cal will give you the calendar of the present month on your screen, in the nice
standard calendar format. There are a lot of useful options.
If you type:
cal 2000
You'll get the entire calendar for the year 2000. Substitute any year you like. If you
type:
cal 12 2000
You'll see the calender for December of 2000. Substitute any year or month you like.
If you add the option cal m, the week will start on Monday, as it is preferred in many
countries.
Just for fun, I typed cal 10 1492 and I found out that Columbus discovered America on
a Friday. That was good luck for him because that way he got to relax for the
weekend.
'exit'
If you're in Xwindow, exit will close the XTerminal you're working with. exit with
the option "stage right" will get you an error message.
An introduction to aliases
Everybody knows what 'alias' means – 'an assumed name'. An 'alias' in this file are
some lines that you write so that your bash shell assumes that one command is really a
variation of it. As you already know, you can modify a command with a slash '' and a
letter. To see where the .bashrc file was, you could have typed 'ls a' and that would
have shown you every file in the directory, including those that start with '.' If you find
yourself using these 'letter' combinations a lot, you can create an alias so that even
though you type the simple command, like 'ls', you actually get 'ls a'.
To see a list of presently active aliases, just type 'alias' with no parameters and press
Enter.
61
Some of these aliases may be very important to keep you from sending that novel you
just wrote into nonexistence by accident. I have a couple of aliases to keep me from
getting into trouble. They are:
alias cp='cp -v -i'
alias rm='rm -i'
alias mv='mv -i'
Let me explain them.
cp is the command to copy a file to another place or to make a copy of a file under a
different name. In order not to copy a file to a place where there's already a file by the
same name, you could type cp v i, (v for verbose, i for interactive) and it would ask
you if you really want to do it in case there's another file by the same name. Then the
v would show you where it went. This is probably a good idea all the time, so you
could create an alias for it.
rm is the remove/delete command. In Linux, this means gone forever [cue ominous
organ music] You obviously have to be very careful with this one, because in the bash
shell there is really no 'trash' bucket to pick it out of if you delete it. That's why I've
added the i (interactive) command to my alias, so that it asks me if I really want to
delete that novel I just wrote.
mv is for moving files to a different place or renaming a file. I have an alias for it for
the same reasons as the cp command.
62
Lesson Eight
If you're the systems administrator, regardless of the environment (large, medium or
small organization), one of your tasks is going to be to add users to the system. This
means giving a person their user account on one or more machines in your network.
The main issues that you have to deal with is to decide, based on either your own or
the company's criteria, what privileges the user is entitled to.
Another Look at Users
If you're interested in having tighter control over how you create users, you should use
the standard command line tool useradd. Let's look at the options available to you.
First, if we run the following command:
useradd -D
You will see how users are added to the system by default.
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
Let's dissect this a bit. In this example, any user will be added to a group called users.
On a SuSE Linux system, this is a default, catchall group of sorts, that includes all
users. On other distributions each user might be in its own group, named the same as
user him/herself.
As you already know, a user added to the system will be given a directory to keep his
or her files. This is created, by default, in /home. The INACTIVE=1 refers to the
number of days it takes for the system to lock you out when your account expires. As
you can see here, you get locked out real soon!
EXPIRE= refers to a date when your account is supposed to expire. In our example,
there is no date. This is probably fine for regular employees, but if you hired some
outside consultant to do work for you, you might want to his or her account to expire
at the conclusion of business. The best way to handle temporary workers (and
especially fired employees) is to delete the account entirely. But even the best
administrators are often overworked and may forget, so setting an expiration date will
ensure that an account cannot be used.
The next item, SHELL=/bin/bash, refers to the shell that users will have to run
commands on the system. Bash, or the Bourne Again Shell, is standard on Linux
distributions. That doesn't mean that you as a system administrator can't install other
63
shells on the system and make them the default (The Korn shell, for example). The
last item is very important for you as an administrator. SKEL=/etc/skel means that the
files located in /etc/skel will be copied to the users directory when you create the
account. You may want to add files to this directory or you may want to make changes
to them.
Now you're ready to add users to the system with more selective criteria. The "man"
page for useradd is one of the better ones for a Linux command. Here you can see all
the possible options with good explanations about what every one does. Let's look at
an example using some of the most common options.
useradd -c "William Shakespeare - AKA, The Bard" -d
/home/wshakespeare -m -k /etc/skel -g 100 -s
/bin/bash wshakespeare
Let's see what we've done. First, we've added William Shakespeare as a user to our
system. The first option, c, is a short comment that must come between quotation
marks and helps identify our user in the /etc/passwd file. The second option, d is
where you want his personal directory to be created. The m option creates the home
directory and the k option copies the files in the following directory (in our case,
/etc/skel) there. The g option puts the user in the group whose number follows. The s
option provides the user with a shell to use (in our case, Bash). Finally, the name the
user will login with.
64
Deleting Users
As an administrator, you will need to delete users as well. People leave and move on
to other things. They come for short periods and need temporary accounts. Accounts
need to be deleted when they are no longer going to be used. This is of maximum
importance from a security point of view. We've all heard stories of disgruntled
former employees logging back into their accounts and using the system to either
embarrass their former employers by playing pranks or to actually try to do serious
damage.
Again, as we stated before, your Linux distribution choice may have tools to do this.
Some make this easier by also deleting users home directory (and all the files!) along
with the account. The standard tool that comes with all distributions, however, is
deluser It is simply run like this:
userdel wshakespeare
where you substitute the wshakespeare with the username you wish to delete.
In this particular case, we've deleted William Shakespeare's user account, but not his
home directory and files. To get rid of any trace of oldWill, then you would use the r
option:
userdel -r wshakespeare
which would remove everything, including his email. We may not want to do this,
however. Many people leave leave their employment but their work remains property
of the company because of contractual obligations. In this case, we would obviously
want to keep the user's files until they could be looked at, copied to another user's
account or stored. So be very careful with the r option.
Managing groups
The command to create a group is named 'groupadd' and it's used like this
groupadd group
'groupadd' doesn't have many parameters because there's not much to do about groups.
Let's look how it *really* works
A list of users is kept in the file called /etc/passwd
.....
File permissions in Linux
65
Linux has inherited from UNIX the concept of ownerships and permissions for files.
This is basically because it was conceived as a networked system where different
people would be using a variety of programs, files, etc. Obviously, there's a need to
keep things organized and secure. We don't want an ordinary user using a program
that could potentially trash the whole system. There are security and privacy issues
here as well. Let's face it, we don't want Bill to read Bob's love letters to the Janet who
works in R & D. (because Janet is Bill's fianceé) In the end, it's important to know
what belongs to me, to you and to everybody.
As we mentioned at the beginning of this course, the big advantage that Linux has is
its multiuser concept – the fact that many different people can use the same computer
or that one person can use the same computer to do different jobs. That's where the
system of file permissions comes in to help out in what could be a very confusing
situation. We're going to explain some basic concepts about who owns the file and
who can do what with a file. We won't get into an enormous amount of detail here.
We'll save that for the Linux system administration course. We will show you how to
understand file permission symbols and how to modify certain files so that they're
more secure.
File permission symbols
If you run the command ls l in your home directory, you will get a list of files that
may include something like this
rwrr 1 bob users 1892 Jul 10 18:30 linux_course_notes.txt
This basically says, interpreting this from RIGHT to LEFT that the file,
linux_course_notes.txt was created at 6:30 PM on July 10 and is 1892 bytes large. It
belongs to the group users (i.e, the people who use this computer). It belongs to bob in
particular and it is one (1) file. Then come the file permission symbols.
Let's look at what these symbols mean:
• The slash marks separate the permissions into three types
• The first part refers to the owner's (bob's) permissions.
• The slash mark before the rw means that this is a normal file that contains
any type of data. A directory, for example, would have a d instead of a slash
mark.
• The rw that follows means that bob can read and write to (modify) his own
file. That's pretty logical. If you own it, you can do what you want with it.
• The second part of the these symbols after the second slash, are the
permissions for the group. Linux can establish different types of groups for
file access. In a one home computer environment anyone who uses the
computer can read this file but cannot write to (modify) it. This is a
completely normal situation. You, as a user, may want to take away the rights
of others to read your file. We'll cover how to do that later.
• After the two slash marks (two here because there is no write permissions for
the group) come the overall user permissions. Anyone who might have access
to the computer from inside or outside (in the case of a network) can read this
66
file. Once again, we can take away the possibility of people reading this file if
we so choose.
Let's take a look at some other examples. An interesting place to look at different
kinds of file permissions is the /bin directory. Here we have the commands that
anybody can use on the Linux system. Let's look at the command for gzip, a file
compression utility for Linux.
-rwxr-xr-x 1 root root 53468 May 1 1999 gzip
As we see here, there are some differences.
• The program name, date, bytes are all standard. Even though this is obviously
different information, the idea is the same as before.
• The changes are in the owner and group. Root owns the file and it is in the
group "root". Root is actually the only member of that group.
• The file is an executable (program) so that's why the letter x is among the
symbols.
• This file can be executed by everybody: the owner (root), the group (root) and
all others that have access to the computer
• As we mentioned, the file is a program, so there is no need for anybody other
than root to "write" to the file, so there is no w permissions for it for anybody
but root.
If we look at a file in /sbin which are files that only root can use or execute, the
permissions would look like this:
-rwxr--r-- 1 root root 1065 Jan 14 1999 cron
'cron' is a program on Linux systems that allows programs to be run automatically at
certain times and under certain conditions. As we can see here, only root, the owner of
the file, is allowed to use this program. There are no x permissions for the rest of the
users.
We hope you enjoyed this little walkthrough of file permissions in Linux. Now that
we know what we're looking for, we can talk about changing certain permissions.
'chmod' explained
chmod is the program that is used to change file permissions on a Linux system. As
we mentioned, others cannot modify your personal user files but you may not want
other people to even read these files. You can use this command to take away the
possibility of others prying into your private stuff.
The syntax (parts separated by brackets) for using this command is the following:
chmod [a/o/g/u] [+ or -] (plus or minus sign) [r/w/x]
Let's analyze the syntax:
• The symbols in the first brackets refer to the four concepts of users that Linux
has.
o a = all, all users
67
o o = others, (other people)
o g = group, the members of your group
o u = user, (this means you)
• The symbol + adds permissions and the symbol takes them away. As we say
in the Linux world chmod giveth, chmod taketh away
• Your actual rights to files r=read rights, w=write rights (pardon the
homophonic redundancy!) and x=executable rights
Practical examples of chmod
As we mentioned before, you may want to restrict rights to read a file. You would
simply type:
chmod og-r my_world_domination_plan.txt
Now nobody can read your plans to take over the world except you. Best to keep those
secret anyway.
We also talked earlier about those files that you may have copied from a Windows
partition or a floppy formatted for Windows. Even if they're not executable files,
they'll show up as such (rwxrxrx). You can change them to their correct
permissions, getting rid of the executable status with:
chmod a-x the_file
Remember that if you copied them as 'root', you will have to use chmod as root to do
this. You could even go one step further and change the ownership of the file to the
user you desire. You may want to change root ownership to yourself (your user name).
We'll go into this in the next part of the lesson.
Using chmod with number values
The permissions in Linux also can also be changed with number values. An
accomplished Linux/Unix user will probably use this system more. When you're
beginning with Linux, the method we described before will probably be clearer to
you. Without going into tedious technical detail, we'll describe the chmod number
system to you and look at two of the most common examples.
As I said before, we have three sections to permissions; those of the owner of the file
followed by those of the group and then the permissions of others. So if you use
numbers with 'chmod', there will be three numbers following the command. One
number corresponds to each group. Here's an example of a chmod command with
numbers:
chmod 644 grocery_list.txt
If you had used 'pico' to write up a grocery list for your trip to the supermarket today,
Linux would have given you 644 permission by default. That means, read and write
permissions for the owner but no write permissions for the group and for others. So
the number 6 means read and write permissions for you, the number 4 means read
68
permissions for the group and the last number, 4 means read permissions for others.
Now the question is: Why these numbers? Why not other numbers, like the number 8
or 12 or even 1345? Let's explain this.
The three types of permissions correspond to three numbers. Read permission is given
a value of 4. Think of it as the most important permission. (if you can't read a file,
then what else can you do with it?) Write permission is given a value of 2. Execute
permission is given a value of 1. Here's what it would look like:
It's really just a question of simple arithmetic. In our example of chmod 644
grocery_list.txt, we've added the 4 for read permission and to the 2 for write
permission for the owner to get 6. We've just given the group and others read
permission, so there's nothing to add in these two groups. Just give it a 4 in each case.
Presto! 644.
Some practical examples with numbers
Let's take another look at my file that has my plans for dominating the world
(my_world_domination_plan.txt). I had taken away the read permissions for
everybody except myself using +/ letter method. (chmod ogr
my_world_domination_plan.txt)
Now let's do the same with the numbers.
chmod 600 my_world_domination_plan.txt
As you can see I have read and write permissions for me (4 read + 2 write equals 6)
and 0 permissions for everybody else. The Zero value means 7 (maximum permission
value) minus 4 minus 2 minus 1 equals 0.
Real worls examples with chmod
I'd like to talk about a real world practical example for doing this. There is a command
mode program called 'fetchmail' for getting your email. It's a very good program if
you're using your computer as different users for various jobs. It will send mail to the
different users based on email addresses. The different addresses are stored in a file
that you create called '.fetchmailrc' This file also includes the user name and password
for retrieving mail from each address. We've got a possible security hole here,
particularly if you're networked. This file shouldn't be read by everybody. When you
create your .fetchmailrc file, you must then use chmod 600/chmod ogr on the file to
69
solve the security issue. In fact, 'fetchmail' won't run if you don't. It will complain
about the file's permissions.
Let's look at another "real world" example. As the internet becomes more popular,
websites need to be more user friendly and interactive. It's becoming more and more
common to use scripts to improve the quality of a website's offerings. If you used a
language like perl to write the scripts and you hosted your website with a company
that runs Linux on their servers (we would hope that you would do this!), you would
probably be given permission to use these scripts on your website. You would then
have to give the scripts read and execute permissions so that the your visitors could
use them. After you uploaded a script to your website, you would then issue this
command:
chmod 755 my_awesome_script
and the script would become "executable" (and readable) for the outside world. (7 4
read, 2 write 1 executable for you, 4 read and 1 executable for group and others). You
could also use chmod og+rx my_awesome_script The script is then "converted" into
a "program" so to speak. You have also converted yourself into a "web developer"
with the right to hang your shingle on the door.
chmod is one of those commands that are used most by system administrators. In our
Linux system administration course, we'll go into this command in more detail. In this
lesson we've shown you just a few practical examples to get your feet wet with this
very important command.
Using chown
The command chown is the chmod's cousin. It is used for changing the ownership
rights of a file (hence the name 'chown' change owner). It does not change the read,
write and execution permissions however.
This command, though available to every user, is probably going to be used when
you're working as root. The command is uses like this:
chown owner:group the_file
Let's say you want to copy something from your Windows partition (if you have one).
You mount the partition (as root) and to save time, you copy the file to your user
directory /home/bob/. If you type ls l the_file you'll get something like this:
rwrr 1 root root 2428 Nov 17 13:18 the_file
As we now know from the previous lesson, root is the owner of the file. Therefore,
root is the only one who has write permissions for the file (permission to modify its
content). If you plan on working with the file as "bob", there isn't a snowball's chance
in hell to modify that file until, as root, you run chmod on the file. So let's do it!
chown bob:bob the_file
70
This example presupposes that your Linux version creates groups for each user. There
are others that will create a generic group called users for everybody who uses the
computer. On a network, groups are created according to the needs of the
organization. On your single home computer, just type ls l and see what system
corresponds to you.
As you can see, 'chown' is absolutely necessary if you're working as more than one
user with the computer.
71
Lesson Nine
Acquiring root privileges in a safe manner
As I mentioned, there's a chance of doing some damage when you work as root. There
are other ways to protect yourself. One of them is using the program su.
su lets you work as root when you're logged in as another user. Good practice dictates
that you disallow root logins from remote machines, so if you're performing
administration tasks remotely, su is irreplaceable. The remote machine lets you log in
as user fred, for example, and then you just type:
su
and type the root password. For all intents and purposes you've got a root terminal
open now. That means that you can do anything – just as if you had logged in as root
in the first place. You're really running the same risks by working as root, but you've
at least eliminated the risk of logging in as root. That's quite important from a security
standpoint.
You need to add the c (command) switch and put the actual command in quotes. Then
type the root password.
As you see, you can run any command that root can. That, of course, means that you
need to know the root password, so this is something that only the system
administrator should do. It's not a good idea to be giving your password to other users
so they can run commands. They can do that with sudo, as we will mention soon.
su can also stand for switch user. For example, if you had two accounts on a machine
let's say bob and harry you could log on as 'bob' and do: su harry and then work as
harry.
72
You're not just restricted to doing things as root. This might come in handy if you've
got two accounts on a machine. Instead of having to log in as the other user, you
could, for example, read a file that you've restricted permissions for. Let's say you've
got a file called my_ideas and you've removed read permissions to it for your group
and for others. Instead of logging in, you can type:
su fdavis -c "less /home/fdavis/my_ideas"
and you will now be asked for fdavis' password. Now you can access files from your
other user account without having to log in. Other users may also give you their
passwords to access things in their account. I question the wisdom of doing that, but
in an emergency it's an option. A coworker who's ill may give you his/her password
to access important files. That's acceptable in that kind of situation it seems, but the ill
worker should promptly change his/her password as soon as he/she's back at work.
The use of sudo as alternative
If you're the head systems administrator (or the only one) you can "deputize" your co
workers by installing and configuring the program sudo. In Unix/Linux speak, the
term 'su' means superuser that is, root. Only root has true administration rights and
privileges, so this program allows others to "do" su, hence the name, sudo. Ok,
Sheriff, time to fight the bad guys. Let's see what your deputies can do.
Your distribution should have this very popular program among its packages. If it
doesn't, you can go to: http://www.courtesan.com/sudo and get Todd Miller's great
application. After you've installed it, you have to create what's called a sudoers file.
You do this by typing:
visudo
as root. This is essentially a special version of the text editor vi just for creating and
editing the sudoers file.
Here is an example sudoers file I have for my home network. It is not really as
complicated as most are, but it gives a good basic idea of what you need to do to let
other users help you out with some administration tasks.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a
sudoers file.
#
73
# Cmnd alias specification
Let's break this down. First of all, we add the line
User_Alias TRUSTED = mike, maria
That means that the users mike and maria become the "trusted" users. And what are
they trusted with? Jump down to the last line for a second. They are trusted with
commands in the group INTERNET, KILL and TOOLS. What are those commands?
Jump back up to the section
#Cmnd alias specification
These trusted users can use ntpdate, for example, to keep the computer's time correct.
More information on that command later.
I've created a KILL group (sounds like Mafia hit men!) so other users can kill
runaway process that can only be shut off by root normally. Some server process may
have a problem and you might have to shut down that process. Starting it again is
something that's not included here however. It might be best for these deputized users
call the "real" system administrator and if that's you, for example, you may want to
check out the configuration files for certain servers before you start them again. You
may have to mount floppies or other partitions to get data from them, and that's where
the TOOLS section comes in handy.
When the user executes a command that's authorized in the sudoers file, he/she first
needs to type
sudo
and the command. For example, if you wanted to update the machines clock to the
exact time, you would type:
sudo ntpdate atimeserver.nearyou.gov/edu
Then you need to type your user password. If you make a mistake, sudo will hurl
insults at you (no kidding). Todd Miller has a good sense of humor and the results of
botching a keystroke are sometimes hilarious!
You can add more commands and users to your own sudoers file. Whatever you think
is prudent in your situation. There is some possibility for abuse. Use your best
judgment.
Becoming a super user
74
As we've said, a superuser is a kind of Superman. Being Superuser is not easy, but
we'll attempt to learn all it takes. The following commands are frequently used by
systems administrators to keep an eye on what's going on with their systems.
'last'
The command last will show you the people who have logged into the computer today
and the terminals they are/were using.
If you type:
last
You may get something like this:
fred tty6 Thu Oct 5 16:55 – 20:05 (3:10)
bob tty1 Thu Oct 5 still logged in (3:10)
root tty1 Thu Oct 5 16:23 – 16:43 (0:20)
reboot system boot Thu Oct 5 16:22
As you can see, you worked as 'fred' for 3 hours and 10 minutes. You are still working
as 'bob'. You worked as 'root' for 20 minutes (probably some administration tasks) and
you booted your computer at 4:22 PM.
This is a good way to see who's been using the computer if it's networked. For
example, if you saw a an entry for 'satan' and you hadn't given the Prince of Darkness
permission to login, you could fire off a nasty email to him about misuse of your
server. His address, by the way, is "thedevil@hell.com".
'df'
df is a command that you're going to use a lot if you're pressed for hard disk space.
Once again, there are many programs that run graphically that will inform you of the
space available on your Linux partition. But this is a very good, quick, nongraphic
way to keep track of your hard disk space.
If you type df you may get something like this. (This is actually taken from a system I
use for testing versions of Linux. You'll see it's somewhat pressed for space.)
If you start seeing a df output like this, it's time to get down to your local computer
shop and buy a new hard disk. Anyway, df is a good way to keep track of this.
'free'
free is a command that you can use if you want to know how much RAM memory you
have free on your system. By typing:
75
free
and you will get something like this
total used free shared buffers cached
Mem: 14452 13904 548 28208 492 7312
-/+ buffers/cache: 6100 8352
Swap: 33260 1556 31704
Sometimes, if a program is running particulary slowly, you may find out that your
memory usage is high using this command. Linux's memory management is quite
good but a certain program may be “hogging” memory. You could exit that program
and then type free again to see if it was the culprit.
'du'
du is the way to see how big files are. You can use it on a directory or on a particular
file. This is another command I use a lot. It's probably best to use the option du b (b
for bytes) and it will give you the exact figure in bytes. By default, du shows the
closest kilobyte figure. Let's look at a couple of examples:
If I type:
du people_I_owe_money.note
I may get an output like this:
194 people_I_owe_money.note
But instead, if I type:
du -b people_I_owe_money.note
I'll get:
197120 people_I_owe_money.note
As you can see, it's a big file. I owe a lot of people money. On the other hand look at
the output for 'people_who_owe_me_money.note':
1 people_who_owe_me_money.note
No, that's not the kilobyte figure. That's the byte figure!
You can also use this on a directory, and it will list the files and subdirectories and
give you the byte or kilobyte count, whichever you prefer.
Commands to control programs on your system
'ps'
Everything that is running on your computer is a process. You may prefer to call them
“programs”, but they really are not. Some programs (multithreaded ones) have several
processes, that is several separate tracks of execution. An example of such program is
the Apache web server. Apache needs to respond to multiple requests from visitors in
76
the shortest possible time. Thus Apache program has many processes running at the
same time, waiting for as many people to click on links in their browser windows at
the same time.
What do the columns mean? First each process is marked by a unique number, the
process ID (PID). When all the PIDs are spent by new processes (usually the
maximum number is 65535) the count starts over from zero. Ofcourse, there can never
be more than 65535 processes at the same time. TTY means terminal, and informs you
where a process displays its output and reads its input. Time doesn't show when the
process was run – it tells you how much processor time it uses, what percentage of the
overall time that is. Finally you can see the whole command used to run a process
along with all the parameters.
If you happen to forget what your name is, you can type ps u. This is the user mode
and your user name will appear in the first column. Actually, there's more than that.
There will be other columns about memory usage, the time you started running the
processes and others.
You can see other users processes if you type ps au. If you're not using a networked
computer, you will see yours and root's processes. If you're into detective work, you
can type just ps a and try to guess who's using the process.
Finally, ps usually gives you only processes that have a TTY. Some don't – those are
the daemons, will talk more about them later. To see also the processes that have no
TTY, use parameter x. So:
77
ps aux
is a command every Linux admin should have in their arsenal.
'kill'
kill is a very explicit word. It implies “death”. In the last part of this lesson we talked
about process IDs or "PIDs". Well, with the command kill plus a PID, you can
terminate a program. In other words, you kill the program. You will probably only use
this with troublesome processes; programs that may not let you exit regularly. A good
example of this is when you try a new program that hasn't got all the bugs worked out
of it yet. If the 'exit' button doesn't work, you can 'kill' it.
To do this, first, you would type ps and you would get this output that we talked about
before.
Let's say you're trying a new game that was just ported to Linux. The game is called
“Evil and Nasty Alien Visitors”. The name of the “binary” or program itself is called
evilaliens (the last one on my ps example). It's a beta version (i.e. check it out and tell
the author what bugs are still in it) and the game starts giving you problems. Now you
can't exit the program either. The aliens just took over Oklahoma and you swore you
got them all. You're playing in your Xwindow enviroment and you have an X
terminal open (probably the one you typed ps into). You would just type kill and the
PID number, in my example, 441. That is:
kill 441
and the program disappears, along with all those nasty aliens.
Here's a little trick. If you don't want to do two steps, ps and kill and you know the
name of the “binary” or program itself, as I mentioned before, you can just type:
killall evilaliens
and that should also do the trick.
Using 'kill' as root
Remember that when you work as root, you are the allpowerful master of the
universe (or at least the computer). When you use kill as root, you are the 007 on Her
Majesty's Linux Service. You have license to kill the process you desire. If you're
working as root and you need to use the kill command, it's a good idea to run ps au
78
and look closely at your PIDs. You don't want to end up killing some process that you
need.
Another way to kill a process
Try typing this: find / (kind of an absurd thing to do, but good as an example). It will
just start finding everything. If you have done something like this by mistake, you can
use the keys Ctrl+C to stop the 'find' process. In these cases, there's no need to use the
kill command.
Really kill stuff
Ok, you're probably feeling a bit sick of all the killing, so we'll use a nicer word:
signals. Processes on Linux need to communicate. They send signals to each other.
There are all kinds of signals.9 One of them is called 'hangup' (usually written as
HUP) and it means “pretty please go away, can you?”
This is what you send to a process when typing kill PID. 'kill' is just an awkwardly
named tool for sending signals to processes, and its default signal is SIGHUP. Of
course, sometimes a process don't respond to this nice request. The reason usually
isn't that they are rude, but just that they're all tied up with something else, like trying
to read your damaged floppy or waiting for your response on some other terminal.
That's when a proactive administrator may decide to use something stronger. A special
signal called SIGKILL can't be avoided by a process, and it literally eradicates it from
the system. It's invoked by parameter 9 to command kill.
Naturally, only root is allowed to do that.
Assigning and controling jobs
As we saw, typing something like find * may take a while to finish. Sometimes when
you run something like that, you decide that you don't have time to wait but would still
like your command to finish. For example, if you start downloading a Linux
distribution using wget10 it will probably take a long time. You can just press Ctrl+Z
to pause this process.
Note that this is not the same thing as Ctrl+C. Ctrl+C (or kill or kill 9) will end your
download and if you're lucky your download program will enable you to continue
sometime later (with wget just use wget c). Ctrl+Z means pause. When you press
Ctrl+Z you see something like this:
[1]+ Stopped find
9 http://www.comptechdoc.org/os/linux/programming/linux_pgsignals.html
10 I hope that I don't need to say something as obvious as man wget.
79
'1' is a number that is assigned internally to the paused program. Next time you pause
something it will get number 2, then 3 etc. To continue a paused program type:
fg 1
and it will resume just where it stopped.
fg means foreground – if this suggested to you that there is also bg, you're right. So
you can press Ctrl+Z again (note that the number is still 1) and type
bg 1
Now your program is running in the background. You can continue doing something
else and when the program is done, your shell will display something like this:
[1]+ Done find
which means that find has ended.
Managing excess output
If you actually used find / in this example, you would be in trouble – the background
program keeps printing its stuff. So find / will display every file on your system. As
the files are printed, your prompt drifts outside of the view very fast, as well as
anything else you try to type. Essentially it looks as if you lost control of your system!
But don't despair. You can still type fg 1 blindly and the program will come to front
where you can stop it permanently using Ctrl+C.
Can't remember the numbers? Just use the following command:
jobs
It will give you a nice list of all running programs with their corresponding numbers.
Forking the process
If all you really want is just to run a program in the background, you don't need to
press Ctrl+Z and type bg X. There is a shorthand:
find / &
That is, just type whatever you want to run in the background and finish the command
line with an ampersand (&).
The ampersand is usually called a “fork”. It doesn't look like a fork, but what it does is
that it “forks” the process execution. That is, instead of one process (bash) you now
have two processes that run simultaneously. Well, actually that's also what happens
with bg 1. “Fork” has completely the same effect as bg command.
But what about HUP?
If you ever worked at a computer remotely (via some kind of Internet connection), the
idea of running programs in the background sounds just perfect! You can leave an
80
important download to run over night and when you log back in in the morning your
distro is waiting for you.
Alas, it doesn't work like that. Each time you log out, all the programs that you had
running will receive a HUP (hangup) signal. This is the same thing as if someone
pressed Ctrl+C for each of them. This means your download will stop as soon as you
disconnect.
Luckily, there is a sort of HUPfilter, a command that basically makes your program
insensitive to breaks:
nohup
So, if you want to have your search running even after you log out, you can just type
nohup find / &
and all the files will be guaranteed to be found... somehow.
A neat side effect is that all of find's output is redirected to a file named 'nohup.out'.
You don't have to type '> nohup.out', it's automatic.
'top'
top is a good command to use when you want to see what your system's doing. top is
designed to show you how your CPU is being used. It will give you a pretty complete
list of everything that's going on in your computer. Here's a sample output of the 'top'
command:
PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND
332 root 12 0 4492 4184 1480 R 0 8.3 6.6 0:09 X
350 bob 4 0 13144 11M 7728 S 0 2.7 19.3 0:04 netscape
386 bob 1 0 768 768 596 R 0 0.5 1.2 0:00 top
345 bob 0 0 972 972 704 S 0 0.1 1.5 0:00 FvwmButtons
1 root 0 0 168 168 144 S 0 0.0 0.2 0:02 init
2 root 0 0 0 0 0 SW 0 0.0 0.0 0:00 kflushd
3 root 0 0 0 0 0 SW 0 0.0 0.0 0:00 kpiod
4 root 0 0 0 0 0 SW 0 0.0 0.0 0:00 kswapd
5 root 0 0 0 0 0 SW 0 0.0 0.0 0:00 md_thread
48 root 0 0 136 120 96 S 0 0.0 0.1 0:00 update
137 bin 0 0 300 296 228 S 0 0.0 0.4 0:00 portmap
141 root 0 0 292 264 212 S 0 0.0 0.4 0:00 rpc.ugidd
157 root 0 0 512 508 412 S 0 0.0 0.8 0:00 syslogd
81
161 root 0 0 692 688 296 S 0 0.0 1.0 0:00 klogd
212 at 0 0 304 276 220 S 0 0.0 0.4 0:00 atd
225 root 0 0 424 416 348 S 0 0.0 0.6 0:00 inetd
258 root 0 0 580 548 428 S 0 0.0 0.8 0:00 lpd
top has many cool options you can use while running it. To get a list of such options,
press H key (no need to hold shift, just press the key). The option I found most useful
is 'S'. It changes the delay between refreshing the list of processes. Default delay is 3
seconds which I found to be too much, so I usually change it to 1 or .5 seconds. Note
that there's a penalty to this – top itself is now using more resources. Also, when
working over network, too many refreshes can slow down your communication.
Also you can use 'k' to kill processes from within top!
Changing process priority
Each process on Linux has a priority. Processes with higher priorities will take control
over processor more often and for longer periods. The priority is a number between
20 and 20. The highest priority is (surprise!) 20, while 20 is the lowest. Default
priority of newly started programs is 0.
Be careful when assigning priorities! If a process isn't nice and tries to do too much
stuff at once, and you give it 20 priority, it may slow down or completely halt your
computer. Therefore the priority in Linux is usually called niceness (NI column in
top) and a command to change it is renice PID N where N corresponds to niceness
you wish to set. Reniceing can also be done from within top by using the N key. You
need to be root to set niceness lower than 0.
82
Lesson Ten
File Systems in Linux
This is a beginner's course and one of the concepts that newcomers to Linux find
different is the idea of a file system in Linux. That is to say, the way data is stored and
managed in Linux.
MS Windows and Mac users are used to clicking on icons and dragging the files they
want copied to a floppy or another part of the hard drive. Linux users that use KDE or
GNOME can have much the same environment. A Linux administrator nevertheless
should be familiar with how it all works “under the hood”. Most graphical programs
in Linux are nothing but “frontends” for various shell commands – that is, when you
click on a nice colourful icon, a bunch of commands are executed in background, far
from site of a frightened user. Actually, something similar happens in Windows as
well, only that Linux allows you to see (and control) this process.
Known filesystems
MS Windows 9x systems use a filesystem called fat32. It's an extension of old system
used by DOS, whose name was fat16. So if you upgraded your Windows from DOS,
you might remember that the installation offered to convert your fat16 to fat32. Newer
Windows such as Windows 2000 and Windows XP use a different filesystem called
ntfs (because they're actually versions of Windows NT). So upgrading Win98 to
WinXP, you might have also upgraded your disk from fat32 to ntfs. There's also fat12
that is used exclusively on floppies.
Very similar to this, there's a variety of filesystems commonly used on Linux. First
there was ext2 that was common in the 1990ies. This filesystem is now gradually
replaced with better things. One of them is ext3. The biggest benefit of ext3 over ext2
is the fact that the former is a journaled filesystem. This means that there's a sort of
journal of all disk activities. So if one such activity fails in the middle (like, for
example, if the power goes off), the system can easily repair the damage by replaying
the appropriate actions backwards until the system is in a consistent state. This means
that if you switch off your PC without doing a proper shutdown, the likelihood of
getting lost chains or clusters is much lower. Similar, ntfs is a journaled fs, while
fat32 isn't.
Another commonly used fs on Linux is reiserfs. It's made by a really smart guy from
Germany named Hans Reiser that has some great ideas, but also some not so great
ones, so many people choose to use ext3 or reiserfs depending on how much they
83
agree with mr. Reiser. Finally, big corporations such as IBM, SGI and Sun have
contributed filesystems created by their development teams to Linux, and so we today
have xfs, jfs and others.
Also of note is the iso9660 filesystem. It is used exclusively on CDROMs.
Known devices
A bit of history
So what's with the names such as ext2, you wonder?
Well originally Linux used a Minix filesystem.11 As Minix was a purely academic OS,
its filesystem was limited. Linux developers were very annoyed with Minixfs' lack of
features and kept adding them. Thus Linux filesystem became known as Extended
Minix (as opposed to plain Minix).
At the time when work on Linux 2.0 started, Linus and friends decided that the
horrible kludge that Extended fs has become needs to be rewritten. Extended 2 (or just
ext2) was born.
Ext2 is designed to be not just backwards but also forwards compatible. This is
achieved using socalled feature bits. Let's explain this...
The first block of data on an ext2 or ext3 partition is called “superblock”. You should
see this word often in the error message “wrong fs type, bad option, bad
superblock...”. Actually, this probably means that this partition contains a filesystem
of different type then the one you tried to mount. Superblock identifies the partition
name, type, and all the features that the filesystem supports. So if your Linux version
doesn't contain certain features, they'll simply be ignored, but if you write anything on
such partition you won't magically get those features back. This way you can use ext3
11 We talked about Minix in Chapter 1. It's a minimalist UNIXlike operating system developed by mr.
Andrew Tanenbaum.
84
partitions even on old Linux systems, but you don't want to write anything to them
unless you must, as you will lose your journal data.
Mounting file systems
In this part of the lesson about file systems we'll learn how to use the commands
mount and umount .
To access a floppy disk from the command line of our shell, we would use the
command mount and type the following: (remember: you need to be working as root
to do this)
mount -t ext2 /dev/fd0 /mnt/floppy
Now this assumes a couple of things:
• you have a floppy disk in the drive (you'd be surprised how many times I
forget to actually put the floppy in the drive)
• in this example, the floppy type (indicated by the option t) is a Linux
formatted floppy. If you want to mount a Windows floppy, change the option
to t vfat
• in your root directory (you can get to it by typing: cd /), or in /mnt directory,
you should find a directory named floppy. If you don't, you should create it
(mkdir floppy). Some Linux distributions create this automatically during the
installation process. Some don't.
Let's explain what we've just done here. When we type: mount t ext2 /dev/fd0
/mnt/floppy we are telling Linux that our floppy disk (/dev/fd0) is now part of our
Linux file system and that any files we would like to store on that disk will be copied
to /mnt/floppy, as if it were just another directory on our Linux system. If you did it
right, typing the command 'df' (the command to see how much free disk space) should
include something like this:
/dev/fd0 1390 649 669 49% /mnt/floppy
Your numbers may vary (especially if your floppy is blank!)
Now, to copy to and from the floppy disk, you would type:
cp my_file /mnt/floppy
85
If you wanted to create individual subdirectories on the floppy, you would first change
to the /floppy directory:
cd /mnt/floppy
Then you would use the mkdir command to create the directories you want. You can
also use the command cp r my_directory/ /mnt/floppy to copy the directory along
with all files and subdirectories to the floppy (make sure you have space! I have on
occasion tried to copy a 3MB file to a 1MB floppy!)
Automatic mounting of removable devices
Some Linux distributions have provisions for automatic mounting and umounting of
removable devices (this refers to floppies, CDROMs, USB sticks and other such
devices that are expected to come and go).
With one of them called supermount, in order to read from the floppy, all you have to
do is go to /mnt/floppy and try reading from it (for example, type ls). As soon as you
exit this directory the device will be umounted. Other such systems, such as magicdev,
work only from the GUI environment while from shell you need to mount and umount
devices manually, as described above.
Mounting other devices
You can also use the mount command so you can access other devices.
If you would like to get some files from a CDROM, the standard command to do this
is:
mount -t iso9660 /dev/hdb /mnt/cdrom
The system type, iso9660, is the standard file system for a CD. The device (/dev/hdb)
is the nonSCSI type of CDROM and the mount point (/mnt/cdrom) should exist. If it
doesn't, you should create it in the root directory with mkdir, just as you may have
done with the /mnt/floppy directory.
Remember that the concept of CDROM is read only. You won't be able to write to
this type of CDROM drive. A message will tell you that when you mount this type of
device.
Mounting another partition of the hard disk
Many people may have preferred to install Linux along with another operating system.
You may have Linux and Windows installed in the same computer. If you would like
to access files on the Windows partition you would type the following command:
mount -t vfat /dev/hda1 /mnt/windows
Windows is always in the primary partition, so that's why we've used the device hda1
(hard disk partition 1).
86
If you change to the mount directory (cd /mnt/windows) and then type: ls you'll see
something interesting. The directories are blue but the files are green (or red
depending on your distribution of Linux). You won't have the various colour
combinations as you do in Linux. That's because Windows' file system doesn't
distinguish file types. Everything looks like it's a program (binary) instead of a regular
file.
When you copy files from the Windows partition to the Linux partition you should
bear this in mind. For example, if you wanted to copy an mp3 file from the Windows
partition to the Linux partition to test out your sound configuration, it would show up
as a executable program and not just a standard file under Linux. This doesn't effect
your playing it, but for a more accurate accounting of what you have on your system,
you may want to change the permissions of the file so that it shows up as a regular file
in your colour scheme. We'll talk about file permissions and and making changes to
them shortly.
Umount command umounting file system
Mounting file systems that aren't part of the standard Linux system is considered a
temporary condition in Linux. Now that we know how to mount these outside file
systems in Linux, the important thing now is to learn how to unmount it when we're
finished using it.
In the early days of Linux, you could do serious damage to your system if you didn't
unmount manually after you were finished. Nowadays if you have mounted a system
and you shut down the computer without unmounting, the chances are pretty slim that
you're going to trash a file system. Slim, however, isn't good enough for me. I'd rather
not take a chance. I always take the time to unmount these external file systems when
I'm finished with them. Especially, if you don't umount a floppy disk after writing to
it, your files could be lost at best, and at worst you may need to reformat the floppy.
The command for this is:
umount [/mount point]
In the examples I used in this lesson, the mount points were:
• floppy: /mnt/floppy therefore umount /mnt/floppy
• CD: /mnt/cdrom umount /mnt/cdrom
• Windows partition umount /mnt/windows
Remember also to NOT be accessing the floppy etc. when you use umount or it will
give you a drive busy message. If you get this, you may have left a terminal open
where you were using to copy or write to the particular drive.
Also if you use a GUI program to view a partition (such as Konqueror) it may leave
some process using a partition even after you've done with whatever you were doing.
87
But there's a neat trick to remedy this. Command fuser will show whatever process is
currently using a partition. So for example:
fuser /mnt/floppy
will give you something like:
/mnt/floppy: 3539c
This means that process with PID 3539 is currently using the floppy. Now you can
just use ps to find this misbehaving process and punish it properly. Note that if the
process in question is bash, then it's probably you that is misbehaving! Exit the
mounted device before unmounting, by typing cd /.
I just wanted to point out another thing too. You are “unmounting” but the command
is umount (that is, without the N of un) Being u(n)familiar with the mount concept
when I started with Linux, I typed unmount instead of umount and much to my
surprise, I got the message: command not found. U(n)deniably, I had done something
wrong. It took me a while to figure out that the command didn't include an N. I
haven't really done a survey on how many people have actually done this. For all I
know, I may be the only person who has, but I just thought it best to warn you.
Well, now you can use the standard devices that most PC users need. Later in our
advanced class we'll talk about installing and using other devices like scanners, CD
writers, Zip drives and matter/antimatter flow inducers. (well, maybe we'll save that
last one for the superadvanced classes!)
/etc/fstab
/etc/fstab ... ... ...
Formatting disks under Linux
Formatting a floppy for Linux
Most floppies sold on the market are preformatted for MSWindows. You can copy
data from Linux to a Windows formatted floppy with no problem. If you want to copy
Linux files to a floppy to be used in another Linux machine or to be used by you later
in Linux, then it might be better to format the floppy for Linux's ext2 file system.
We should also say now that this is considered an administration task. You have to be
working as root to be doing this. As you get more familiar with Linux, you can use
commands such as su to do the work of root on certain occasions when you're not
actually working as root. We'll explain this command in later lessons.
88
To create a linux floppy “by hand”, you would place a floppy in the drive and type:
mke2fs /dev/fd0
The command is an abbreviated way of saying "make an ext2 file system". The other
part is the device, your floppy drive, which is known to Linux as fd0 (floppy drive 0).
As we mentioned in the first part of the course, everything is a file in Linux, including
your floppy drive.
A general formatting command is mkfs, but you need to specify which filesystem you
want to make – for example mkfs.vfat /dev/fd0 will format a floppy with fat
filesystem compatible with Windows.
You will hear the customary noise of the floppy drive (some are louder than others –
some older ones that I've heard sound like a chain saw) and you will get some output
like this:
Linux ext2 filesystem format
and some other information about the size of the floppy etc.
You now have a Linux formatted floppy. You may want to run this command to check
if the floppy has defects:
e2fsck /dev/fd0
Some windows managers have a nice programs to do both the formatting and the
checking of the disk at the same time.
What about “defragging”?
This I get asked a lot. Many people are used to “defrag” their disks in Windows so
that they “work better”. I saw them do that and none of them could swear that there's a
difference. Well, I say, whatever rocks your boat. If you are just dying to “defrag” your
disks in Linux too, you can do it this way:
defrag
But this command is not very likely to be installed on your system.12
12 You might want to read this article – http://www.newsforge.com/os/03/10/07/2028234.shtml – which
not only explains why defragmenting is not needed on Linux, but also talks about resizing partitions,
something which I don't have time to do in this course. I advise also reading this FAQ for a more
technical viewpoint: http://cbbrowne.com/info/defrag.html .
89
Lesson Eleven
About daemons
Daemons are the evil invisible processes that are after your soul. Well actually they're
not evil. They just do system maintenance that doesn't require their visibility. As we
mentioned before, they have no controlling TTY, which means that you don't normally
see their output or send them any input. But, as you are the root, the one in charge,
you are able to see them and control them.
If you're familiar with Windows, you might notice that these programs have a much
more boring name there – they call them services.
Starting and stopping services
Daemons live in a special place:
/etc/init.d/
In some distros the place is different. For example, in some older versions of RedHat
its
/etc/rc.d/init.d/
In Slackware there is no such place at all. Slackware has its own convention for
talking with daemons, but since Slackware is a bit demonic distro as such, we won't
touch that subject.
Lets look inside this directory. Most of the executable files we see are the actual
daemons, such as https (Apache), sshd, bind (DNS) and many others. Running any of
these files (how do we do that?) will give us a list of available options, such as this:
Usage: /etc/init.d/partmon {start|stop|restart|status}
This is the same for most daemons. stop can disable a daemon if you don't like its
presence, to bring it back use start. If you're not sure its running or can't find it in the
output of ps aux use status. restart is a shorthand so you don't have to type two
commands.
SysVinit system
Ok, if you ever see System V (a very old UNIX system) mentioned in the context of
Linux, it will usually have to do with daemons and which of them run automatically
(at system boot).
When you turn on your system, it goes through a number of levels. Each level contains
certain daemons. Daemons that are in level 1 start the first, then those in level 2 etc.
90
until level 5 which is the last one. You don't have to go to the last level if you don't
want. These numerical levels have certain conventional meanings, but distros don't
need to keep those meanings. Furthermore, you can reconfigure the run levels as you
desire.
Anyway, level 2 usually means the minimal working system (just so you can log in
and fix something). Level 3 is a fully working system but with no graphical
environment. Finally, level 5 should also run an Xwindow environment. In modern
distros this is symbolized by a special daemon called 'dm' (which means “display
manager” and actually is the logon screen you sometimes see). So, if you never use the
rodent on your desk, just configure the system to start to level 3 instead of 5.
How do you decide what is in which level? Well, levels are nothing but directories
(what did you expect) named like:
/etc/rc.d/rc1.d/
/etc/rc.d/rc2.d/
etc. These directories contain symlinks to actual daemons that are, as we said, under
/etc/init.d directory. The symlinks look like S12foo or K34bar. The S means that a
daemon will be started in this runlevel and K that it will be stopped (or killed, as some
would like to say). The number represent the order of events – first the S01 is started,
then S02 etc. If a daemon has neither S nor K symlink its status in this runlevel is
undefined. E.g. when switching to this runlevel from another one, if the daemon was
previously running it will still be running, and if it was down it will remain down.
Please see Appendix A. Some common deamons for a small list of services commonly
found on Linux.
/etc/inittab
...
Monitoring log files
...
/var/log/messages
...
dmesg
...
syslogd
91
...
92
Lesson Twelwe
Writing shell scripts
................
The '.bashrc' file
You'll find a lot of files on the system that end in 'rc'. Those files allow you to
configure a certain program to run just the way you like it. The best way to find it is to
type:
ls .bashrc
You can open that file with vi, joe or pico. For example, in your home directory you
would type 'pico .bashrc'
Adding aliases to the .bashrc file
Well, you now have '.bashrc' open in 'pico' or your new, favorite text editor. It would
be a good idea to add this line first, so you know what you've done.
# my personal aliases
The pound sign (#) tells the shell not to read that line. It's known as a 'comment'. Then
you would add:
cp='cp -v -i'
on the next line write:
rm='rm -i'
so we don't send anything into byte heaven without a warning. And finally
mv='mv -i'
So you're aliases will look like this
# my personal aliases
alias cp='cp -v -i'
alias rm='rm -i'
alias mv='mv -i'
Save that file and logout and login again. Now you have a safer, easier shell
environment. As you get more proficient at Linux, you can add more aliases as you
see fit.
Now your shell's ready to go. If you type logout and then login again, you're aliases
will work. There is also a shortcut. If you type:
source .bashrc
you're aliases will be ready to go.
93
Automation of Tasks on Linux
One of the main tasks of a system administrator is carrying out maintenance work on
the server. Most of these tasks can be automated or programmed to be carried out at
certain times without user intervention. In this section we'll talk about the two most
widely used programs to carry out tasks in this way.
Use of 'at'
'at' is a program to carry out commands that you intend to do only once. It's mostly
used for scheduling specific jobs under specific circumstances. If you had to rotate
your company's webserver logs every Saturday, 'at' is not the appropriate tool for the
job. That would be done best with 'cron', about which we will talk about shortly. Let
say your boss, the CTO, called for a meeting with you at 1:00. He wants to know how
frequently your external consultants are logging into the network. This is a prime
candidate for 'at'.
First, you'd type:
at 12:45
which would give you plenty of time to get that information before the meeting. You
will see the 'at' prompt:
warning: commands will be executed using /bin/sh
at >
Now you'd write the commands you want carried out. Here we'll get the output of the
command last, which tells us who's logged in to our servers lately, and write it to a file
called 'logins'. The second command, separated by a semicolon (;) will then print
that file using lp.
last > $HOME/log-ins; lp $HOME/log-ins
press 'Enter' and then 'Ctl + d' and you will see the following:
job 15 at 2003-02-16 12:45
Of course, your job number will vary with the number of times you've used 'at'.
There are various ways to indicate at what time you want 'at' to carry out commands.
at now + 5 minutes will carry out a command five minutes from when you type it.
There's even a provision for at teatime which will carry out commands at 4:00
PM/16:00 hrs. (If you don't believe me, consult 'man at'!). You can cancel these jobs as
well. If you type:
atrm 15
you will remove job 15 from the 'at' queue. To see what is in the 'at' queue, type:
atq
You can control which users are allowed to use 'at'. By default
/etc/at.deny
94
controls who cannot use 'at'. That is to say, the users listed in at.deny cannot use it.
You can also create an
/etc/at.allow
file. Creating at.allow makes the at daemon ignore the /etc/at.deny. Therefore, anyone
who is not in at.allow cannot use 'at'. The question of using one file or another comes
down to a question of your management style. If you prefer to let people use things
until they abuse the privilege, then use the default at.deny. When the user 'barney'
programs an 'at' job to set off an infernal sounding noise when he's gone to get coffee,
scaring the bejeebers out of everybody in the office, then you can add him to the
at.deny file. If you're of the opinion that nobody needs to use it, then create an at.allow
file with only your personal user account listed. Remember that the root user can
always use at.
Use of 'cron'
From a system administrator's point of view, the cron daemon is probably the best
thing since sliced bread. You can schedule practically any program at any time, for
any date and at any interval. That is to say, if you want a text dump of the number of
times a person with the IP address 64.09.200.12 has logged into your computer and
you only want it on February 4th, cron will do this for you.
The jobs that you want to run with cron can be scheduled in various ways. The most
common way is to edit a file which is known as your crontab. Normally, each user has
his/her own and is able to schedule jobs by editing it. You can add to and delete
entries from you crontab by typing:
crontab -e
But before we go jumping right into scheduling jobs, it's important to point out that
cron looks for a particular syntax in your crontab file. You just can't just write:
get my mail from mail.mydomain.com
and expect it to work.
Once you have decided when you want a particular command to be run, you add the
command itself at the end. A typical crontab entry will end up looking like this:
30 3 * * 0 $HOME/bkup_script
which runs a script in your home directory to back up your files at 3:30 AM on
Sunday.
The syntax in your crontab is not easy to master, but it is not excessively difficult to
comprehend either. First, there are 5 time periods that cron looks for. You start your
crontab entry with these. Here is the order and some examples:
95
Minute Hour Day (of the Month Weekday
month)
40 = twenty to 2 = 2:00 AM 9 = 9th day of 10 = October 6 = Saturday
the month
Table 1. Guide to Cron times
If you entered this into your crontab, you would simply save the file by pressing ESC
+ :wq which is a vi command. Vi is normally the editor that crontab uses by default,
but you may use a text editor other than vi, by typing export VISUAL=pico, for
example, which would allow you to use the pico editor. Every time you want to alter,
add or delete an entry, you would first type.
You will not be able to use all of these fields at the same time. If you have used the
first four, you do not need the last one. This last one, the weekday, is particularly
useful because it lets you run jobs once a week. There is also another way of doing
that and we'll talk about it shortly. If you don't wish to specify a particular time
period, you must substitute an asterisk (*).
crontab -e
Enter whatever it is that you want to get done and then type
ESC + :wq
(or the combination of keys used to save a file in your particular text editor of choice).
If you're curious about what's in your crontab file and want to list the jobs you have
programmed, type:
crontab -l
If you want to delete your crontab file, type
crontab -r
Variations on a theme
Crontab entries don't have to necessarily have just numbers in them. We can combine
the numbers with other characters to modify how commands get carried out. For
example, I have a USB webcam that doesn't really do what it's supposed to, which is
to take a picture every minute and then shut off. It takes the picture all right, but it
doesn't shut off. So I wrote a script to shut it off and then I added a crontab entry to
call this script every minute. This is what I added:
0-59/1 * * * * $HOME/shutoff_cam >/dev/null 2>&1
Let's look at this one part at a time
059/1
basically means that between the 059 minutes of every hour, at every 1 minute
interval, the camera is to shut off. To show you how useful cron is, I remember seeing
a James Bond movie where the perpetual badguy, Blofeld, was brainwashing girls to
carry out biological attacks from a base in the Swiss Alps. He would play these
hypnotic tapes to the girls every evening. There is one scene where you see Blofeld
96
and one of his minions switching the tapes manually. If only they had had a Linux
computer! They could have done this:
30-45/3 22 * * * mpg123 /home/esblofeld/brainwash_girls.mp3
>/dev/null 2>&1
which would play the brainwashing instructions at 3 minute intervals between 10:30
and 10:45 PM.
Disclaimer: PLEASE DO NOT TRY BRAINWASHING TECHNIQUES AT HOME! ALSO,
LINUX ONLINE DOES NOT ENDORSE THE WORLD DOMINATION SCHEMES OF
SPECTRE. THIS IS ONLY USED AS AN EXAMPLE. THE ONLY WORLD DOMINATION
SCHEME WE ENDORSE IS THAT OF LINUS TORVALDS.
We should also point out something that you've probably already noticed in the two
examples above; that they end with
command >/dev/null 2>&1
We tacked this on the end because cron, by default, mails a "report" to you of the
command you carried out. This is so you can either get the output directly in the mail,
and/or to see if the command was successful. You may have made a mistake when you
added an entry to your crontab (like typing the wrong path or the name of a command
wrong). That way, you're notified and even if your job was important and you missed
the first one, you can correct it and then you won't miss any others. Again, in the
examples above, if we got a mail every time the command was carried out (every
minute or couple of minutes), your inbox would quickly fill up with useless mail.
Therefore, we tack that on so that cron will send notification of those jobs to /dev/null
(ie. the trash).
Here are some other examples of variations:
0 0 15,30 * * cat /var/log/mysql.log > $HOME/mysql_use
30 8 * * 1-5 /usr/bin/who
The first one makes use of the comma, which means 'and'. In the first example, we see
that we will get a report of MySQL use on the 15th and 30th of every month (except
February, of course!). The second one will run 'who' which tell us who is logged in,
every weekday (15) at 8:30 AM. This would be a particularly good one for systems
administrators who want to see who's working (or at least who's loggedin) at the time
they also start work.
Permissions for cron
The ability to use cron is regulated in the same way as 'at'. Those in
/etc/cron.deny
are not allowed to use cron and all other users are allowed. If you have a
/etc/cron.allow
file, this supersedes cron.deny (ie, cron.deny is ignored) and allows only those listed
in it to use cron.
97
cron.hourly, cron.daily and cron.monthly
Most Linux distributions have three directories in /etc called cron.hourly, cron.daily
and cron.monthly, which, as you may have already guessed, lets the systems
administrator run jobs on an hourly, daily or monthly basis. Simply by placing a shell
script or a symbolic link here, jobs can be carried out at those intervals. There is no
need to have a crontab entry for these jobs.
As you can see, the sky is the limit with the things that you can do with cron. It won't
get you to the point where you've programmed absolutely everything, letting you pass
your working hours at the beach, but it will make your life a whole lot simpler.
Task: Customize your login script so that each time you log on to your system the
following is displayed:
Welcome $USER
You were last here at $LASTDATE
There are currently $USERS users on the system
Of course, instead of the variable names the script should display corresponding
values.
Task 2: create a script that “rotates” the /var/log/messages file. E.g. each month this
file should be moved to directory /var/backup and renamed to “messagesMMYY”
where MM is the number of current month and YY the last two numbers of current
year.
98
Lesson Thirteen
Backing up your files
Let's face it, computers aren't perfect. Linux is an “almost perfect” operating system,
but things do happen and data is sometimes lost. The best way to avoid problems is to
backup your files. Linux provides two key programs to do this: tar and gzip.
First we'll start with tar. This programs assembles various files into one package,
commonly called a “tarball”. Let's say you have some files – notes that you've taken
during this course. You have:
• notes_1.txt
• notes_2.txt
• notes_3.txt
• notes_4.txt
• notes_5.txt
and you've placed them in a directory called /linux_course. You want to back them up
and keep them on a floppy, let's say. You would type the following command to
package them in a tarball:
tar -cvf linux_notes.tar notes*.txt
First, you have tar, the name of the program. Then you have the options, c (create –
create a new archive), v (verbose – show what files are being put in), f (file –
specify file name – should always be the last option). Then you have the name of the
file you want to create (linux_notes.tar) and the files you want to backup (notes*.tar).
This presupposes that you may have other files in the directory that you don't want to
include. If you want to include ALL files in a directory, just substitute notes*.txt for
*.*.
If you've got good data storage capabilities (Jazz or Zip drives, a CD writer or a tape
backup drive), you might want to back up whole directories along with their
corresponding subdirectories. Then you would enter in the directory, let's say
/home/bob/ and issue the command:
tar -cvf bob_backup.tar *
With one asterisk, you will include directories and files without extensions (my_file
as opposed to my_file.txt). Be prepared to get a fairly voluminous tarball.
This is the first step in the backup process. Now let's look at the second step; the
compression of these files.
99
Using 'gzip'
As we mentioned, tar just assembles the files together into only one file. There is no
reduction in the size of these files (the tarball might even be bigger!) Now we would
have to do one more thing in order to reduce this file into a more manageable size: use
gzip.
gzip is the preferred compression tool for Linux. To reduce the size of your tar file,
you would issue the following command:
gzip your_tar_file.tar
and the tar file would be compressed. You can also compress a regular file using the
same command, but gzip is used primarily with tarballs.
The result would be a file like this: your_tar_file.tar.gz
The two file extensions show us that the file is a tarball and it is compressed with the
gzip format. You can now proceed to store this as you see fit.
Putting it all together
tar has an option built into it to use gzip to zip the file at the same time you make the
tarball. If you add z to the options, and change the name of the file to create to a .gz
extension, you have the whole shebang in one step. Our previous example would be
modified to this:
tar -czvf bob_backup.tar.gz *
Remember f should always be the last option.
Untarring and unzipping files
Using tar and gzip sort of supposes that you're going to want to "untar" and "unzip"
these files at one point or another.
The easiest way for doing this is to use tar for the whole process. You would locate
the zipped tarball in question and then ask yourself a question: Did I make any
changes to the files inside the tarball after I made it? If you did, then you've got an
old tarball. If you untarred it in the same directory, you'd overwrite the existing ones.
If you would like a copy of the old file, untar it in a different directory. If you don't
want the old files, then you should make a new tarball. It's pretty standard backup
practice.
When you've decided what you want to do, to proceed with the "untarring", issue this
command:
tar -zxvpf my_tar_file.tar.gz
100
I've used my preferred options. I'll explain them:
• z unzip the file first
• x extract the files from the tarball
• v "verbose" (i.e tar tells you what files it's extracting)
• p preserves dates, permissions of the original files
• f use the file in question (if you don't specify this, tar just sort of sits around
doing nothing)
The files are extracted and your original tarball is preserved (my_tar_file.tar.gz). You
can also untar the file and then use gzip separately. Just leave the z option out of the
previous example and type:
gzip -d my_tar_file.tar.gz or
gunzip my_tar_file.tar.gz
(gunzip runs gzip d "automagically"!)
These commands are good if you've just zipped a regular file (not a tarball).
Other compression tools
zip
Most Linux distributions come with other tools to compress files. One of these is zip,
famous in the MSDOS/Windows world. If you're planning on compressing files to
give to someone who (still) uses the Windows operating system, this might be your
best bet. You can also use unzip if someone gives you a file compressed with zip.
Consult the man file (man zip) for specific instructions on using this tool.
bzip2
There is also another tool that is rapidly gaining acceptance in the Linux world: bzip2.
As a matter of fact, the Linux kernel source package, usually comes "bzipped". When
you compile a kernel (create a custom kernel for yourself from source) there is an
option to create a bzipped kernel. This is supposed to become the official way of
doing it in the near future, so it may be a good idea to get to know bzip2.
For all practical purposes you would use this tool in the same way as you would gzip.
The compression factor is supposed to be a little better. There are some differences in
options for more advanced users. Consult man bzip2 for more information.
101
Lesson Fourteen
Installing New Programs
The way you install a new program will depend primarily on two things:
1. What distribution (version) of Linux are you using?
2. What is the origin of the program that you want to install?
Let's look at the first question: What distribution are you using?
RPM
There are some basic commands you're going to need to know to take advantage of
the RPM system.
rpm -i new_program.rpm
This installs the program (i option for install)
rpm -q program_name
This "queries" your system to see if you've got a certain program
installed. Let's say you hear there's a new version of the popular
Internet browser Opera for Linux and you don't know if your Red Hat
based distribution installs this by default or not. Before you download
the RPM for Opera, you could type the command: rpm q opera. If
you do have the package installed, it would give you the version
number:
opera-5.0_whatever-number
If you don't have the package installed, you will see:
package opera is not installed
If you don't have Opera installed, then you can download their RPM
and run rpm i opera_whatever_version.rpm as root and install the
program.
102
If you do have the program installed and the rpm q opera command
gives you a older version number and you want the newerone, then you
have two options.
One is to "uninstall" the older package and install a new one in its
place. Not that this is the most efficient option. I just wanted to
introduce you to the e option for RPM. That is, to get rid of a program
that you've installed, you would type rpm e program_name. For
example, if you've got Opera's beta version 7 and you've just
downloaded the beta version 8, then you would first do:
rpm -e opera
This gets rid of Opera from your system. Then you would type
rpm -i opera_beta8.rpm
(or whatever the package is actually called). That installs the new
version.
Those are the basic commands of the RPM install/update system in a nutshell.
When you're using your windows manager, there are some very good tools for
installing, updating and uninstalling RPMs that are graphically based. You can choose
menu options to do all that we explained before instead of having to type the
commands in the terminal. You may want to look into programs like Kpackage for
KDE or Gnome RPM for the GNOME enviroment. They may make these tasks a lot
easier, especially if you're just starting out in the Linux world.
Some words of caution on downloading RPMs
Some of the most popular Linux distributions base their install and update prodedures
on Red Hat's package management system. These include Mandrake and SuSE for
example. Both of these companies create their own RPMs to be specifically installed
on their systems. That means if you're using SuSE or Mandrake your best bet is to go
to their respective "official" websites or mirrors and download their particular RPM
and install it using the procedure outlined above or their specific tools. You may run
into a problem if you installed an RPM for Red Hat on a SuSE system. Certain
components in the package (like documentation or libraries) may get copied into a
different directory than was intended for that system. Third party RPMs from
reputable companies, like the Opera web browser in mentioned above, should install
fine on any RPM based system. I have successfully installed this package (the same
103
exact RPM file) on SuSE, Mandrake and Red Hat. I even converted this RPM to
Debian (.deb) package format and successfully installed it in a computer running
Debian. More on this conversion later in the show!
Just a brief second word of caution. Getting an RPM doesn't necessarily mean that
you're automatically (or “automagically”) going to be able to install it. Many websites
out there offer RPMs for download. The good ones usually include a list on that
particular RPM's page of other programs or libraries that you need in order
successfully install and use the program. If you see a list a mile long of
“requirements” (those other programs and libraries you need), then you might want to
ask yourself if you really want to try that program out.
And here's just an editorial comment on my part about this type of thing as well. The
big buzz word with Linux is "free". That's fine. You can theoretically get a
distribution from the Internet along with programs and install it for free. (ie. no
money down). I think, however, that time is money, to use the trite expression. Time
might be even more valuable than money. (lost money might be reearned but not lost
time). When I first installed Linux oh so many years ago, updating and installing stuff
was at times a frustrating experience. I suggest that newcomers to the Linux world buy
(yes, I said buy) a good boxed set of a commercial distribution and then they'll have
more programs than they would ever need, all installed and working properly along
with a manual to tell you what to do in case something doesn't work.
Now let's look at installing programs with Debian.
Debian packages
There are various methods to installing new programs on a Debian system. I like to
classify them according to your connection type.
dpkg
This is the "classic" way of updating a Debian system. Typically, you could go to
Debian's website or any one of its mirrors and download a package. Then you would
type:
dpkg -i package.deb
to install it.
The main drawback to this is that you may find a package that you like but it may have
dependencies (ie. other programs that it needs to make it run) and if you don't have
those packages, then the install will fail.
This is what the Debian people themselves have to say about this method:
Many people find this approach much too timeconsuming, since
Debian evolves so quickly typically, a dozen or more new packages
104
are uploaded every week. This number is larger just before a new major
release. To deal with this avalanche, many people prefer to use
automated programs.
Despite what they say, the main advantage of dpkg, it seems to me, is that it is easy for
people who have dialup connections. This is because the alternative, automated
programs they're talking about, which are dselect and aptget are better for permanent
connections (cable, xDSL, T1, T3). Let's talk about this method of installing new
programs with Debian.
dselect
When you use dselect you get a graphic user interface of sorts (not under X window,
though) to guide you through the install of new programs.
First you'll get asked for your preferred access method. That means, how you're going
to get and install them. For example, if I were doing an install of Debian with CDs,
then I would choose CDROM. But if I were updating, I would choose FTP
Then you would choose the packages you want with a + sign. You can even put
updates on hold (indicate that you want to update, but not actually do it) with a = sign.
There may even be conflicts or dependency problems and 'dselect' will warn you
about those.
Then you start the process by choosing the install option. Debian will then configure
the installed packages. Then you're on your way.
As I said before, the main advantage to this is that any conflicts or dependency
problems will be resolved right here. The Debian people point out that this is ideal for
installs or largescale upgrades. If that's the case, it seems that a slow and sometimes
expensive dialup connection would be less than ideal for this.
In the next section we'll look at installing programs under Slackware .
Installing new programs on Slackware
Slackware, known to the Linux world as "Slack", has the reputation of being, on one
hand, a flexible distribution that allows you to do practically anything you want and,
on the other hand, one that is for "experienced" Linux users only.
A lot of these considerations are "politically" motivated. Slackware lacks some of the
"smooth" and "slick" graphic installation packages that are becoming standard fare in
commercial companies' offerings but in the end, if you're willing to just use the
command line utilities, it's just as easily updated as any other major distribution.
105
Slackware's package format
Slackware packages come in *.tgz format. This a variation of the *.tar.gz format we've
seen before. You can go to your favorite website and download new programs for your
Slackware system and with a simple:
installpkg some_program.tgz
you have your new program installed.
If that particular package doesn't quite move you and inspire you too much, you can
just remove it:
removepkg some_program.tgz
You can also add the option warn between the installpkg/removepkg command and
instead of installing the package, it will tell you what new files are going to get added
to your hard disk. That's a good option for the "I wonder if I want this" moments of
your life.
You can upgrade programs to newer versions with this command:
upgradepkg a_new_version_of_something.tgz
Using other package formats
If you're using Slackware and you can't find a package your looking for in the *.tgz
format, you can also grab on to an *.rpm and convert it.
The way to do this is:
rpm2tgz some_package.rpm
This takes the "rpm" in question and converts it to *.tgz format. Then you can use
installpkg on the new file you've created to install it.
106
Lesson Fifteen
Networking
ifconfig and route
......
Other config files
The most important configuration files are located in the /etc directory. Any good
administrator will know this directory like the back of his/her hand. Here is list of the
most important files that you may have to change regularly:
hosts
hosts.allow
hosts.deny
Let's have a look at what these files do.
hosts is a list of the machines in your network with their names and IP addresses.
Anytime you add a new machine to the network, you should add an entry here.
Actually, before the Domain Name System (DNS), there used to be a "master" hosts
file to locate all of the machines on the Internet. This was, of course, in the days
before the Internet was used by the general public. It looks like this:
# this machine
127.0.0.1 localhost
The naming scheme is entirely up to you. What we have here is a class C network
(192.168.X.X) which is connected to the Internet, probably via some highspeed line.
The first part, as you can see, are the IP addresses. This is followed by the Fully
Qualified Host Name, which includes the domain name and the top level domain. You
should not use .com, .org or other Internet top level domains if you're not connected to
the Internet. The last part is the name of the machine or "alias". The first line of this
hosts file lacks that last bit. That's because you can enable what's known as
'loopbacking' on a Linux machine. It may be the case that you want to run networking
programs on a machine but you don't have an actual network. Think of 127.0.0.1 as a
107
virtual network inside your machine. When you type 127.0.0.1 or localhost, it "loops
back" to the machine itself. Even with a network, this is often used to run
development web servers, for example, where you want to restrict access from the
outside.
hosts.allow is a file that controls who has access to the services that your machine
provides. It might look something like this:
ALL : 192.168.
imapd: .friendly.com, 999.99.
sshd: .friendly.com
The syntax is simple. You define the service (all, imapd, sshd) and separate the list of
hosts allowed to use them with a colon (:). The host names or IP addresses must be
separated by commas. Neither names nor numbers have to be complete but they
should begin or end with a dot (.) where applicable. That is, in the example above,
host names can begin with a dot because that means any machine in that domain,
friendly.com, can access that service. (ie, quite.friendly.com, very.friendly.com). With
numbers, you can specify that machine netblock are allowed to access your services
by putting a dot after the first sets of numbers, as you can see in our example of
192.168. and 999.99
In this example, those using machines in your local network (192.168.) are allowed to
use all the services available (ALL). Machines in domain .friendly.com and the
netblock 999.99. are allowed to access the IMAP daemon, normally used to access
email via IMAP . .friendly.com is allowed to login to our network via SSH (Secure
Shell).
hosts.deny is a file that controls whocannot access the services that your machine
provides. Most hosts.deny files are the same. They look like this:
ALL : ALL
which means that ALL are denied ALL services. This is standard practice. As we have
seen with cron and at, X.deny and X.allow files work on the principle that users who
are not specifically allowed to use services are denied them. Though it may sound
logical, it needs to be restated that if we use the hosts.deny approach, if your name is
not listed, then you're allowed to use all the services offered. If we used the
hosts.allow approach, then we establish who can use certain services and we therefore
deny the rest to everybody else. This is easier to maintain and it is more secure.
Another configuration file that you may come in contact with from time to time is
resolv.conf.
resolv.conf is used primarily to list the name servers your machine uses to find other
machines on the Internet:
search mycompany.com
domain mycompany.com
108
nameserver 192.168.0.3
nameserver 999.99.9.9
nameserver 999.99.9.8
The first entries, search and domain, tells what domains to look at and then append to
names. For example, if you just typed the name 'intrepid' in a browser, it would
append .mycompany.com to that name to access that machine. The other entries
beginning with nameserver list the the IP address of machines that have run Domain
Name Service (DNS) software (BIND, for example) so that you can find other
machines on the Internet by name. Our first entry here is a machine in our local
network that runs this software. The others listed are normally those of your Internet
service provider or others who offer name service to the public.
Ping, traceroute, ssh, netcat.....
.......
109
Lesson Twenty
Compiling kernel
What is the Linux kernel
The Linux kernel is essentially what Linus Torvalds started work on in 1991. A kernel
is the part of the operating system that handles the communication between software
and your machine's hardware. In the decade since Linus first kernel was released, its
complexity has grown enormously and so has the number of people working on it. It
is now the largest collaborative project in the world. The reason for this is because
Linus released the Linux kernel under the terms of the GNU General Public License,
which makes it freely distributable and allows anyone to make changes to it. In this
lesson we are not going to be talking about making changes to the source code itself,
but we will talk about choosing certain files of this source code in order to create a
custom kernel.
Where to get the kernel source
As I mentioned, the kernel source code is available for anyone to download it and you
can find it at Kernel Org.
At the time of this writing, the latest stable version of the Linux kernel is
2.4.22 . Though the arrival of version 2.6 is imminent, we will be dealing with
the 2.4.X version of the kernel in this lesson.
The latest stable version of the kernel comes in at just under 30 megabytes in a bzip'd
tarball. A gzip'd version is also available and is slightly larger. You should download
the format of your choice and untar it in the directory /usr/src/.
Kernel configuration
Compiling a new kernel is a serious thing. It's a lot like changing the motor in your
car. If you haven't done it correctly, the machine, which is like your whole car, will not
run. For this reason, you should not attempt this on a mission critical system the first
time around. On the other hand, you shouldn't be afraid of it either. Like any upgrade,
if you have taken the appropriate steps and have made backups you shouldn't have
any problems.
110
First, you need to know what hardware is in your machine in order to get a good
kernel at the end of the process. There are also other concerns. For example, you need
to decide what kinds of file systems your machine needs to work with (ext2, Reiser,
VFAT, NTFS, etc), what character support to include in the kernel, what networking
protocols you need to use or whether the machine will be used as a router or firewall,
to name a few. This is important because what sets a Linux kernel apart from, say, a
Microsoft Windows one is that you can pick and choose what goes into it and then
your kernel will be much leaner. This customization is what makes Linux operating
systems more stable. So it's important to know what you need. It makes no sense to
compile support for USB scanners into your kernel if you're not going to be using a
USB scanner. On the other hand, if you have this type scanner and you don't compile
USB support into the kernel, you won't be able to use it.
There are three main interfaces that you can choose from when you are preparing the
configuration of a new kernel. They are 'config', 'menuconfig' and 'xconfig'. The first
one is an oldstyle commandline interface that is not very attractive nor do I
recommend it if this is something that you've never done before. The last one, xconfig,
is a GUI based configuration tool that requires you have Xwindow running. This may
not be the best option if you have a server because there's no need to be running x
window in that environment. As a general rule, I stick with the middle option,
'menuconfig' because it has an ncurses based GUI (text mode with colors) and
therefore it is visual and straightforward. It can also be used to configure a kernel on a
remote machine, something that xconfig is just not suited to. Here's what the
menuconfig system looks like:
To use this, just type: 'make menuconfig' inside your /usr/src/linux/ directory. You will
see something very similar to the screenshot above. What you have here are the major
categories of kernel configuration options. Since I don't know what each machine out
there is going to need, it would be impossible to go over every option. However, we'll
look at the more common options and use those as examples.
111
The kernel configuration process creates a .config ([dot]config) file with your
options in the /usr/src/linux/ directory. If you have systems with similar
hardware, you can use it between machines. This also comes in handy if you
do a complete switch to another distribution, for example. If you use the same
.config, you'll need to fire up 'menuconfig' once so your .config file gets
"registered" with the new system.
Using kernel modules
One of the most popular features of the Linux kernel is its support for modules. A
module is code that provides for support for certain things. These modules can be
inserted or removed from a kernel while its running. Normally, support for, say, a
network card would be builtin to the kernel. That is, the kernel would always include
that support. It would form part of the kernel itself. If your network card were to fail at
some point and you weren't able to find that kind of card, you would have to
recompile your kernel to get it to provide support. However, if you indicated that you
wanted to provide support for various types of network cards as modules when you
configure your kernel, you could swap out a new card supported by one of the
modules. You would then have a program called 'insmod' activate the modules to
provide support. Besides this, a kernel with all of its support options compiled into it
will be bigger. It may become so big that you may not be able to make a floppy rescue
disk from it. It's perhaps a good idea to configure nonpermanent items as modules.
(SCSI support for pen drives, if your hardware is IDE, for example). Configuring
items as modules requires you to choose this option at the beginning.
If you activate this, you should indicate (M) if you want something configured as a
module. An asterisk (*) will compile support directly into the kernel.
Other kernel options
Directly following the modules support options is the processor type option.
Processor type and features --->
Here, you should use the processor type for your machine (Pentium III, AMD, etc.).
You should obviously not try to get support for an AMD Athlon if what you have is an
Intel 486. Again, you need to know what's in your machine before you even start.
You will find the rest of the options to fairly selfexplanatory. If you're going to be
using the machine as a mail server and/or web server, you need support for your
network card, tcp/ip support and perhaps some other protocols plus iptables support is
recommmended if you're planning on implementing a firewall. Choosing support for
things like this then leads to opening subcategories to see more options for this
112
support. Again, it's impossible to go through all of these options, but fortunately the
kernel maintainers have done a lot of work to provide explanations for most of them.
They are to be commended for their labors. By pressing < Help >, you'll see
explanations and even some recommendations. If you think you might need this
support, it's a good idea to read through the explanations thoroughly. And as the
kernel maintainers point out in all of these help bits, if you don't know what this
means, you can probably safely choose 'no'.
If you're planning on "rolling your own" kernel, as they say in the Linux
community, please take the necessary time to do this carefully. Napoleon once
said: 'Dress me slowly, I'm in a hurry'. The time you take at the beginning to
make sure that you've included all the features you want will save you time on
the other end, just as Napoleon knew that the time spent in making sure the
buttons were all lined up prevented his dresser from having to unfasten
everything and start again. I have been in situations where I rushed through a
kernel configuration only to boot the machine and have sound cards not work
or firewalls give error messages just because I left things out in my haste.
When you exit 'menuconfig' you will be prompted to save your configuration. Once
you've done this, you can proceed to compile your new kernel.
Compiling a new kernel
I remember the days when compiling the kernel took hours (or even days on slow
machines). With today's powerful CPUs and cheap memory, you should probably be
able to get a new kernel up and running in under a half an hour (not including
configuration time).
Your first step in compiling the kernel will be to create the interdependency
configuration for the new kernel. For example, if you've got a BTTV web cam you
also need video support for Linux. If you've chosen BTTV support for your kernel and
not 'Video for Linux', then your dependencies will break. To make sure you've got
everything you need, you need to type the following:
make dep
You'll start seeing a lot of activity. If you see error messages at the end, then you've
got some unresolved dependency. You'll need to go back to 'menuconfig' and add
support according to what the error messages show. If this isn't your first try at
building the kernel, you can invoke the following command to clean up files left
behind from previous attempts. It is optional.
make clean
Now we're ready to create our kernel. You can now invoke the following command to
compile your new kernel:
make bzImage
113
Again, if you're working with recent hardware, this will not take too long. If you're
curious, you can watch what it's doing. If you've got a slow machine and you're not
wellversed in C programming, it might seem like watching paint dry. Sooner or later
you'll have a nice new kernel, deposited in /usr/src/linux/arch/i386/boot/. This doesn't
mean that you're finished, however. If we've chosen to use kernel modules, we need to
deal with those now. We need to do this:
make modules
This command will create the modules. Now you must move them to /lib/modules. To
to this, you need to use this command:
make modules_install
Please note that there's an underscore (_) between those words. Even though that's the
last command we're going to invoke related directly to the kernel, we're still not
finished. Now we need to move our new kernel to the /boot directory. This is
accomplished by simply doing:
cp /usr/src/linux/arch/i386/boot/bzImage /boot/
If you've already got a bzImage, this will overwrite it. If you want to keep the previous
kernel image, you may rename either one of the files (kernelnew, bzImage.old, etc.).
We still have one more step to go. We need to tell the bootloader about your new
kernel. This will differ depending on the bootloader you're using.
LILO and GRUB
In case you're wondering, we're still talking about the kernel, not a Walt Disney
movie. LILO and GRUB aren't cartoon characters. They are two bootloaders that are
used to boot the kernel on Linux systems.
LILO
LILO has traditionally been the most popular bootloader on Linux systems. We talked
briefly about LILO in our section on configuration files. Here we're going to talk
more indepth about it. LILO is a program that allows you to choose how you're going
to boot your computer. You can configure it to boot one or more Linux kernels or even
boot into another operating system, like Microsoft Windows. LILO is commonly
installed into the master boot record or your hard drive, though you may also choose
to install it into a sector of a primary partition. It has a configuration file, lilo.conf,
which controls what it does. This can be found in /etc/lilo/. Here's the sample lilo.conf
we saw in a previous lesson:
# device to boot
boot=/dev/hda
# our root partition
root=/dev/hda1
# map file
map=/boot/map
# delay in 10ths of a second before booting
delay=20
# kernels to boot
114
default=linux
image=/boot/bzImage
label=linux
read-only
append="hdc=ide-scsi"
image=/boot/vmlinuz
label=linux_old
read-only
We must add the above line to lilo.conf to make our system aware of the new kernel.
After we save the changes, we need to invoke LILO so that the changes take effect.
Simply type:
lilo
This last step is extremely important. If you don't do this and you shutdown or
restart, your system will not be able to boot from the hard drive. You'll need to
insert a floppy or CD rescue disk and mount the hard disk partition where
lilo.conf resides and run lilo again.
Now you're free to reboot and try out the changes.
GRUB
115
normally installed into the master boot record. Here's my grub.conf for my RedHat
workstation:
default=0
timeout=10
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
title Red Hat Linux (2.4.20-8)
root (hd0,0)
kernel /boot/vmlinuz-2.4.20-8 ro root=LABEL=/
initrd /boot/initrd-2.4.20-8.img
As we did with LILO, we'll add some lines so that we can use our new kernel:
title Custom Linux Kernel 2.4.22
root (hd0,0)
kernel /boot/bzImage ro root=/dev/hda1 hdc=ide-scsi
'title' is what will appear in the splash screen so that you can choose at boot time. what
follows 'root' is how GRUB understands your hard drive. Linux will boot from the
first partition of the first hard drive. This is the hd0,0 part. GRUB starts counting at
zero, though it may sound confusing at first. Next we tell GRUB where the kernel
image is, to boot it readonly, where our root (/) directory is located. Finally, like the
LILO 'append' parameter, we tell GRUB we've got a IDE CDRW drive that should be
treated like a SCSI device.
Enjoy your new kernel
Now you can enjoy your new kernel. It probably runs better than the one that's offered
out of the box by most distribution vendors. Also, keep in mind that users of
proprietary operating systems can't change their kernel for better performance. That's
another reason for enjoying it the freedom that Linux provides.
116
Appendix A
Some common daemons
I compiled a small list of daemons that you will usually find on a Linux system. This
list references names that you are likely to see in /etc/init.d directories or in the ps
output.
* We do not recommend disabling services marked with an asterisk unless you know
what you're doing
117
Service Alternative Description Configuration
names
devfsd * Creates virtual device files in the /dev
directory.
dhcpd DHCP server automatically assigns IP addresses /etc/dhcpd.conf
to computers.
dmx dm, prefdm This “service” simply starts your preferred
graphical environment. By moving the dm
service in the hierarchy you can affect the speed
with which your system starts.
fam * File Alteration Monitoring daemon, tracks /etc/fam.conf
changes made on your system files and informs
the applications. Certain programs (e.g.
Konqueror) use it to refresh their view.
fbset * Configure the framebuffer (console based ?
graphics).
fetchmail A service that fetches email from remote /etc/fetchmailrc
servers into local mailbox folders.
ftpd A simple but not very secure FTP server.
gam A more modern version of fam ?
gpm Support for mouse in console applications (such /etc/gpm/*
as lynx)
hwscan harddrake, * The tools of various distributions to track new
kudzu hardware on your system and configure it.
hotplug * Support for devices that are activated on
plugging them in (such as USB memory,
cameras etc.)
inetd * A superdaemon that starts other daemons as /etc/inetd.conf
needed. It's best to leave this daemon active, but
look into its configuration for unwanted
services for added security.
inn Internet News Network, the most popular news ?
(Usenet) server.
iptables firewall, * A simple (builtin) firewall. ?
SuSEfirewall
ircd IRC (Internet Relayed Chat) server. There are /etc/ircd/*
many varieties of it.
irda Support for infrared control devices. /etc/irda.conf
irkick A Kicker (KDE panel) applet for infrared ?
control.
idsn Loads the kernel modules needed for certain /etc/sysconfig/isd
ISDN cards. n
joystick Configure whats necessary for joysticksupport /etc/sysconfig/joy
stick
kalarmd korgac A KDE panel applet for scheduling (alarms). ?
118
Service Alternative Description Configuration
names
keytable kbd Loads the (nonEnglish) keyboard layout for use /etc/sysconfig/ke
in console. yboard
kheader Updates links to kernel headers so that when
you recompile modules etc. they are compiled
for the currently running kernel (in case you
have several).
kjournald * Maintains “journals” for filesystems that
support it (such as ext3).
klipper KDEs cut&paste buffer. ?
klogd Kernel log daemon, monitors kernel messages
so that they can be read using dmesg.
kmix kamix A sound volume mixer program. ?
ksysguardd A daemon started by program KsysGuard /etc/ksysguardd
(activated by KDE using Ctrl+Esc). If it's
properly configured, can be used for monitoring
systems remotely.
lisa Background network scanner, used by ?
Konquerors LAN browser.
lpd An older printing system (see cups above) or a ?
simulation of it that uses cups.
mingetty * A minimalist getty, gives console support.
mtink Allows ink level monitoring on certain Epson ?
printers.
mysql mysqld MySQL, one of the most popular opensource /etc/my.cnf
database servers.
named bind Berkeley Internet Name Daemon, one of the /etc/named.conf
most popular DNS servers on the Net.
netfs autofs Mounts automatically all the configured Samba ?
and NFS shares.
network internet, * Configures and starts all the network devices /etc/sysconfig/net
networking and other configured for automatic connection. work/*
Some distros may break if you disable these /etc/sysconfig/net
daemons, due to lack of the loopback device. working/*
nis Network Information Server, a complement to ?
nfs for identification of computers on network.
nfs Network File System, a service that enables /etc/exports
exchange of files wih UNIX/Linux computers.
nmbd NetBios daemon, enables Windows computers /etc/samba/*
to “see” your Linux machine in their Network
Neighborhood. Should be used with smbd
nscd Name Service Caching Daemon, speeds up /etc/nscd.conf
network operations by making a local DNS
cache.
119
Service Alternative Description Configuration
names
ntpd xntpd Network Time Protocol (NTP) updates your ?
computer clock according to a remote server.
numlock Activates the numlock on boot.
oki4daemon Support for Oki 4w and compatible printers. ?
oooqs OpenOffice.org QuickStarter, a tray applet that ?
preloads OpenOffice.org in memory so that it
starts faster.
partmon Warns if your partition is close to being full. ?
portmap Support for Sun RPC on Linux. Many servers ?
use portmap daemon services, including: NFS,
NIS, Samba.
postfix A very popular mail server. Postfix is specified ?
in LSB (Linux Standards Base) thus many
distros preinstall and start it by default even
though there is no real need.
proftpd A popular FTP server. /etc/proftpd.conf
random * Resets the random number generator. This
increases the security of your system.
rawdevices raw * Activates support for “raw” access to block
devices.
resmgr resmgrd ??? ?
rpasswdd ??? ?
rsync Updates files from a remote server. Commonly ?
used for creating a mirror server.
samba smbd Enables exchange of files with Windows /etc/samba/*
computers.
saslauthd ??? ?
sendmail A very popular mail server. /etc/sendmail.rc
/etc/mail/*
snmpd Simple Network Management Protocol (SNMP) /etc/snmpd.conf
daemon. SNMP simplifies monitoring of
devices in a network.
squid A versatile web proxy server. /etc/squid/*
ssh sshd SSH (Secure Shell) daemon. Enables secure and /etc/ssh/*
simple remote access to your computer.
syslog syslogd * Provides logging services to various /etc/syslog.conf
application. Logs are commonly kept under
/var/log
udev * A new device mapping system for 2.6 kernels
(see devfsd).
vsftpd Very Secure FTP Daemon. ?
120
Service Alternative Description Configuration
names
xfs X Font Server, the XWindow won't start /etc/X11/fs/confi
without it. g
xinetd * An advanced verion of inetd, a system for /etc/xinetd.conf
starting daemons when needed. /etc/xinetd.d/*
121
old stuff
Lesson Seventeen
Printing under Linux
Although this is my personal opinion and I have not done scientific research on this
topic, I would say that word processing is probably the computer activity which is
done with the most frequency. Email may be surpassing the popularity of basic word
processing (email is just an extension of that, really). The fact is that people open up
their word processor of choice (or the one they're forced to use at work) and write
things on a pretty regular basis. Writing things, logically, means printing them
afterwards. Despite what we're hearing about the web doing away with the printed
material as we know it, it seems that we handle more paper not less of it in our
networked world. After all, many people curl up in bed with a novel or a report for
work. I don't see that custom being altered unless someone comes up with a
comfortable way to use a computer in bed!
Obviously, if writing/word processing is so important and printing is the logical next
step after writing, then getting your printer up and running under Linux is going to be
a priority. Luckily, Linux has changed a great deal and hardware manufacturers got
the idea quick that it didn't matter what OS people used their printers with, it was just
important that they used them. That means that all of the major distributions offer first
rate tools to get practically any printer running under Linux.
What you're doing when you print under Linux
Historically, printing in the Unix platforms started off as just sending plain text to a
line printer, (resulting in rather plain looking text on paper with holes on each side
some of you might remember this). The basic means of printing in Linux just takes off
from there. When you first set up your Linux machine to use a printer, you'll be
configuring the lpr or "line printer". The lpr works with the lpd or "line printer
daemon" running on your system. . A "daemon" is just a program that works in the
background, without your direct intervention. This daemon just waits there for
printing jobs to be sent to it, which it will then send to the lpq or "line printer queue".
The queue (queue the British word for what Americans call a "waiting line") just puts
your print job on hold until the system figures out the way to print it. This holding
pattern is usually pretty quick maybe a couple of seconds because computers work
pretty fast, generally.
As I mentioned, printing used to consist of just sending rather boring looking output
to a line printer. Today's computing needs in terms of printing are much more
demanding. Exotic fonts, graphics and other visual goodies can be found in standard
printed material that comes from a computer. Your Linux machine should be capable
of printing anything you want as long as you have the correct filters. For example, if
you downloaded a report from the Save the Whales Foundation on the mating habits
of the pilot whale in PDF format and you wanted to print it, you'll need some filters
installed that know how to print PDF files. All mainstream Linux distributions come
with Ghostscript. This is a free implementation of Adobe's Postscript filters. These
122
filters are used to make sure that "What you see is what you get", to use a hackneyed
expression.
How to print
If you want to print, you should push the "print" option in the menu. OK, you know
that already. But how do we get from the point where you've got Linux installed to
where you can print something with your word processor? Here are the steps.
1. Install a printer
Most Linux distributions come with tools that will get you printing in no time. As I
mentioned before that Linux's printing system is based on basic line printing, you'll
need a working "printcap" file (to be found in /etc/printcap, usually) that tells your
system what printer it's supposed to work with. With SuSE you can use YAST to create
this file (which will invoke a program called 'apsfilter'. Red Hat comes with
"printtool", Mandrake has its printer setup tool in its main configuration package.
Debian and Slackware both use the 'apsfilter' tool as well.
This lesson is not meant by any means to be the definitive list on products from every
vendor, so if your particular distribution isn't listed here, you'll have to consult the
documentation in your case.
For example, the /etc/printcap file that SuSE configured for my main machine at home
is this:
printer1ascii|lp1|y2prn_printer1.uppasciiprinter1|y2prn_printer1.upp ascii:\
:lp=/dev/lp0:\
:sd=/var/spool/lpd/y2prn_printer1.uppasciiprinter1:\
:lf=/var/spool/lpd/y2prn_printer1.uppasciiprinter1/log:\
:af=/var/spool/lpd/y2prn_printer1.uppasciiprinter1/acct:\
:if=/var/lib/apsfilter/bin/y2prn_printer1.uppasciiprinter1:\
:la@:mx#0:\
:tr=:cl:sh:
#
printer1|lp2|y2prn_printer1.uppautoprinter1|y2prn_printer1.upp auto:\
:lp=/dev/lp0:\
:sd=/var/spool/lpd/y2prn_printer1.uppautoprinter1:\
:lf=/var/spool/lpd/y2prn_printer1.uppautoprinter1/log:\
:af=/var/spool/lpd/y2prn_printer1.uppautoprinter1/acct:\
:if=/var/lib/apsfilter/bin/y2prn_printer1.uppautoprinter1:\
:la@:mx#0:\
:tr=:cl:sh:
#
printer1raw|lp3|y2prn_printer1.upprawprinter1|y2prn_printer1.upp raw:\
:lp=/dev/lp0:\
:sd=/var/spool/lpd/y2prn_printer1.upprawprinter1:\
:lf=/var/spool/lpd/y2prn_printer1.upprawprinter1/log:\
:af=/var/spool/lpd/y2prn_printer1.upprawprinter1/acct:\
:if=/var/lib/apsfilter/bin/y2prn_printer1.upprawprinter1:\
:la@:mx#0:\
123
:tr=:cl:sh:
2. Install the Ghostscript package and other useful filters
Most major distributions always recommend the Ghostscript package by default, so it
goes on your system with an standard install. This will take care of your more
advanced formatting needs. Other ones, like the jpeg libraries and other image
formatting libraries are also installed by default so you can print your image files
easily and painlessly.
3. Turn on the printer and press the print button
I sometimes forget to turn on the printer, so that's why I included this last part.
Some useful trouble shooting techniques
Most printers work from a parallel port. You must have parallel port support enabled
in your kernel. Most major Linux distributions will install a generic kernel with this
enabled. Printing therefore shouldn't be a problem. However, most people at some
stage of the game prefer to compile and install their own custom Linux kernel. When
you get up to speed on Linux and you decided to do this, always remember to include
parallel port support into your new kernel. I have forgotten to do this (which ironically
seems to happen with much more frequency as I get familiar with compiling kernels)
only to find that I can't print anything when I've finished installing my new kernel.
I have also noticed my system choke on stuff sent to it from Corel WordPerfect. I
won't go into the "hows" and "whys" (because I honestly don't know why or how this
happens) but I have fell victim to an inability to print from WordPerfect on occasion.
What I usually do is see if in fact I have pressed the button 'print' and something is
waiting to be printed. To see if you have something waiting in the printer queue, just
issue the command:
lpq
This will show you what's in the printer queue or if there is in fact anything there.
Output generally looks something like this, if you have a problem (like my printer
being unplugged, in this case).
waiting for printer1 to become ready (offline ?)
Rank Owner Job Files Total Size
1st bob 46 grocery_list.txt 667 bytes
2nd bob 47 lyrics_to_sinatra_my_way.txt 2323 bytes
For example, if I wanted to just get rid of these files, shut WordPerfect down and start
it up again and try printing again (which usually works for me), I would just issue the
command:
lprm
Which removes the whole line printer queue. I could also be selective about it and
only delete on of the files by typing the command:
lprm 47
Alas, my debut in the karaoke bar will have to wait, but I can still do the shopping.
Hopefully you won't need to use these troubleshooting techniques very often, but
they're good to know just in case.
Enjoy printing under Linux!
Using Linux to access the Internet
124
We live in an interconnected world. In fact, you're using this interconnectivity in form
of the Internet to access this course. Chances are, however, that you're using some
other OS to connect to your ISP and read this course. After this lesson, you should be
able to connect and browse what's out there in cyberspace using Linux.
Onramps to the "information superhighway"
I think that the term "information superhighway" is a perfect analogy for the Internet.
That's probably why it has become so popular. The superhighway itself is the
telephone companies infrastructure the lines, fiberoptic cables, switches and
satellites that bring the hundreds of millions of pages of content to you, including this
page. Your computer is like that car on the highway. Your modem or other device that
connects you is like the engine of your car. That's why we've written this lesson. If you
can't get the engine to work, you're not going anywhere. Linux and other OSes are a
bit like the fuel you put in your car. If you have been using Windows, that's like using
gasoline. If you switch to Linux, that's different, like jet fuel. You'll have to modify
your engine to be able to use it, but you'll go faster in the end.
Types of connections
There are basically three types of connections to the Internet; leased lines, broadband
and dialup connections.
Leased lines are highspeed connections that ISPs use to connect you to the rest of the
Internet or big companies use to communicate between parts of their organization and
to allow you to connect to them. These are known as T1 and T3 lines in North
America and E class lines in Europe. This course will not deal with setting up and
Internet connection with these lines. It's a little out of the scope of your average Linux
user.
xDSL (Digital Subscriber Line) and cable modem are what is known as "broadband"
connections. These services offer 24 hour highspeed connections to the Internet in
most cases (unless you shut off your machine, of course). For example, in my area, I
have ADSL service. My connection runs at 250 kilobits per second when I am
receiving data. To put it in other terms, I can download a 5 megabyte file (like a song)
in about 34 minutes. This depends a lot on where you're connecting to and other
factors, but broadband is the best alternative for home users. Depending on what
company is providing you with this service, you can even use this connection to serve
your own personal or small business webpage using Linux as a web server. In the
xDSL area, you can even opt for higher speeds (up to 2 megabits per second) and have
Internet service that rivals much more expensive leased line alternatives. Lately, cable
modem is becoming more popular than xDSL, particularly in the United States
because the cable companies seem to have gotten on the ball faster to offer consumers
high speed connections. With all due respect to telephone companies, there may be,
and I suspect there are legitimate technical reasons why a cable connection is
essentially cheaper and easier to provide to to consumers. The reasons behind this
would go beyond the scope of this lesson, (and I'm not a telecom engineer) so suffice
it to say that cable seems to be the way people are going to get high speed connections
to the Internet.
Dialup (standard modem) connections are by far the most popular way of connecting
to the Internet. Up until the late1990's, if you weren't a Fortune 500 company, it was
125
the only way to get on the Internet. This connection type basically consists of using a
modem to dial the phone and connect to the Internet Service Provider (ISP). The
modem "negotiates" the connection (ie tells the ISP who you are) using a couple of
established network protocols. The best speed you can hope to get out of a dialup
connection is 56 kilobits per second. That is to say, about 5 times slower than the
slowest broadband connection.
ISDN a footnote: A few years ago, in my area at least, the telephone company was
trying to sell people on ISDN (Integrated Services Digital Network) to solve the two
main problems with Internet use, namely the slow modem speed and the fact that you
couldn't make or receive phone calls while using the Internet. They promised
connections of up to 128 kilobits per second (the key words here being up to, using the
tactic of car advertisements that say from 9,599 dollars, but in reverse). This has never
seemed to have caught on, at least in my area. The few people who I know who had
this service (and later dropped it) complained about the speed. What they promised,
just couldn't be delivered. At any rate, nobody seems to be talking about it so much
anymore.
Let's move on to the next section where we'll show you how to set up the different
Internet connection alternatives under Linux.
ADSL with Linux
Fortunately (or unfortunately, depending on your relationship with your local telecom
company) the telephone company handles most of the heavy lifting during the process
of getting Linux to work with an ADSL connection. I went through the process of
switching from standard dialup not too long ago, so the process is fresh in my mind.
Here are some of the things I had to do.
1. Call the ISP. This is pretty important. Sometimes they will offer you Internet
service and at the same time arrange for the telephone company to come over
and install a splitter which allows you to use the same phone line for data and
voice transmission. It is also important that you know if you accept their
services, you may have to accept the hardware they recommend (or force on
you). There are two main connection options; via router and via modem. They
may pretty much obligate you to use one or the other, even selling your their
own hardware in the process. In the best case scenario, ask if you can use your
own choice of hardware and then hope they say yes.
2. Choose a router or modem If a modem isn't forced upon you, then it's a good
idea to choose the router option. The basic reason for this is that it is usually
platform independent which means that it doesn't matter what OS you're using
because you can probably configure it using Telnet (in my case) or even a web
browser, which I have also seen done. For example, in my case, I chose a
router that had capabilities for filtering out unwanted incoming connections.
This is very important for security because you're going to be connected 24
hours a day. This is a great option for a small business because a router allows
you to painlessly share the connection between multiple computers.
3. Get an Ethernet card If you go the router route (pardon the pun), you're going
to need an Ethernet card. These cards are designed to allow you to connect
computers in a Local Area Network (LAN). My card of choice (because it was
126
the only one they sold in my area) is the NE2000 clones. Realtek 8029 PCI is
the one I use in my machines in my home office. This is a good one because
most major distributions will detect this (they always have for me) during a
standard install of Linux. Plus, even if you've never looked under the hood of
your PC you can muster up your courage and install this card yourself. For the
fainthearted, I have even heard of the telecom people doing this for you. You
can also call your local guru. I encourage people to do it for themselves. It's a
question of using a small screwdriver. What that's in, you connect the router to
the Ethernet card so your PC can receive the data. If you've got more than one
PC in the house, you should get an Ethernet hub to distribute the connection
between PCs.
Putting in all together
A picture speaks a thousand words, so I made a little drawing of my home network to
demonstrate what a possible set up might look like. (graphics courtesy of The GIMP
It's really too good of a program for my poor artistic skills!)
Two cables (red) come from the splitter. One is for the phone and one goes to my
router. One Ethernet cable (green) goes from the router to the hub. Other Ethernet
cables (blue) go from the hub to the PCs.
Now, to get on the highway
My home network is a private local area network, so each PC is assigned an IP
address which is a number that computers identify themselves with. In case you didn't
know, when you go to www.linux.org, you're actually going to a computer that is
assigned a number on the Internet. In my home, these numbers start with 192.168. and
then have two numbers after these. The numbers 192.168.X.X are reserved for private
networks, so you will have to use these. If you used any other numbers, they might
conflict with numbers that are actually out there on the Internet. I assigned my PCs
the numbers 192.168.0.1, 192.168.0.2, 192.168.0.3, 192.168.0.4 respectively.
127
Now, when the telecom people came to hook me up, I took out my router and
connected it to the data line coming from the splitter (see the picture). Then I hooked
up the router to the hub and then one of my PCs to the hub. In my case, the
manufacturer of the router in the factory assigned the number 192.168.1.1 to the
router, so as soon as I turned it on, you could say for all intents and purposes that I
had another computer on my local network with the address of 192.168.1.1. The router
was equipped with the possibility of using a a program on a CD to configure the
Internet connection if I was using Microsoft Windows or Telnet for another OS, like
Linux.
Before I used Telnet to access this router, I had to know what address my telecom
company had assigned to me for Internet purposes. That is to say, when you use the
Internet, you don't identify yourself to other computers with 192.168.X.X. With ADSL
you are assigned a unique number with which to connect to other computers. This
number has to be unique. It's a lot like running a men's bowling team. If there are 20
members and 7 of them are named Bob then, if someone announces that "e;Bob has
the highest score" then there's going to be confusion. In my case, I was given a unique
number, let's say it was 20.20.20.20. Then I used Telnet to access the router. I opened
an terminal in my PC and typed:
telnet
then:
open 192.168.1.1
which was the local numbered address the router came with by default. They also
furnished me with a default password which I used to connect to the router.
Once in, I had a text mode menu (the best you can do with Telnet) and going by the
router's manual plus my local telecom's instructions, I assigned the router the unique
Internet numbered address my telecom had given me and then I changed the address
of the actual router to 192.168.0.5, to me more in synch with my local network's
numbering scheme and then I changed the password to access the router. I saved the
changes and exited. Now, at least, I had ADSL service coming in to the router.
The final step was to tell the PCs where to get their Internet connection from. I was
using my workstation to configure the router, so I logically started with that one. I run
SuSE Linux on this machine, so I had to change 2 files: /etc/route.conf and
/etc/resolv.conf. The changes I had to make took all of 30 seconds.
First, in /etc/route.conf, I had to write the line:
default 192.168.0.5 0.0.0.0 eth0
Which means that 192.168.0.5 is the default "gateway" to the Internet, or where the
machine is going to route out of to get to the outside. 0.0.0.0 is the subnet mask (not
important for our discussion here) and eth0 stands for your Ethernet card that you
installed and is connected to the hub which is connected to the router.
Then I added two lines to my /etc/resolv.conf file.
nameserver 30.30.30.30
nameserver 40.40.40.40
These are not the actual numbers I was given. It's just an example I used to correspond
to the numbers that could be given to you by your telecom company. These are the
primary and secondary DNS numbers. DNS stands for Domain Name Server. A
128
domain name server is just a machine that has an inventory of other computers on the
Internet. That is to say, these computers know that www.linux.org is actually a number
out there and they help you find it. Without these numbers, you wouldn't stand a
snowball's chance in hell of finding anything on the Internet. I learned this fact in my
haste to get the rest of the network set up. When I was configuring the last computer, I
forgot to change /etc/resolv.conf file. When I fired up my browser, it basically did
nothing until I remembered to change that file.
If you're using Mandrake or Red Hat, instead of /etc/route.conf you'll have to add two
lines to /etc/sysconfig/network . These are the lines I added:
GATEWAY=192.168.0.5
GATEWAYDEV=eth0
The changes to /etc/resolv.conf are the same.
You're on line let's be careful out there
After doing all this, I was on line with all machines going out through the router. I
quickly disconnected the hub to all but one machine and following the instructions,
and set up some necessary security. This is important because you are a sitting duck
for intruders with ADSL. You may not think that your local home network might be
important compared to some corporate website (which, it really isn't as far as a target
for hardcore hackers/crackers) but there are a lot of mischievous people with time on
their hands that go around looking for trouble. These people use tools they get off the
Internet to scan numbers at random to see if the machine attached to the number can
be "hacked". Most of these people, popularly known as "Script Kiddies" seldom know
how the software works and really don't care. They just know they can do harm with
it. As they say, a little knowledge is a dangerous thing. IRC chat is a good place to
chat with friends and also a good place to inadvertently invite people to take a swipe
at your machine. Most people on IRC are there to socialize, seek technical help and
even work and collaborate on projects at a distance. But there are a few people with
dubious social skills who are just on IRC to be jerks. A lot of these people are script
kiddies who like to get in feuds with people on channels. Seeing as IRC can tell a lot
about where you are, you are somewhat vulnerable to these socially unacceptable
characters and what they may try to do with you. Remember, they don't have to know
how the program works, only what it does. Report any threats to the channel
operators. Sometimes the person's ISP figures in the information on IRC. Report them
to their ISP or the local authorities if they threaten to do harm to your machine.
Security with ADSL
Security in Linux is way out of the scope of this beginners' course on Linux. There are
a couple of things that you can do without having to be a guru on security to help
secure your Linux box.
A brief explanation of ports
I was lucky in that my router has the ability to filter packets built into it. Packets are
the data that comes in and out of your computer when you're connected to a network,
like the Internet. The people who designed the big network of networks came up with
the concept of ports or point of entry to computers from the outside. For example,
webservers run on port 80. If a user on a network wants to access a web page on a
server, their computer makes a request to port 80 on the server to send them the page.
129
That's a pretty safe port. It has to be. The WWW wouldn't function if it didn't.
Actually, it isn't the port itself that should be considered safe or unsafe, it's the
software running the behind it. Apache's webserver is pretty safe. But, as we have seen
with the famous CodeRed worm, Microsoft's webserver IIS isn't. Telnet, for example
runs on port 23. That's a port that I told the router not to accept connections to. Telnet
is a 'shell' a way to connect to a remote computer. The passwords you send to
connect via Telnet, even though you may see little asterisks (or nothing) can be picked
up easily by people who 'sniff' these passwords. I also disabled my computer's ability
to accept connection via Telnet. I substituted it with SSH or Secure Shell. SuSE
Linux's most recent offering, (v. 7.2 at the time of this writing) enables SSH by
default. SSH accepts remote connections that are encrypted or coded. That makes it
almost impossible for someone who you don't want to to connect and try to do harm to
your computer from the outside. SSH runs on port 22. I also have FTP disabled (port
21).
Firewalls
A firewall is just a barrier between a network that's inside a home or company and the
outside world. If your private network didn't have a firewall, people could just connect
to it and see what they wanted. It would be like a house made of glass. People would
spend the day throwing stones at it.
Any decent network that's connected to the Internet has a firewall. The subject of
firewalls goes way beyond the scope of this beginner's course and I don't pretend to
explain how to set up a firewall here. Some big corporations pay people big money to
set up firewalls in their organizations and then they get hacked anyway. I always think
of Goldfinger's comment in the James Bond movie of the same name when he
explains his plan to steal the gold from Fort Knox to a bunch of incredulous Mafiosos.
007's redheaded nemesis says: "It is a bank like any other and banks can be, how do
you say 'knocked off'" If you want a good guide to providing security for your PC
running Linux, I suggest you read Bob Toxen's Real World Linux Security: Intrusion
Prevention, Detection and Recovery, the best selling book on security from a Linux
perspective.
Practical protection for the beginner
A good way to protect your Linux machine, when you don't know too much (yet)
about security is by making the following very simple changes in two files:
/etc/hosts.deny and /etc/hosts.allow
First, in /etc/hosts.deny add the following line:
ALL : ALL
This is meant to block (1st ALL) services that your computer provides from anybody
(2nd ALL) that may try to log in to your machine. Then, if you have more than one
computer (a small business or home network) you should add this line in
/etc/hosts.allow
ALL : 192.168.0.
This will allow local users to access the computer. There's no reason not to let people
locally to log in via the SSH program that we mentioned before. This is OK as long as
you trust them. If you are a home user you're probably safe but if you are using this to
set up a small business network, I would be a bit more careful. There are all kinds of
130
stories about disgruntled employees taking liberties, revenge, extended vacations with
company money, etc.
One last word: This ISN'T a substitute for a firewall or a serious security set up. If
you are setting this up on a small business network, please read some books or seek a
professional security consultant's help.
Dialup connections with Linux
Despite the increasing popularity of broadband Internet access and cable company's
ventures into the Internet business and their offering of connections, the vast majority
of people in the world, at the time of this writing, connect to the Internet via telephone
dialup through the use of a standard modem, usually at speeds ranging from 14.4 to
56 kilobits per second (kbps). The purpose of this lesson, therefore, is to discuss the
way to get a dialup connection running under Linux.
There are modems and then there are "winmodems"
Once upon a time, there were modems (which still exist) where the ability to use it to
connect to computer networks, like the Internet, was based on the configuration of the
hardware. Nevertheless, companies like Motorola, Rockwell and others developed
modems where the configuration of the device was made possible through software
more than the embedded programming on the hardware. This software was
exclusively compatible with, yes, you guessed it, Microsoft Windows. They became
known as "winmodems". Until recently it was impossible to get one of these little
jewels in the MS crown running under Linux. If you happen to have one, you could
check out Linmodems.org for more information about installing drivers for these to
run under Linux. Motorola recently released a set of drivers for their "winmodems".
The best and easiest way, however, of maintaining a dialup connection is using an
external modem or an internal modem where the hardware primarily is designed to
handle the connection. Before I had an ADSL connection, I used an external Dynalink
56 kbps modem. The setup of this modem under SuSE Linux, Red Hat, Mandrake
and Slackware was trivial. Before that I used a 38.8 kbps internal modem and a 28.8
kbps one before that, upgrading as the higher speeds became available and their
decreasing prices warranted the change.
External Modems
External modems are called that precisely because you have a little box that sits
outside your computer. These connect either via a parallel port or a serial port. A
parallel port is one that is normally used to connect a printer. A serial port is similar
in appearance to the one that is used to connect your mouse. For example, on my
workstation, where I am writing this lesson, there are two serial ports, known as
"com1" and "com2". As you can remember from our lessons on other subjects such as
hard drives and floppy drives, Linux always knows these devices by other names, files
that reside within the /dev/ directory. In our case, Linux knows com1 and com2 as
/dev/ttyS0 and /dev/ttyS1 respectively (in the computer world, we usually start counting
at zero). If you have a serial mouse, this is usually occupying com1 and therefore
/dev/ttyS0. If you then get an external modem and you want to use it, you would hook
it up to the second serial port, com2, which, as I mentioned, Linux knows as
/dev/ttyS1. The trick (really not a trick because there is no difficulty involved) is to
131
alter your Linux configuration so that it knows that you've got an external modem on
/dev/ttyS1 so it can communicate with it.
Under SuSE Linux for example, this is quite easy. As 'root' you would fire up their
configuration tool called YAST and choose the option 'System Administration' and
then the option 'Integrate Hardware into System'. At this point you're asked to choose
the hardware you want to configure and obviously you would choose 'Modem
configuration' which is the second option. You'll see the various "com" ports available
and even, with the newer version of SuSE, USB modem support. If you have a serial
mouse, be sure to choose com2 or /dev/ttyS1. You should have your modem set up
after you've done this.
If you've installed Red Hat Linux, then you should have no problem setting it up with
one of their utilities known as modemtool. If you've installed Mandrake, their tool
HardDrake should do the trick. LinuxConf is also an allpurpose tool that includes
modem configuration. I have had (and heard of) mixed results with this tool.
Now that you've got a modem connected, we'll talk about configuring your connection
with your ISP in the next part of the lesson.
Getting in touch with your ISP
There are a lot of tools out there to assist you in establishing a connection with your
ISP so you can get out there on the Internet. Most will do the job quite nicely. I have
found one in particular that is the easiest of all to use. Not surprisingly that it is called
eznet. It was written by Richard Hipp and it makes setting up your Internet connection
absolutely trivial. For Red Hat and RPM based distributions there is a RPM package
compiled by Kent Robotti and available through RPMfind.net. There is also a "tarball"
available at Ibiblio's website If you're feeling adventurous, you might want to go to Dr.
Hipp's website and download the C source code and compile it, which is another
option.
Basically, the program asks you a series of questions about your ISP, information
which this company should have given you and about where your modem is located,
(what we covered in the previous section). There is a possibility to handle several
different ISPs (at one point, I had 3 different ISPs configured). Once you've answered
the questions and you have your connection setup, connection is nothing more than
typing one command in a terminal:
eznet up 0
The program starts counting ISPs with the number 0, so that's your first ISP. Just
substitute for 1, 2 etc. for other connections you may want to set up.
Other options
If you use YAST in SuSE Linux you can set up your connection using WvDial. I must
confess that earlier versions of this program were not entirely successful in setting up
my connection. Euphemistically speaking, they couldn't do it. This program has been
greatly improved and your probability of success along with it.
If you've picked out your windows manager already and it happens to be KDE, you're
in luck because there is a program called KPPP which will set up a connection for you
fairly painlessly. The only problem I seemed to have with this was is known as the
"negotiation" of the connection with my ISP. There are two protocols known as PAP
and CHAP. If you run into this problem, it just might be a question of trying one or
132
the other and sticking with the one that works. With KPPP, you can also tune or tweak
your connection speed to get better results from your hardware.
User of Red Hat have a very powerful and simple to use graphic tool with RP3. This
is standard issue on all versions of Red Hat since 6.2
For the technically curious
As you'll notice, the program I mentioned for KDE is called KPPP. The K stands for
KDE but what does the PPP stand for? It stands for PointtoPoint Protocol. This
protocol enables two computers to connect across a network. The protocol basically
provides the means for the two computers to first, identify themselves and then ask
whether whether the computers can read the data each other sends. In your /sbin/
directory, you'll find the pointtopoint protocol daemon, or pppd which is a program
that provides for that communication between computers.
What you essentially do when you set up your Internet connection is to make sure that
pppd knows how to communicate the right information. If the two computers either
can't authenticate themselves to each other (ie realize that they have "permission" to
communicate) or the type of data their sending is incompatible or both, then the
connection fails. What eznet, kppp, RP3 and other similar programs do are to create
the necessary configuration files that pppd reads. When I first set up an Internet
connection with Linux, I created these files by hand without the help of one of these
programs. It was an interesting exercise but essentially took a long time to figure out
at those days. If you're interested in finding out what goes on behind the scenes, I
suggest you check out the page Linux DialUp Networking in a Nutshell which has a
nice list of the processes and files that come into play.
A common problem
The most common problem I have come up against is that somehow the very
important configuration file /etc/resolv.conf gets overwritten. This happens with some
Linux distributions and the reasons are numerous and I usually chalk it up to what I
called excessive "meddling" with important configuration files on the part of some
major Linux distributions. The symptom of the problem usually is that even though
you've connected to your ISP, you're not reaching pages out there. The first thing you
should do is make sure /etc/resolve.conf includes the two or more IP addresses of the
domain name servers; those machines that translate for example, www.linux.org, into
our actual numerical address. As I mentioned in the section on ADSL, it should look
something like this:
nameserver 30.30.30.30
nameserver 40.40.40.40
Your numbers will of course be different, but if you don't see at least two lines like
this: nameserver plus an IP address, then you'll have to add it again. Then you should
find out why and how your distribution is overwriting this file so it doesn't happen
again, unless, of course, you want it to. SuSE, for example, has a section in their
YAST tool where you can configure it not to overwrite certain files like resolv.conf.
That pretty much sums up setting up dialup connections. Happy surfing with Linux!
Lesson Eighteen
Getting Linux to make sounds
The hills are alive....
133
If you're like me, the first thing that interests you in setting up your computer is
making it play sounds, particularly music. When I installed Slackware so many years
ago (1997 seems like an eternity for Linux) I think I was more interested in making
my sound card work than making the modem work to get connected. Music has
always been pretty important in my life long before the World Wide Web even existed,
so that was pretty logical.
Sound Cards
When I bought my first sound card in December of 1992, it came in a big box that
Creative Labs sold me and it was a Sound Blaster. In that big box there was a bunch of
stuff software (for Windows 3.1), a CDROM drive (with an insertable cartridge
that my 2 year old just managed to break after all these years!) and some Midi gadget
which never interested me and is still in the same box in my attic. I had good luck with
that sound card (I still do because it still works). Due to this, I have always bought
Sound Blaster cards. These cards have usually configured fairly easily under Linux. I
was once bought a machine that did not have a Sound Blaster brand card in it and I
was not able to get it configured under Linux. I honestly don't remember the name of
the card and I promptly paid a little bit more money and exchanged that one for a real
Sound Blaster and quickly got it running under Linux.
Sound Blaster uses the Alsa drivers to make sound come out of your Linux machine.
These people have made my life much richer as I can listen to lovely music as I write
this lesson of the beginner's course. There are a lot of other supported cards. My
eternal gratitude to the people working on the Alsa Driver project. You might want to
have a look at their list. And see if your sound card is on their list. The nasty hardware
manufacturers who do *not* share their information (and therefore, their cards do
*not* work) are listed in red.
If you use the SoundBlaster card, you may also want to check out Creative Lab's page
Configuration tools
Before I go into the tools to use to get the sound card working, it's important to point
out that the Linux kernel needs to be configured to use a sound card. If your kernel
doesn't have a clue about what to do with a one, there is precious little tools like
sndconfig can do to help you. Luckily, every install I have done in the past year and a
half or so of a major Linux distribution has come with a kernel that has sound support
in it by default. If you're installing "Joe's Homebrew Linux" distribution (where you
must compile your own kernel), then you might be beyond this beginner's Linux
course and you probably already know how to make the kernel you want. But if you
are a true beginner (that's who this course is for) then you're probably going to get a
"made for sound" kernel. The latest versions of Red Hat, SuSE, Mandrake and Debian
that I have installed are all sound enabled from the beginning, depending on, of
course, whether or not the hardware is mainstream enough to be detected on install. I
wrote in a review of Mandrake 7.2 in the Spring of this year (2001) about how it didn't
detect my very mainstream Sound Blaster 16 card. The good thing is that Mandrake
7.2 is very much a thing of the past. They're on version 8.1 at the time of this writing
and on that same machine, I did a "clean" install (I did not update I removed 7.2 and
installed 8.0 new) and it found and configured my Sound Blaster 16 card without the
134
slightest problem. If the distribution you have installed (or are planning to install) is
uptodate, you should not have a problem.
It is also important to know what type of sound card it is in terms of the slots that it
uses on your mother board in your computer. On my machines, the motherboard (that
big thing inside a PC that you plug all the cards into) or mainboard as it is also known,
will accept ISA Plug and Play cards (bigger slots) and PCI cards (smaller slots). I'm
not a USB user, so I won't feign expertise here and give USB guidelines. If you have
an ISA PnP card (I have two) you also have to have the ISA PnP tools installed as well
as a kernel that can use ISA Plug and Play (also know as plug and pray)
As I mentioned, most major distributions will configure the sound card during the
installation process. If this is not the case, you may use to any of the following tools,
depending on your distribution.
• sndconfig I mentioned this one above. It is a tool for Red Hat and distributions
based on Red Hat (Mandrake, KRUD, for example). It is text based (runs it a
terminal) and has always done a good job for me. It will play a sound bit of
Linus Torvalds pronouncing the word "Linux"
• YAST This is SuSE's "Swiss Army Knife" of configuration tools. Their latest
version 2 is graphical. Again, there was no problem detecting my sound cards
with YAST. It plays a little melody that's also the KDE default startup sound.
You can adjust the default volume as well. It warns you not to set it too high,
just in case you're wearing headphones and you blow your eardrums out!!
• HardDrake Mandrake uses this graphical tool to configure hardware,
including sound cards. Using the GUI, you can select the sound card and then
push the button that says "launch configuration tool". I suspect that what it is
doing is launching sndconfig which, as I mentioned, is also available for
Mandrake.
• alsaconf If you're using Debian, this is the package you need to set up sound.
The alsabase package is also required.
You should now have a pretty good idea of setting up a sound card with a major Linux
distribution. Strange hardware, old versions of Linux (your cousin lent you the SuSE
5.3 disks) and obscure distributions (Zingblatter's Ultra Linux 1.4) are beyond the
scope of this course, so if you're one of those out there who pine for the sweets sounds
of Mozart flowing from your PC, you can take a look at the HOWTO's on the
subject.You can also go to your favorite search engine (mine is Google ) and enter
Linux sound card setup and you have access to the zillions of bytes of information on
the topic.
Let's go on now to all of the available programs to play all of that sound and music,
from the Beatles to Hans and his Swiss Alpine Yodelers.
Now that we have our sound card working, it's time to check out some of the options
that we have for playing sound. If you're following the course in order of the lessons,
we haven't begun to talk in depth about the use of the Xwindow system in Linux, so
the tools for playing and recording sound here will be used from the command line.
I'd also like to add an editorial comment, if I may. I use a window manager but the
programs I listen to CDs, MP3s etc. are command line applications. I am not implying
that there aren't some fine programs for playing and recording sound. There certainly
135
is some nice stuff out there. The programs I use (which we'll talk about here) are great
applications that work just as well as their graphic counterparts but in many ways are
more easily configurable, at least for me. Besides, we're talking about sound, so I just
have to set the CD or playlist and listen. I really don't have to see anything.
Recording Sound
Due to Microsoft's monopoly on operating systems (yes, they have been convicted of
this in a court of law), the most popular format for sound recording is is their *.wav
format, also known as PCM. When you make a recording of yourself or someone else
speaking or you "rip" a track from a CD for later conversion to mp3 or ogg (we'll talk
about this new and open format later), you're probably going to use the *.wav format.
If you simply want to record yourself saying something using Linux, all you need is a
microphone and and recording tool that gives you a file in this format. For this lesson,
we'll use 'wavrec'.
'wavrec' is easy to use. It's easy because the default recording settings for this
applications are all acceptable for getting a quality recording (if you've got a fairly
good microphone). You just have to type some simple commands and you're all set.
Here's an example:
Let's say I want to record a note to myself that says the following: "Note to self: make
sure you respond to Dave's email about SuSE'. I would just type the following"
wavrec dave_note.wav
make sure the microphone is on (you'd be surprised how many times I forget to turn it
on!) and start talking. The default recording time for 'wavrec' is 10 seconds. That
means, if you don't specify a recording time on the command line (I didn't) you'll get a
10 second long sound file. My sentence above, "Note to self ..... bla bla bla" lasts
about 8 seconds. Of course, the duration of the sound file depends on whether you're
talking a normal rate. If you auction cattle in Iowa, then you probably don't need 10
seconds to say that sentence, so you should modify the time for the file, like this:
wavrec t 3 dave_note.wav
The t option refers to seconds, so you should type the number of seconds after. Here,
even 3 seconds might be pushing it for a cattle auctioneer. Just remember to give
yourself enough time for what you want to say, in seconds. If you want to recite
Abraham Lincoln's Gettysburg Address, then you would first multiply 60 and 2 to get
120 seconds. Why this figure? Because Lincoln is reported to have taken only 2
minutes to give this famous speech. If you would like to record Cuban leader Fidel
Castro's speeches, then I would advise getting a huge hard drive. He once made a
speech that lasted 7 hours.
You can add all kinds of options to wavrec. I use this tool all the time to record short
sentences for use in computer assisted language learning. Here are the values I use:
wavrec S t 5 s 44100 a_sentence.wav
Let's explain these options. The first one, S, means stereo. If you look at the man
page for 'wavrec' (type: man wavrec), it says that stereo is the default. Nevertheless, I
have noticed that mono is in fact the default. That is to say, if you use 'wavrec' with no
options, you get mono not stereo sound. It would seem there is an error in the man
page. After the S, we have the t option for seconds (we explained before) then we
have the s option which is the sampling rate in Hz. I chose 44100 because this is a
136
good highquality sound which is necessary for my language teaching endeavors. It's
important not to confuse the S (capital letter) with the s (lower case). s takes a value
in Hz while S has no value. I have purposely put the t option in between them to
avoid confusion. There you have it. Issuing this short command and then changing the
file name, I get a lot of work done because my sentences seldom last more than 5
seconds and these values are fine for my work.
Now, you must be asking the question: "I've made a *.wav file, now, how do I hear it?"
The answer is easy: With 'wavrec' 's companion program, 'wavplay'. Here's how:
wavplay a_sentence.wav
This will play the sentence we recorded above. That's all there is to it. I should also
point out that the same options in 'wavrec' are available for 'wavplay' if you want to
add some effects to playback. For example, if you take our first wav file,
dave_notes.wav, and play it like this:
wavplay s 44100 dave_notes.wav
you'll find it's doubly fast. That's because our note about Dave was recorded at the
default 22050 hz, so if you do the math, you see that what we've done is double it's
sample rate . You might want to do this:
wavplay my_favorite_song.wav
then sing a line of your favorite song. Play it back to your friends using the s 44100
option and have them rolling on the floor with your Alvin and the Chipmunks
impressions. I have actually entertained my 2 year old son for hours with this.
Using the same logic, if you take our a_sentence.wav and play it like this:
wavplay s 22050 a_sentence.wav
you've cut the sample rate in half and so you get a really cool impression of the
creatures that take over people's bodies in Star Trek's original series episode 'The
Lights of Zetar'.
I know what you're probably thinking. I need to be productive. I don't want to record
Chipmunk sounds and scifi weirdness. Well, then. Here's a good way to use these
tools, plus a couple of other command line tools to read reminders to yourself in the
morning, or whenever you'd like. First, create a subdirectory in your own directory
/home/[you]/
mkdir reminders
then go into reminders (type: cd reminders). Now, Let's create a sort of introductory
wav file that's always going to be there. I'll explain why we need that in a bit.
wavrec t 3 0intro.wav
Say something like "Your reminders" or "Reminders for you". Three seconds should
be enough for that. You may have noticed that the name begins with zero. That is
simple because for our reminder system, we invoke 'wavplay *' with the asterisk to
play every file in that directory. By naming it '0intro.wav', that assures that it will be
played first with our system.
Now record some reminders. I recommend using a YEARMONTHDAY format plus
some meaningful word for naming the wav files. For example, type:
wavrec t 5 20011024_trash.wav
and say: "Remember to take out the trash". I suppose 5 seconds should be enough to
say this. Try recording a few more reminders for different things, like "call cousin
137
Jack" and "remember to pay back gambling debts to bookie". When you've got a few
wav files in there you should play them to see that they've come out all right (you
don't need to do this every time we're just practicing)
wavplay *
You'll see that the 0intro.wav file gets played first. If everything sounds good to you,
then we're ready for the next step which is to play our files automatically at a given
hour.
One of my favorite applications in Linux is called 'cron'. This is a pretty powerful tool
that is used primarily by system administrators to automate their tasks and duties. It's
powerful because it can schedule something to be run automatically at any time,
whether that be once every three minutes, every hour, once a day or every Thursday. It
can even be used to run a job that you do only in January. But just because it's
powerful, it doesn't mean it's complicated to use. For our purposes, it's very simple to
configure 'cron' to play our reminders. First, we have to edit a file that is called
'crontab' and add our instructions. There is a systemwide crontab file for root's
exclusive use, but there is also one available to every user to run command line apps
that he or she is authorized to use. To add a job to be done, just type:
crontab e
Then we add the following line to our crontab file (e is for edit)
30 7 * * * /usr/X11R6/bin/wavplay $HOME/reminders/*.wav
The crontab edit procedure uses your default command line editor which is probably
'vi', so if you don't remember our little tour of 'vi', just press 'ESC + i' before you add
this line.
Let's explain how a crontab file works. The file is read by the program 'cron' and it
carries out the instructions in it. In our example, our wav files get played at the 30th
minute of the 7th hour, that is to say 7:30 in the morning. This is because the crontab
file must start with the minute [059] you want something done, followed by the hour
[023] the day of the month [131], the month of the year [112] and the day of the
week [07] (where 0 and 7 are both Sunday). I have left the last three as asterisk. This
tells 'cron' that these values don't matter. That is to say, cron should play our *.wav
files every day of the month, every month of the year, 7 days a week.
The next step as you can see is to tell cron to run 'wavplay' and play the files in your
home directory. We use the symbol $HOME for that. Also notice how I have put the
exact path to where wavplay is. To see if your system differs, then type:
which wavplay
to show you where the program is. Then adjust accordingly. I used this exact path
because, it would seem on my system, the master crontab file (found in /etc/crontab )
doesn't recognize that path automatically. I am assuming that this is for security
reasons, so I didn't go in and change the path. Some things are probably best left
alone, so no harm done if you just put in the exact path in the crontab file.
If you want to test it, just give it a time within a couple of minutes or so. That is, if it's
3:30 in the afternoon, you might want to first edit your crontab like this:
32 15 * * * /usr/X11R6/bin/wavplay $HOME/reminders/*.wav
that will play the reminders at 3:32 PM, to show you that it works. Just make sure
you're not playing anything else, like MP3s, because you won't hear them. That's the
138
rationale for my 7:30 AM start time. It's a good hour for me when I am just getting to
work and I'm probably not listening to heavy metal at that hour of the morning.
Actually, I never listen to heavy metal.
Now, when you've finished hearing them, you can delete them (if you want) That's
where the rationale behind the YEARMONTHDAY.wav comes in. You just delete
the daily ones by typing, for example rm 20010928*
That keeps the 0intro.wav file in there. I mentioned before that I was going to explain
why it's necessary to have it there. 'Cron' will mail you when there is an error, so if
you had no reminders for a given day, you would at least have one file in the
/reminders directory. That way, 'cron' doesn't have to mail you an error message
because the program 'wavplay' didn't find any *.wav files.
By deleting the unnecessary reminders, you've got some free disk space. Speaking of
that, if free disk space is something that worries you, in the next part of the lesson
we'll talk about those famous (and controversial) files that take up less space MP3s
and how to make them under Linux. We'll also talk about the new free audio format
comparable in sound and space to MP3 Ogg Vorbis.
MP3 format
If you've touched a computer in the last couple of years you've at least heard about the
MPEG layer 3 format, popularly known as MP3. You have probably listened to an
MP3 and you may have even "ripped a track", that is, made an MP3 file from a song
on a CD.
MP3 has become somewhat controversial. In light of the Napster case, sharing MP3
files has opened up a Pandora's Box of questions about copyright, fair use and
intellectual property. This really isn't the place to debate those questions but there are
some issues related to the making of MP3s that concern Linux, Open Source and Free
Software in particular.
We'll talk about the programs available to make sound files in MP3 format, but I
should point out that MP3 is a nonfree format. That is to say, the Fraunhofer Institute
and Thomson Multimedia developed MPEG Layer 3 technology and they hold the
patent rights it. If you want to write programs that encode and/or decode MP3 format,
you have to pay licensing fees. Thomson has set up a website to talk about these
issues, if you're interested. What does this mean for Linux? Well, if you are an
advocate of the Open Source and/or Free Software model that Linux grew out of, MP3
might be seen as a format to be avoided. Actually, if you think this way, you now have
an alternative with Vorbis' *.ogg format. We'll talk about that shortly. But being that
MP3 is so prevalent nowadays and encoders/decoders do exist for Linux, we'll talk
about making and playing MP3 files.
Let's go back to our "reminder" system. If you go into the /reminders directory we
created (cd reminders) and type:
ls l *.wav
you'll see that the default quality of a 5 second recording gives us a file of about 1/4
megabyte. If we made the file a little better, as I do when I'm working with sample
sentence for language learning, you doubled the file size to just under half a megabyte
each. To check this, I made one of each format:
rwrr 1 mike users 132344 Nov 27 12:11 0intro.wav
139
rwrr 1 mike users 220544 Nov 28 08:37 20011128_fair.wav
rwrr 1 mike users 441044 Nov 28 08:34 20011128_good.wav
If for some reason you wanted to keep these reminders, files of this size would quickly
begin to take up space. Disk space is cheap, but there's no reason to occupy space if
we can compress it. We could take out our tools gzip or bzip2 that we learned about in
a previous lesson. 'bzip2' will actually get the file down to about half its original size:
rwrr 1 mike users 206442 Nov 28 08:34 20011128_good.wav.bz2
But there is a much better way of doing this, for now, by converting it to MP3 format.
Look what we get for the same file as an MP3:
rwrr 1 mike users 80234 Nov 28 08:48 20011128_good.mp3
You've got it down to about one fifth of its size. And you can hear it right away with
an MP3 decoder/player. Let's show how we did this.
First of all, you need a program that converts *.wav files to MP3 format. There are a
few of these available for Linux. One of these, and probably the most popular, is Tord
Jansson's BladeEnc. He's had some trouble with the MP3 patent holders so, again,
we've stepped into controversy here. How do we avoid bringing patent holders' wrath
down upon ourselves? Well, by going over to Fraunhofer's website and getting a demo
of their MP3 encoder, appropriately called 'mp3enc' (the demo is actually called
'mp3encdemo' very logical) we can convert these files in MP3 format. That will at
least give us an idea about how all this works in Linux.
You'll get a *.tgz (Slackware package) compressed file. Just unzip and untar in your
home directory:
tar zxvpf mp3encdemo.tgz (or whatever the current file is called)
There is a precompiled binary (aka program that works right away) and some
documentation (manual, other README files). There is a section in the manual that
says "For the impatient". Being impatient by nature, I went right to that and found out
how to convert my *.wav files to acceptable quality MP3s. Now, we're lucky that our
reminders aren't very long, because the generous Fraunhofer people have given us a
demo that only encodes 30 second long files. I know what you were thinking. You
were going to run next door and borrow the neighbor's "Greatest Punk Love Songs"
and start rippin'. We'll you're out of luck unless you want to do a medley. At any rate,
the Fraunhofer demo will do nicely for learning purposes. To use the program, just
pick one of the reminders and type:
mp3encdemo br 128000 if 2001[whatever].wav of 2001[whatever].mp3
where [whatever] is the date of your reminder. Let's look at these options. br stands
for bitrate This is 128 kilobits per second and you'll get an acceptable, almost CD
quality file. if stands for "if it works" naah that's only a joke. (I couldn't resist). if
means input file, that is, the file your inputing or feeding to the encoder. Logically
then, of means output file, the MP3 file you're going to get. There you have it. Feel
free to encode any files you want. (as long as their under thirty seconds, of course)
Actually any MP3 encoder for Linux that you can find out there works in basically the
same way. You input a *.wav file with some options and you get an MP3 file. The
program BladeEnc that we mentioned before, behaves similarly and there is no 30
second limit. (wink, wink, nudge nudge, and the author begins to whistle nervously)
Playing MP3 files
140
OK. Now we have our MP3 file. That begs the question: How can I hear it? Well, we
need an MP3 decoder and/or player. I say "and/or" because these could be two
different things under the xwindow system. Popular graphic MP3 players are actually
frontends for MP3 decoders. That means they provide a graphic control panel for
using a program that you don't really see. That's why I usually use the command line
programs, as I mentioned earlier. So let's save some CPU power and learn how things
work in the process.
'mpg123' is a very popular command line program for playing MP3 files. It is also
highly versatile. You can create playlists and play songs in alphabetical order or in
random order. You can even play little tricks and create weird disco versions of songs.
(no kidding) You can even "reverse engineer" the MP3 file or even parts of it back to
*.wav format. As far as I have tried, most graphic programs can manipulate playlists
and add an echo effect but can't take full advantage of mpg123's features. You can
only do it on the command line.
Anyway, 'mpg123' comes with most major distributions. If you visit mpg123's home
page you can find out all about it. You can also get source code and RPMs if you don't
have it installed already.
To simply play an MP3 file, enter the directory where the files are and type:
mpg123 your_mp3_file.mp3
Let's say you already have a lot of MP3s. You may have gotten some ... then again, I
don't want to know where you got them. You could random play them
mpg123 z *.mp3
One of my favorite things to do is to create a playlist. Here's how I do it. This will be
good review practice for the command line as well.
First, I enter a directory where I have MP3s:
cd classical
Then I see what songs I have:
ls *.mp3
Then I pick out some songs that I particularly like and make a file that is going to be
my playlist:
ls 1 Mozart_nightmusic.mp3 > favorites
The command 'ls' with the option '1' lists the file name without any other
information. The > symbol as you remember from our lesson on pipes, etc. creates a
file called 'favorites' and includes the 'ls 1' output in it. To add more songs, we would
repeat the same command, but this time we would (obviously) change the MP3 file
name and most importantly we would change the one > symbol to two >> symbols.
This way, we just add to the playlist file and we don't overwrite the file as would be
the case if we didn't use two >> symbols.
ls 1 Beethoven_fur_elise.mp3 >> favorites
So I'd just keep adding songs until I had a nice playlist. To see the list, you'd just type:
less favorites
If everything is satisfactory, then we can play these songs. Just type:
mpg123 @ favorites
141
The email (@) symbol tells mpg123 to look for the playlist. That would play the songs
in the order they are on the list. If you want to play them in random order, you would
just add a z before the @ option
More fun with mpg123
Let's say you wanted to play "Name That Tune". Don't laugh! I have done this at
parties. You know, you only play so much of a song and the people have to guess
which one it is. Well, with mpg123, you're all set. This command will only play the
first 50 "frames" of a song:
mpg123 k 0 n 50 Mozart_nightmusic.mp3
And you'll have the liveliest parties on your block! All courtesy of Linux and mpg123!
Seriously, the k option tells the program which frame to start at and then n option
indicates where it should stop. Pretty easy!
You want more party ideas? Well, how about doing TechnoMozart? That's easy too.
Just type:
mpg123 d 2 Mozart_nightmusic.mp3
This will make the program skip over every 2nd frame. That is, it will play a frame
and skip one. This is *not* the Chipmunk effect. You will hear the same tone of voice
because this doesn't effect the sampling rate of the file. It will just sound "techno" as I
pointed out. Even though I mentioned parties and that, I have used this program and
this effect in my language work for purposes of "serious" study. As the rate of the
voice is not altered, you can change the number and see at what point people can't
understand something. By this, you can test the aural skills of a person learning a
language. By the way, you can also do the opposite by changing the d X option to h
X. Instead of skipping frames, mpg123 will play the same frame X number of times.
Remember, these options do not produce the "slowmo" or "Chipmunk" effects. It just
slows down the speed of playback.
As we mentioned before, you can also "reverse engineer" the MP3 file back to a *.wav
format. Remember, before you try this at home, the *.wav format is at least 5 times
bigger, so make sure you've got plenty of hard disk space.
mpg123 w Mozart_nightmusic.wav Mozart_nightmusic.mp3
You can also use the different options like d or h combined with the k and n to
produce weird *.wav sound effects files. Your imagination is the limit. If you do want
to do technomultimedia things with mpg123, you can use the v option to get
complete information about the track your playing.
Well, after all that is said and done about MP3, I must confess that I don't like working
with MP3s as much as I like working with the new, free (as in beer and source code)
Ogg Vorbis format.
Ogg format
Due to the restrictions on the use of MP3 technology, Ogg Vorbis is a good way to
enjoy digital music in a compressed format. Though it is associated more with the
Linux and Open Source world, both Windows and Macintosh ports of the Ogg
libraries are also available. This is proof of its growing popularity as a digital music
format. There are even companies now using Ogg format for sound in their games.
You can read the latest news on the status of the Ogg Vorbis project at their website.
Installation of the Ogg libraries
142
First, in order to listen to and make files in Ogg Vorbis format, you should to go over
to the Ogg Vorbis website and download some packages that are needed: libao, libogg
and libvorbis These are the actual libraries that do the compression and
decompression of the sound. The command line software for coding and playing the
*.ogg files can be found in there as well, in a package called VorbisTools. Included in
this last package are the programs oggenc and ogg123. These are designed to work in
the same way as the packages bladeenc and mpg123 in the MP3 world. Their
command line options are essentially the same.
Before you actually visit the site and start downloading, if you have bought a boxed
set of a major Linux distribution recently, you should have these libraries included on
the CDs and be able to install this painlessly with your distribution's installation tools.
If you got your CDs from your cousin Larry with "Redhat" written on them in magic
marker, then feel free to go over and download the RPMs at www.vorbis.com and
install them, as you remember from our lesson on RPMs.
rpm i libao[whatever's current].i386.rpm
rpm i libogg[whatever's current].i386.rpm
rpm i libvorbis[whatever's current].i386.rpm
rpm i vorbistools[whatever's current].i386.rpm
Note: Don't get the source RPMs (the one with 'src' in the title). You won't need those
if you're running Red Hat or any RPM based distribution (like Mandrake, KRUD etc.).
Also, install in the order I have given you above and do this as the 'root' user
If you've got some other distribution like Slackware that works better with tarballs
than RPMs (or if you are feeling adventurous/masochistic, then get the files ending
with *.tar.gz (the tarballs). Unzip and untar them and read the readme and/or install
files which will instruct you how to get those packages installed and working. I took
this from libogg's own README file:
./configure
make
and optionally (as root):
make install
I guess you get the idea. Now let's see what we can do with these libraries and
programs to get some nice sounding *.ogg files.
My nostalgia project with Ogg Vorbis
To try out the capabilities of Ogg Vorbis and the capabilities of Linux in general for
manipulating sound I decided to convert to *.ogg format some old analog audio
recordings that I had of a "garage" band I was in during the late 70's and early 80's.
These were produced before the first CDs ever appeared on the planet using 8 track
reel to reel equipment in my best friend's basement. Various cassettes were made of
the original recordings and I wanted to preserve them digitally. It also gave me the
opportunity to outline the procedure to use as a tutorial and to cowardly stay outside
the realm of copyright infringement issues. There are, I am sure, people using Linux
who grew up in a time when the letters CD only meant "certificate of deposit" and
who listened to vinyl records and audio cassette tapes. Some might have even listened
to 8 track tapes and are afraid to admit it. If you have stereo equipment that has a
143
turntable and/or audio cassette player with lineout plugs, this tutorial may also be
applied to the possibility of making copies of records and tapes for yourself, which the
law allows, if you own them.
How to digitally enshrine your past delusions of grandeur
Needed:
• One unsuccessful garage band of the 70's
• A cassette of music of rock star wannabes
• Audio cassette player with lineout plugs
• Cables to connect the player to your sound card
• optional Medical insurance (in case you get ill listening to the music)
All sound cards have inputs for your speakers/headphones, a microphone and a linein
cable (that is, the lineout from stereo equipment). Their function is either color coded
(speakers are usually green, microphone red and linein blue) or written on the metal
bracket of the sound card. Plug the lineout of the cassette player into the linein input
on the sound card. Usually, the microphone is the default source for recording. You
may have to fire up the Alsa mixer and change this. Type:
alsamixer
then, using the arrow keys, make your way over to the linein column and push the
space bar. That should activate your line in as the recording source. It should look like
this:
You can also adjust the sound with the up arrow.
Somewhat tarnished bronze oldies
Now, I put my cassette in the player and I was ready to go. I planned on using the
wavrec program I mentioned earlier in this lesson to convert the analog tape audio to
*.wav files, but I discovered a slight problem. I didn't know the length of time the
songs took to play. Being your basically lazy system administrator type, I decided to
try a little trick. I figured that none of them could probably last longer than 5 minutes,
so I typed the following:
wavrec S t 300 s 44100 stairway_to_the_basement.wav
That meant that wavrec would continue to record for 300 seconds (ie 5 minutes). You
can change that for however many seconds that you like. I sure you remember the rest
of the options from earlier parts of the lesson.
144
My plan consisted in pushing CRL + C when the song came to an end. At first, I was
afraid that would corrupt the data but when I tried it, it worked. The first trial run
sounded fine using wavplay. So I just continued doing this:
wavrec S t 300 s 44100 smoke_on_the_wafer.wav
and pushing CRL + C at the end. Soon I had all my songs converted to *.wav files.
Then came the time to convert them to *.ogg format.
Working with Oggenc
Then I used oggenc to get them this format. Here's an example with one song:
oggenc b 192 a "Grage_Band" l "Demo Tapes" t
"no_sympathy_for_the_neighbors"
no_sympathy_for_the_neighbors.wav n "%a_%t.ogg"
Let's explain some of the options.
• b stands for bitrate. Anything above 128 will give you good quality. I chose
192 here because this is fairly good quality without being excessively big.
• After the a option you should put the artist (I use the term loosely in my case)
in quotes.
• The l option is for the name of the album. We never made an album, so I just
put "demo tapes" as you can see.
• t stands for track or the name of the song.
• Now, type the name of the song whatever.wav
• n followed by "%a_%t.ogg" tells the program to name the Ogg file for the
artist(%a) and the track (%t).
You've noticed that I have put underscores_between_words in true Unix filename
fashion. That's a good idea. (Demo Tape excepted that's not going into the file name)
That should create some files in Ogg format for you. One word of caution. Both MP3
and Ogg encoding is very CPU intensive. Make sure you're not doing anything that
needs a lot of CPU cycles at the same time. If you're interested in seeing just how
CPU intensive this is, just run the command: top and that will give you an idea.
Once again, if you've got some old tapes or old records and you want to make copies
for yourself, here's a way to do it. There is software available to take the scratchy
sounds from *.wav files made from LPs. There is good explanation of the process at
uklinux.net.
Well, enjoy all those old cassettes and LPs and if you were once a neighborhood Rock
and Roller, then try out the Ogg Vorbis tools and take a trip down memory lane.
Compact Disks
I love the scene in the Adam Sandler movie The Wedding Singer where the Yuppie
junk bond trader Glenn Gulia, brings on of the first CD players home to his fianceé
Julia, played by Drew Barrymore. Gulia exclaims: "It's a CD player it cost 800 bucks,
but the sound quality is excellent!" I remember those days in 1980's when I heard my
first CD and was amazed no scratches no hiss. The CD, as promised, ousted the LP
record forever. Not soon after the release of CDs and CD players, records disappeared
from all but collector's shops. Luckily, CD players didn't stay around 800 US dollars
for long.
145
Soon software companies realized the potential for data storage in these little plastic
disks and the CDROM market was born. From about 1992 on the use of CDs in
computers increased exponentially. Now, almost 10 years later, we're not only talking
about reading CDs but writing to them with CDRW drives that cost under 200 US
dollars. A spinoff of the CD, the DVD (Digital Video Disk) is becoming more and
more popular everyday. Soon we will have affordable drives for home use that write to
these disks as well.
Linux has never been behind in supporting these types of media, so we'll show you
some of the utilities out there for playing and ripping tracks from CDs.
Playing CDs
As I pointed out earlier in the lesson on sound, I like to use command line programs to
play CDs. My favorite one and I think the one that's easiest to manage is tcd by Tim
Gerla
You can control which tracks to play, adjust the volume, eject the CD and do other
things all from the keyboard. You can use 'tcd' to keep a database of your CDs for easy
playing. Under Xwindow, you can fire up this baby in an xterm and enjoy hours of
listening pleasure.
GUI based CD players are plentiful as well, and when you've installed and configured
your Xwindow system, you can try out those as well.
Ripping CD tracks
The whole Napster phenomenon, as I pointed out at the beginning of this article, made
the practice of converting songs on CDs "ripping as it is also called" very popular.
Here we're going to talk about one of the most widely used programs in the Linux
world. The official position of this author is that ripping tracks from one's own CDs
for personal use is OK by me (and the law, it would seem). For example, ripping your
favorite songs and converting them to Ogg format to make it comfortable to play your
favorite songs from your desktop doesn't entail you venturing into legal gray zones. If
you shared them however, that's a different story. So, if you're interested in ripping
tracks from CDs, the Linux program par excelence for doing that is cdparanoia .
cdparanoia is billed as a ripping tool for CDdrives that could be problematic. It
seems to work fairly well on the variety of speed drives that I have tried except for a
146
couple of ancient ones. It's available for download from the same people who bring
you Ogg Vorbis. Here's how it works:
Let's say you wanted to rip track (song) 6 from a CD. You would place the CD in the
drive (I have forgotten that on occasion duh) and type:
cdparanoia "6"
The output would look something like this:
cdparanoia III release 9.8 (March 23, 2001)
(C) 2001 Monty and Xiphophorus
Report bugs to paranoia@xiph.org
http://www.xiph.org/paranoia/
Ripping from sector 48423 (track 6 [0:00.00])
to sector 58677 (track 6 [2:16.54])
outputting to cdda.wav
(== PROGRESS == [ > | 050085 00 ] == :) . ==)
So now you have track 6, called 'cdda.wav' (cdda stands for Compact Disk Digital
Audio, by the way) ready to be converted into your favorite compressed format, like
Ogg. Here's a refresher. To convert your ripped track to Ogg, type this: (change it to
your info)
oggenc b 192 a "The_Rubber_Band" l "Gummed Up" t "shes_elastic" cdda.wav n
"%a_%t.ogg"
Now you have a nice Ogg file that you can play with ogg123
Other options for ripping tracks with cdparanoia include:
cdparanoia B
This will rip the whole CD into separate tracks, named track01.cdda.wav, track02.cdda.wav,
track03.cdda.wav etc.
cdparanoia cdparanoia B "5"
This will rip tracks up to and including track 5 into separate *.wav files. If you want
one big file, just eliminate the B option. Do not forget to type the double hyphens
before track numbers. Just to finish off, here's an interesting combination:
cdparanoia "4[:45]4[2:15]"
The above example will rip track 4 starting at 45 seconds and end at 2 minutes 15
seconds into the same track. Why would you want to do this? A number of reasons
you only like the awesome lead guitar part of a song? That could be. Anyway, the
manual page (type: man cdparanoia) is a particularly wellexplained one, so if you
want more examples, there's a good source of information there.
Well, that concludes our lesson on sound. You should be able to listen to, create and
manipulate sound with Linux.
Lesson Nineteen
Graphic User Interfaces with Linux
147
Some preliminary commentary and perspective
As much as I like Linux and think that it is the best operating system out there today,
most people who use computers equate Microsoft with computing. In particular, the
only computing environment that most PC users have ever seen comes in the
successive versions of their flagship operating system Windows(tm). However,
computer scientists and people who have an interest in computers beyond the mere
enduser stage know that graphic user interfaces or desktop environments like
Windows really represent the look and feel of the computer experience, but not the
experience itself. Windows has become famous for essentially blurring the reality of
what a computer really does. That is to say that Microsoft Windows, especially since
the release of Windows 95, has masked any trace of the traditional "black" computer
screen experience. It was still there you just couldn't see it unless you purposely
looked for it.
Bill Gates, chairman of the Microsoft Corporation once stated that: "Linux is 1960's
technology with a new development model". What does he mean by this? I think
basically that he bet his whole company on the assumption that people didn't want to
see the traditional black screen and the command prompt anymore. The sales of
Windows 95 proved that with a good marketing campaign he was able to sell the idea
that people didn't want it and people responded. Then Linux started to gain in
popularity and be noticed by a certain segment of the public around 199899. The
problem was that Linux offered the black screen and the graphic user interface as a
separate package. Bill Gates had already established that this was a nono and so
Linux gets chalked up as "retrograde".
Now it's 2002 and Linux still offers the black screen and graphic user interface
separately. But then again, a lot has happened since 1998. For one, IBM has spent 1
billion US dollars on Linux and essentially gotten its investment back. Linux's market
share continues to rise. It still pales in comparison with Microsoft's desktop popularity
so much so that as most everyone knows, Microsoft was convicted of being a
monopoly in restraint of trade. Then again, in 2000 and 2001 successive email viruses
and worms crippled Windowsbased IT departments and brought scores of corporate
networks to a grinding halt. Why? Because we're in a new world of connectivity. Bill
Gates' comment about Linux may be turned back now upon his own company. If you
asked your average Linux enthusiast what he or she thinks of Windows, you might get
this reply: "Windows is preInternet technology with a slick new marketing
campaign". Microsoft spends most of its days now fighting security brush fires
because in blurring the difference between the operating system and the graphic user
interface it sacrificed security for ease of use. Windows development model was
conceived before everybody's computers where connected to each other and it
continues to reflect that. Linux, however, was born on the Internet and grew up with
it. Unfortunately, more complaints about Linux's perceived lack of user friendliness
outnumber complaints about Windows being essentially a Maginot Line solution for
secure computing. Hopefully in this lesson on graphic user interfaces under Linux,
you'll get a good idea how the balance between user friendliness and security is a good
one with our favorite OS.
The GUI family tree
148
Without getting into a lot of technical jargon, in order for those nice windows (yes,
with a small 'w') to appear on your computer screen, you have to have some graphics
libraries installed on your computer. These libraries determine how a window is to
appear, what it is supposed to look like and what the buttons and menus are supposed
to do. That fact that you can use GUI based computing under Linux goes back to the
time before Linux was even thought of. In the mideighties at the Massachusetts
Institute of Technology they came up with the X window system. By 2002 standards it
was a primitive GUI system to run programs with. The main idea behind this actually
came from an earlier project at Xerox called WIMP (Windows, Icons, Menus,
Pointer), a project that essentially started the idea that computers could be used in an
attractive graphical environment. 1
The 'X Window system' provided the libraries to make the frames, buttons and menus
that make up a window. Development of X Window still continues under the auspices
of the X Consortium. In 1992 the XFree86 Project was started. This aimed to develop
a free version of the X Window System. There have been several versions of XFree86
and the current stable version at the time of this writing is XFree86 4.0. Though there
are other equivalents to the libraries that XFree86 offers, it is by far the most widely
used window system under Linux. Any attempt at using Linux as a desktop operating
system to get "productive" work done (word processing, spread sheets) or to entertain
oneself (play games, listen to music, watch TV) will start with the installation of
XFree86.
With major distributions, the install process takes care of getting XFree86 on to your
system. There are two parts to this. One is installing XFree86 itself. The other is
installing the X server that goes with your particular hardware. The X server is just
the means of getting XFree86 to work with the graphics card that you have in your
computer. For example, if you have a graphics card from ATI, then you would install
the XFree packages along with the X server package for ATI. If you have an S3 card,
then XFree86 and the X server for S3 cards should get installed. I explain this because
some distributions do a pretty fine job of getting you up and running, but you may get
asked what graphics card you have when you do a more interactive type of install of
Linux. In this case, you have to know what card you have so the correct X server gets
installed and you can have a graphical environment to look at after the install process
is finished.
Recently, major Linux distributions will also offer you the possibility of getting right
into the GUI when you turn on your computer. This is done by way of the program
XDM. This is the Microsoft Windows influence on how things are done that I
mentioned before. Traditionally in Linux, you would turn on your computer and get
the black screen and the command prompt. Then you would type:
startx
and your graphical environment of choice comes up. 'Choice' is the key word here. By
having the command prompt and then issuing a command to start the GUI, you can
switch into any number of desktop environments "on the fly". Of course, if you're not
interested in having more than one, then you can use XDM and have your favorite
desktop there waiting for you.
149
Regardless of the way you choose to start up your machine, before you see your your
desktop utilities of choice, we're going to have configure XFree86 to use your
monitor, mouse and keyboard. That is, whether you type startx or not, we'll have to
come up with a come up with a configuration so we can, in fact start X.
1
The X Window User HOWTO by Ray Brigleb, 1999
XWindow configuration
In Linux days of yore, it used to be quite a task to get XWindow running even on a
standard Intel type PC. Now all of the major distributions have their own tools to get
X running in no time.
SuSE offers a program called Sax. This is about the most userfriendly program I have
yet encountered for X setup. It is graphical, so the simple fact that you can run it
before you've even start configuring X is a good sign.
Mandrake offers their X configuration right in the install package so you go from start
to finish all in the same package.
However, given a situation where your X setup doesn't go smoothly, you can do this
this step by step, in text mode, with a program called xf86config. This is a last resort
and will almost always get you good results.
This program asks you questions about your peripheral hardware, like your keyboard,
mouse and monitor. Here are a couple of examples of what it looks like:
The most important questions that this program will ask you about your hardware are
the ones about your monitor. I don't mean to imply that the others are not important.
For example, if you don't answer the type of questions about your mouse correctly,
your mouse won't work. Or if you don't enter the country/language values for your
150
keyboard layout, you may not be able to use letters or symbols that exist in your native
language. That is obviously important. However, if you don't enter the values correctly
for the type of monitor you have, your monitor can get seriously damaged. If you
enter the vertical and horizontal refresh rates incorrectly, your monitor will become
just another useless piece of plastic and glass, like so many others waiting to be
thrown away or recycled. It's beyond the scope of this lesson to explain what the
vertical and horizontal refresh rates mean (actually, it's the horizontal one that's a real
stickler) but trust me you need to go get the manuals for your monitor and enter the
real values when it asks you. If you don't believe me, this is what xf86config says
It is VERY IMPORTANT that you do not specify a monitor type with a horizontal sync range that is
beyond the capabilities of your monitor. If in doubt, choose a conservative setting.
At this point in the configuration, you can choose option 11 and enter your own values
from the monitor's manuals and you'll be sure to get the correct settings.
Once you have passed this point, the questions are more straight forward and errors
have less grave consequences.
In the past years, as I mentioned, major Linux distributions have streamlined this
process so you probably won't even need xf86config. But it's nice to know you have it
there, especially if your hardware is proving to be less than cooperative.
To boot or not to boot (in graphics mode), that is the question.
Before start talking about the different windows managers and desktop environments
that are available for Linux, let's first see how our barebones XWindow setup is
working. Some X programs don't need a windows manager to run, so let's try a simple
experiment with one of them. Type this in your terminal window:
xinit /usr/X11R6/bin/xedit
This will fire up a simple text editor called 'xedit'. You can try writing something and
pushing the buttons. When you push 'quit', you'll notice you go back to your standard
terminal. Try the same with an xterminal:
xinit /usr/X11R6/bin/xterm
Type in a few commands. Then type 'exit'. Your xterm session ends and your back in
your terminal.
There isn't any practical reason to use XWindow in this way. It's better to use its
powerful capabilities with a fullfeatured windows manager and desktop environment.
Before we go on to talk about choosing a windows manager that suits you, we should
talk about how you want your computer to boot. Do you want it to go directly to a
graphical environment or do you want your machine to boot into text mode where you
would then issue the 'startx' command? If you want graphics mode right away, then
you need to have a program like xdm, which will start your windows manager of
choice, or 'kdm' or 'gdm' which will start KDE or GNOME, two desktop environments
that we'll talk about a little later.
The decision to startup graphically is made when you first install Linux. If you found
that you've changed your mind; that is, you now want to startup graphically or vice
versa, you can usually change this with your distribution's tools.
You can change the startup behavior by going to your /etc/ directory and changing a
file. The file name will depend on your distribution. With SuSE, for example, it is the
file called rc.config. You should change the line:
151
DISPLAYMANAGER=""
to:
DISPLAYMANAGER="xdm"
You may also use 'kdm' or 'gdm' here. Make sure that your CHECK_INITTAB setting
is "yes"
In the case of RedHat and RedHat based distributions (Mandrake, KRUD), you'll need
to change the file /etc/inittab. In the line: id:3:initdefault:, the number 3 needs to be
changed to a 5
As I mentioned, if you want to do just the opposite, change the default graphical login
to a text mode login (something which I recommend), just reverse all those changes
above. If you decided not to use a graphical login, you may want to uninstall 'xdm' (or
gdm/kdm).
Well, now that we're clear on whether to use a graphical startup or not, let's explore
some of the possibilities for your Linux desktop.
Choosing the look that's right for you
In recent years, as Linux has become more popular, members of Linux community
have tried hard to shake off the reputation, which I feel has always been unwarranted,
that the graphical user interface for Linux is at best, boring and at worst,
unmanageable. This is based on, of course, comparisons with the user friendliness of
the omnipresent MS Windows and the welldeserved good reputation of the
Macintosh OSes. After using Windows 95 from 1995 until the end of 1997 and testing
various Mac OSes extensively (at one point using Mac OS 8 exclusively for one
month I was staying with relatives and needed to get some work done), I can safely
say that Linux doesn't and probably hasn't had a reason to envy the other two major
OS offerings in terms of graphic interfaces since about 1998. Graphic user interfaces
under Linux are comparable with these other ones in just about everything and even
enjoy some advantages. The major one over MS Windows is, of course, stability and
security. The advantage over Macintosh is primarily cost related.
If you're reading this, then you've probably made the decision to try Linux. Before we
talk about what your Linux desktop is going to look like, we should first talk about the
difference between a window manager and a desktop environment.
Window managers
Most programs made for computers nowadays run in a graphic environment. However,
it became apparent that these programs would be more efficient if they could take
their attributes from a common source. This is what a window manager does. It
decides how the window is going to look, the aspect of its buttons and frames. It
determines how it is going to reacted when you click in it or you reduce it or resize it.
There are more two dozen different window managers available for Linux. The more
popular ones make their way onto Linux distributions. They range from completely
minimalist to wellengineered works of art. Here is a list of the ones that generally
find their way onto the major distributions' CDs.
• the fvwm family
• Blackbox
• IceWM
• Sawfish
152
• Enlightenment
•
WindowMaker
•
AfterStep
You can check out the above sites and find one that you like. The first one, FVWM, is
my personal favorite. It is also the most minimalist of the one's I've listed here. This is,
as far as I know, the oldest of the aforementioned as well. This is not meant to be an
endorsement of this window manager. I just happen to like its minimalist approach
and low memory requirements. I'd rather pass that RAM savings on to the really
important applications running on my computer.
I have provided a screenshot (153k) of the my view on the world of Linux. * I have a
menu item that links to a script that will place a new picture as the desktop image
when I get bored of the one I've been seeing for a couple of days (or hours, depending
on my threshold of boredom at the moment).
I have fun tweaking the configuration file. I think the main reason that a lot of people
prefer other windows managers to fvwm2 is that the file that sets up your desktop
menus and buttons and other things has to be worked on by hand. They really prefer
the clickasyougo configuration of other window managers. I happen to like
experimenting and I am prone to change it once a month or so (depending on that
threshold of boredom factor again). Fvwm2 is so configurable that if you got 5
different configuration files, known as .fvwm2rc, off the Internet and tried them out,
you would swear that you're seeing 5 different window managers.
You can check out the .fvwm2rc file behind the above screenshot. I'd like to
acknowledge that the main file was written by Jay Kuri. Thanks Jay, wherever you are.
I also included some tweaks that I got here and there. The main buttons you see are
from Eric S. Raymond's (author of The Cathedral and the Bazaar) .fvwm2rc and
modified slightly.
Of course, everyone is not into tweaking and prefer a more "clickable" configuration.
Peruse the offerings out there and choose one that suits your needs. You may also
want to hold of on the window managers for a bit and read the next section. We talk
about desktop environments, the ultimate userfriendly GUI experience for Linux.
*
There's a neat application called gkrellm that keeps track of a lot of things that are going on with the
system besides displaying the time and date. MS Windows users should take note of the uptime (last time
of reboot) of 27 days, 21 hours. We had a power blackout that lasted about 3 hours while a transformer in
my neighborhood was being fixed. Previous uptime was 31 days. I don't remember what happened 31
days before that.
Protecting the environment
Most computer users like to have a set of tools that they always see things like a
clock, a region that displays the date, a button that displays a menu with the programs
available for you to use. People have become accustomed to an icon system that sits
on a "desktop" that allows you, with a click of your mouse, to have your favorite
program up and running or open a web browser to your favorite website. This usually
goes beyond the call of duty for a window manager. In these cases you need the
services of a "desktop environment". This is a uniform looking desktop interface
which sits on top of and uses the services of a window manager. There are two major
desktop environments, GNOME, which uses the services of independent window
153
managers (at the time of this writing GNOME runs with Enlightenment) or KDE,
which has its own background window manager, known as kwm
GNOME or KDE
The question: 'Should I use GNOME or KDE?' was a controversial one not so long
ago. Luckily, now, it is just a matter of which interface you like more. The controversy
stemmed around the KDE project which was founded in 1996 with the goal of creating
a uniform desktop experience for Linux. KDE made the decision to use libraries to
create the desktop interface which were not open source. The libraries in question,
known as 'QT' are now open source, so the question is pretty much moot. However, at
the time, the issue inspired a young Mexican developer named Miguel de Icaza to
create a desktop interface known as GNOME.
GNOME was founded in August of 1997 and was an attempt to create a uniform
desktop manager that was totally compliant with the GNU's General Public License,
avoiding the licensing issues involved in the case of KDE's using the QT libraries.
Miguel de Icaza and Nat Friedman founded Helix Code in 1999 to oversee the
business end of developing the GNOME desktop. Helix Code later changed it's name
to Ximian.
What GNOME and KDE can offer
Both of these desktop environments offer a Microsoft Windowslike experience. To
date, KDE is the only one of the two to offer an office suite for word processing and
it's own web browser. Other than that, both offer toprate productivity applications
like email clients, agenda and scheduling software and address books. They offer
multimedia software for playing CDs, MP3s and other music formats. Both offer a
large selection of games in addition to other sundry applications for system
monitoring and other miscellaneous tasks.
Where to get these desktop environments
Most distributions come with both the GNOME and KDE desktop environments.
However, if your distribution did not have this or you are reading this and have not yet
installed Linux, you may want to check out both offerings.
• KDE homepage
• Ximian Inc.
You can also download the latest versions from their homepages.
Popular, useful and important programs that run in XWindow
At this point you've chosen your window manager and/or desktop environment.
Regardless of the "look" you've chosen, you have to have programs to run. You need
applications to surf the Internet, write email, manage your files, write letters and a
thousand other things you want to do. The rumors you hear about Linux lacking
applications or not being able to "make it on the desktop" are false. There is no major
application that a computer user needs that Linux lacks.
Internet/WWW Browsers
Netscape Communicator
The heavyweight of all browsers was one of the first to release a version for Linux.
Includes an HTML authoring tool and fullfeatured email program. Comes with the
standard plugins to view Flash animation and listen and see Real Audio/Video
content. At the time of this writing, version 6.2 is available for Linux.
154
Opera
Billed as the "fastest browser", Opera Software of Norway released their first version
of Opera for Linux in March of 2000. These early versions were not stable but the
company kept working and released a finished Opera 5 for Linux. At this time, the
company has released a beta version Opera 6 which offers plugin support for Flash
and Real Audio/Video. Their browser for Linux still doesn't have the same features as
their flagship MS Windows version (like an email client), but it's fast and extremely
stable and reliable.
Mozilla
Mozilla is the opensource version of Netscape. It is almost identical but the people in
the Mozilla project have added some extras to it that give it a bit of an advantage over
its "brother", Netscape, like being able to open new tabs (like Opera) instead of only
having the open to open new windows. If you don't like cluttering up your desktop,
this is a welcome feature. It also comes with all the support for plugins, Java and
JavaScript that Netscape has plus the same email client and HTML authoring tools. It
also ads and an easy to use IRC (Internet Relay Chat) client to its extras. At the time
of this writing, the Mozilla project is just about to release version 1.0. It's been a long
time coming, but if the old adage: Slow and steady wins the race, they may win the
browser contest.
Konqueror
Konqueror, part of the KDE project, is a file manager and Internet browser wrapped
up into one. You can surf the net and manage your files at the same time. If you're
migrating from Windows, you should find it very similar to Microsoft's Internet
Explorer. Includes plugin support as well as enabling for Java and JavaScript. You
need to have KDE installed to run this.
Galeon
Galeon is the browser associated with the GNOME project. It is based on the Gekko
HTML rendering engine that also runs Mozilla (this converts HTML into content you
can read). This browser is essentially Mozilla (you actually need Mozilla to run it)
modified somewhat to fit into the GNOME scheme of things. With the use of
'themes', the look is much more configurable than Mozilla itself.
StarOffice
We'll talk more about StarOffice in our section on office suites. It comes with a with a
web browser and an email client.
Speaking of email clients, let's look at some popular ones available for Linux
Email clients
The program you use to get, write and send your email is often referred to as a
"client". This is to distinguish it from the programs that sit on servers that receive and
process emails either sent to or sent from you. Email has become so important in our
everyday life that I have observed that advocating one email client over another often
takes on a fervor usually associated with religious beliefs. Here we'll look at some of
the major email clients for Linux.
Evolution
155
Ximian's Evolution, part of the GNOME desktop project has received a lot of press
lately. It is shaping up to be the only serious challenger to Microsoft Outlook's
domination of the groupware scene. Seeing that it has all the features of Outlook, sans
the virus problem, then you can see why it's getting some notice. If you're looking for
a good email client that comes with scheduling tools, task management, address books
and all those things that the busy yet organized person needs, than Ximian is probably
the thing for you.
Kmail
Kmail is KDE's major email client. It is not a complete groupware solution like
Ximian's Evolution, but its email management capabilities are very powerful. There is
support for all major types of email transport, intricate configuration of mail filters,
complete support for HTML formatted mail and other useful features.
Sylpheed
Japanese developer Hiroyuki Yamamoto has developed this fast, easy to use full
featured email client. This client is a big hit with developers as it offers really nice
threading (the ability to keep track of all mails based on one original mail) and a fairly
good way of managing different email accounts. If you have to respond to mail in
different capacities (boss, friend, worker), Sylpheed offers the tools to do this all in
one client.
Mutt
One of the most famous quotes in the Linux world is the one found at the top of the
home page for Mutt: All mail clients suck. This one just sucks less.. This was said by
Michael Elkins, who developed this email client. A lot of people will probably point
out, and rightly so, that Mutt doesn't have a graphic user interface. That is true.
However, this client is so popular in the Linux world that I just had to include it here.
If you are a newcomer to Linux, you may not want to use Mutt just yet. Using it
efficiently requires a wellwritten .muttrc file. This is the main configuration file that
determines how Mutt is going to work. However, if you get used to Mutt, you are
probably not going to ever switch. It's lack of a pretty interface is more than made up
for by the ability you have to configure Mutt. After you have some months behind you
working with it, emails will practically write themselves. If you handle a lot of email,
this is the client you probably want to at least look into.
Office suites, word processors and spreadsheets
StarOffice
StarOffice is a complete, fullfeatured office suite on the idea of Microsoft Office. It
comes complete with word processor (of course), spreadsheet, database interfacing,
presentation software plus it offers web browsing and email and a few other features.
Originally developed by StarDivision, StarOffice was acquired by Sun Microsystems
in 1999. The current stable version of this suite is 5.2 at the time of this writing.
However, Sun has announced that they plan to charge for downloads of StarOffice
version 6.
KOffice
KOffice is the KDE Project's offering for desktop productivity. It includes all of the
standard office suite applications. The software is offered free of charge.
VistaSource's Anywhere Desktop for Linux
156
This suite was formerly known as ApplixWare. Once again, all the standard office
suite tool are offered here. This one boasts a Microsoft Office look and feel. This is
not a free product. It cost 99 US dollars at the time of this writing.
Siag Office
Don't let a name like Pathetic Writer dissuade you from checking out this office suite
for Linux. The word processor part of the suite can open Microsoft Word format
(*.doc) files. The project started with the Scheme in a grid spreadsheet. Now you
know why it's called Siag. Another free offering in the office category.
HancomOffice for Linux
Hancom Linux of Korea has developed this commercial fullfeatured office suite for
Linux. Provides compatibility with Microsoft Office formats and smooth integrating
into the KDE desktop. An evaluation version is available for download, but the
software must be purchased in order to continue to use it.
GNOME Office
GNOME office should actually appear in quotes, because this is not an office suite in
the classic sense, but a set of applications that are often associated with office suites,
as a package deal, so to speak. Some of the highlights include:
• Gnumeric, a spreadsheet application
• AbiWord, a word processor (it even runs under Windows and MacOS)
• Gnucash, a personal finance manager
• GNOMEDB, database connectivity software
If you download the Ximian Desktop, you'll get these applications plus the other
productivity tools associated with the GNOME project. Little goodies to improve your
quality of life
(aka: those little apps you'd rather not live without)
Music
When I got broadband Internet access, my life changed forever. No more paying for
dialups on a hourly basis. No more painful downloads of software. But what's more
important than all of this is that I could now listen to radio! So what, you say. Well, I
live more than 6,000 miles from the place where I grew up, so when I could finally
listen to a radio station from the city where I was born as easily as my mother (who
still lives there) can switch on the radio, I was delighted. RealAudio player for Linux
is just one of those little apps I'd rather not live without.
RealPlayer
I can't help but make an editorial comment here about this application. This for me
represents more than just a way of listening to your favorite online radio station or
viewing the BBC World Service broadcast. RealPlayer represents the difference
between stations having a choice to "webcast" freely or having to kowtow to
Microsoft. It looks like Gates and Co. plans on dominating the online
music/information industry. Real Networks is at this point the only thing preventing
them from doing it.
Now that I've finished my editorializing, you can go get RealPlayer for Linux and
install it and start listening to web broadcasts.
XMMS
157
XMMS stands for the X multimedia system. If you're familiar with WinAmp, you'll
have no trouble getting used to this program. You can listen to your favorite MP3s
plus files in the newly emerging free Ogg Vorbis format.
Image viewing and editing
The GIMP
GIMP stands for GNU Image Manipulation Program. It should never be associated
with the English word meaning lame. Gimp also has another meaning, according to
the dictionary I consulted: Smart; spruce; trim; nice. That's a better description. This
is a full fledged image creating and retouching application. You can apply all sorts of
filters and even write scripts for doing things to the images automatically. If you work
a lot with images and think that by switching to Linux you'll be unable to work
efficiently with graphics, then check out The GIMP. You'll be pleasantly surprised.
xv
In the words of the its author, John Bradley, xv doesn't stand for anything. I use this
program all the time, literally. It is what I use to display the image in my desktop
window.
type this:
xv root max quit your_favorite_pic.jpg
and xv will display your favorite picture as the pic on your desktop Sometimes I get
bored and I use this script to rotate my favorite pictures.
#!/bin/sh
for i in `ls /home/mike/rotation_bkg/*.jpg`
do
xv root max quit $i
sleep 300
done
If you're looking for heavy duty image software, xv is not it, however. This is the
author's own words:
Basically, xv's primary thrust has always been displaying images (in many formats) quickly and nicely on
a wide variety of display hardware.
That pretty much sums it up. xv is distributed as shareware.
ImageMagick
ImageMagick is a suite of tools for displaying and manipulating images. It's not as
powerful (in my opinion) as The GIMP but more powerful than xv. I use it for three
basic things. The 'display' tool I use to tell my email client open images that people
send me in emails. Another one I use a lot is the thumbnail generator. If you've got a
lot of images in a directory and you want to have an inventory of all of them as one
image, then you would type:
display 'vid:*.jpg'
This creates one image of all of the jpg images as thumbnails in the directory you're
in. This takes up a lot of CPU power on even a fairly powerful machine, so be patient.
158
If you've got a lot of images in a directory and a slow machine, you might want to
consider doing them in small batches.
This next use of ImageMagick is my twoyearold's favorite. I have some pictures of
him in a directory and I type:
animate *.jpg
This starts up a slide show of him at blinding speed and he gets a big kick out of it. If
you want to get the images rotating at a more manageable speed, just use the shift >
keys or click with the right mouse button to call up the menu.
Text editors and viewers
Sometimes you don't want to fire up a whole office suite to read some text file and
sometimes you have to create and/or edit documents as plain text. If you wanted, for
example, to modify my image rotation script above, you would open up a text editor.
There are two that I use on two different occasions.
Emacs
There is a version of Emacs if your not using Xwindow and then there's XEmacs, a
version expressly written for Xwindow. I refer to the xwindow version of Emacs,
which is like the console version, but has clickable menus and windows and
everything you need to work in a graphical environment. Richard Stallman, founder of
the GNU project, first started working on Emacs in 1974. It has since then become the
flagship application of the GNU project. It is truly the perfect application to be the
one associated with the GNU. It is a Swiss Army Knife of editors. To call it an 'editor'
is to insult it somewhat. It does a little bit of everything. To me, it's almost like a mini
operating system in and of itself. If you're a programmer, Emacs is essential for
working. If I could not use Emacs for some reason, I would probably go off and herd
sheep. (and if you think I'm joking, ask my wife). Even for nonprogramming tasks I
use it. The entire Linux Online beginners' course (yes, the words you are reading right
now) were written in their entirety using Emacs. That day in 1974 when Richard
Stallman sat down and started development of Emacs is a great day in history.
xedit
xedit is a basic text viewer/editor for Xwindow. It was one of the first applications. It
is not slick or fancy, but there is one thing I like very much about it. The ability to fire
it up from an xterm with a couple of preferences of mine. Reading fairly long things
on a computer is not one of my favorite activities. My eyes don't seem to like it either.
With xedit, you can specify a readable font and some good eyefriendly colors when
you start it up.
xedit bg seagreen fg navajowhite fn 9x15*bold some_text_file.txt &
As we're on the topic of basic XWindow applications, you can use xcolors to get a
background and foreground combination that suits your eyes. Use the right mouse
button to select a font color and the middle button to select the background.
If you want to select colors (for example, for web page work) and you've got the
GNOME desktop installed, you can use GNOME Color Browser. It's easier to manage
that xcolors and has a nice grab feature to select colors from other places and get their
values/names.
Miscellaneous Programs
roottail
159
tail is a console application that is normally used for monitoring files that change
constantly, like log files. roottail can be used to display these files on your desktop
while you're running Xwindow. I normally use this to remember important stuff. It
really comes in handy. First, you should create a text file with your favorite editor.
Call it 'reminders'. Then on each line, write something that you want to remember.
Then, you run roottail. It's best to do this with a few options. For example, this is how
I run it:
roottail color yellow font 12x24 shade g +10+100 $HOME/reminders &
Let's explain some of these options. First, after 'color' you should use the name of the
color you want the text to appear in. Use xcolors to find a color you like that's
supported by your system. The next one is 'font'. As you see, I've chosen a good sized
one. 'shade' will give the text a little shade under it and will look snazzier. 'g' stands
for 'geometry' or the location in the window. I use +10+100 which set it right in front
of me. You can experiment with settings. Now you have no excuse for forgetting to
buy your loved ones presents on their birthdays!
gkrellm
This is nice little application to monitor what's going on with your computer. You can
keep track of you memory usage, swap space, how much bandwidth you're using
through your ethernet card and much, much more. You can see it in this screenshot.
It's running on the upper right side of my desktop. It's useful as a way to alert you to
how many clueless Windows users there are. Invariably, when some Sircam provoked
mail comes through, the 'eth0' monitor, which checks bandwidth usage will start
rising for no apparent reason. If you do conversions of audio to MP3 or Ogg format,
you can watch your CPU usage go off the scale when you do them. Place your mouse
over gkrellm and press F1 to configure other monitors. There are also plugins and
themes/skins available.
Xchat
xchat is a comfortable IRC (Internet Relay Chat) client. It's very easy to configure to
your liking. There is the possibility to use Python and Perl scripts to automate some
things you do.
A lot of programs to choose from
There are thousands of programs for Linux in our applications section. Have a look
and we're sure you'll find the right programs to suit your needs
Tips and Tricks for XWindow
.xinitrc
This is a file you'll find in your user directory. You can use it to start programs
automatically when you start Xwindow. Open the file with vi or the text editor of
your choosing. Then, for example, add:
xclock bg wheat geometry 100x100+1+1 &
bg sets the background color and the geometry setting I have used here gives you a
fairly small, but not too small clock in the upper left hand corner of your desktop. You
can type: man xclock to see more options. Experiment with options first before you put
your definitive xclock settings in your .xinitrc file. Just type your settings into an
xterm and try different ones. Type: killall xclock to shut off the clock each time.
.Xdefaults file
160
There's another file in your user directory called .Xdefaults. You can use this file to
change the way some of your Xwindow applications look. It's fun to try out different
styles and get some settings that please your eye. Before you try to do this however,
make a backup. Type:
cp .Xdefaults .Xdefaults_good
because there is always some danger of making some applications nonoperable
because you have left spaces where you shouldn't. It is important when you change
settings that you leave no trailing spaces. Most major distributions provide a working
.Xdefaults file. It's best to leave what you find there, but you're free to add stuff to it.
As an example, let's change the look of emacs, for example.
First, open up the file with Vi or any text editor your prefer. Add this to it:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! emacs changes [date]
emacs*Background: DarkCyan
emacs*Foreground: Khaki
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Let's explain what we've done here. First, the exclamation point (!) in this file is used
to make comments. The two rows of exclamation points I've used to show where my
emacs section begins and ends. Then I use two to comment that I am changing emacs
and I have included [date] where I would put the actual date to show when I made the
changes. You don't have to to this. It's just something extra to remind me when I made
the changes. Then we make the actual changes.
With: emacs*background: DarkCyan we can change the background of the application's
menu bar and frame. You can use any color you like that the system supports.
With: emacs*Foreground: Khaki we've changed the color of the words in the menu.
To make the changes take effect, you have to issue this command in an xterm:
xrdb merge $HOME/.Xdefaults
This will restart the xserver database and log in your changes. If you don't do this, X
window keeps your old .Xdefaults in memory and you won't see anything new. Restart
emacs and you should see your new colors. If emacs doesn't come up, you may have
left some trailing white space. If that is the case, just type emacs in an xterm and an
error message should appear saying something like: Warning: Color name "khaki " is not
defined or similar. If you see a space before the second quotation mark, then you've got
whitespace in your .Xdefaults file that needs to be eliminated.
As you get more adept at changing things, you'll make your desktop more to your
liking.
xwininfo
If you're interested in seeing a bit of information about certain programs running, you
can type xwininfo into a terminal and then click on any window. For example, I had
another xterm open and I clicked on it and got this info:
xwininfo: Window id: 0x2c0000e "xterm"
Absolute upperleft X: 211
Absolute upperleft Y: 132
161
Relative upperleft X: 0
Relative upperleft Y: 0
Width: 581
Height: 340
Depth: 16
Visual Class: TrueColor
Border width: 0
Class: InputOutput
Colormap: 0x20 (installed)
Bit Gravity State: NorthWestGravity
Window Gravity State: NorthWestGravity
Backing Store State: NotUseful
Save Under State: no
Map State: IsViewable
Override Redirect State: no
Corners: +211+132 8+132 8128 +211128
geometry 80x243+109
This comes in handy especially to find suitable 'geometry' settings for use in starting
up applications and including them in the .xinitrc file.
xset
This is a command line utility to control things like your mouse, keyboard, monitor
and pc speaker. Both GNOME and KDE have other graphic apps to do this stuff a lot
easier, so I find myself using this less and less. But you can try it out. For example,
type: xset b off to stop your computer from beeping at it. And to turn it back on? You
guessed it: xset b on. You can also change the tone by typing something like: xset b 30
550 300 The first number is for volume, the second pitch and the third duration of the
beep.
xsetroot
In a previous section, we told you how to use xv to put your favorite picture on your
desktop. If you get tired of pictures and you want something plain, you can use
xsetroot to just put a color scheme on the desktop. For example, typing: xsetroot solid
seagreen will get you a solid dark green color as a background. This one is soothing to
the eyes. It's the same color used on pool and card tables. Of course, you're free to use
the color you like! Type: man xsetroot to see other options.
More XWindow Tips and Tricks
Starting X on other virtual terminals
With Linux, you are not limited to starting Xwindow only once. You may open up
another virtual terminal and start another instance of Xwindow. Remember though
that running two instances will use up a lot of memory.
As we saw in previous lessons, to switch to another virtual terminal, press:
CTRL + ALT + F2 (or F3 up to F6)
Then login as another user and type:
startx :1
You can switch between instances of XWindow by typing:
162
CTRL + ALT + F7 and
CTRL + ALT + F8
Using the XWindow programs from another computer
This is the thing I love to show people from the MS Windows world. I point to the
computer across the room and then say: "Now I am going to start the browser from
that system and make it appear here." You don't need to be David Copperfield to
perform this magic. You only need Xwindow running on one and installed on the
other. You also need a means of logging in to the other computer. And here's one more
thing. The computer doesn't even need to be in the same room. It can be in a different
room in a different building on a different continent. Providing your bandwidth is
good enough, you can start a program on a computer 5000 kilometers away and use it
on your desktop.
There are two ways to do this. One is not secure and probably should only be used on
a local network, if at all. The second one is very secure and can be used for trans
oceanic Xwindow sessions.
If you have the remote login device telnet and the telnet server installed on the
machines, you can use this fairly safely in a local network. For example, if you
workstation is called 'amos' and the other machine is called 'andy' and you want to use
a program on 'andy', sitting at 'amos', you would type:
xhost +andy
Then with telnet, login into 'amos' (telnet> open amos)
Then, type:
DISPLAY=amos:0.0
then
export DISPLAY
Now you can type the name of any program you want to run that you know is on
'andy'. Remember though, as I mentioned, telnet is insecure. This are better ways of
doing this. You should never do this if you're working over a public network, like the
Internet.
Remote X sessions with OpenSSH
Open SSH stands for Open Secure Shell. That's just what it is. A secure shell for
logging in at other computers in a secure manner. What goes over the network is
encrypted and your security is not compromised. Most major distributions will offer
this and it is normally installed by default. You may have to specifically install the
OpenSSH server which you need to have to for this to work on your local network.
Using X on another machine, also known as X forwarding is usually disabled by
default so you may have to edit one file to get this to work locally. If you're doing this
across oceans or continents the configuration will depend on the remote machine. As
long as you have a OpenSSH client and an account on the other machine, you can do
this.
As I mentioned, if you want to do this locally. Here's what you have to do. Let's use
our 'amos' and 'andy' example again. You're sitting at your workstation called 'amos'.
Make sure you have OpenSSH server on installed on 'andy' and have created a user
account there. On 'andy' you need to login as 'root' and make sure that there is a line in
a file called 'sshd_config', usually located in /etc/ssh that says X11Forwarding yes. If this
163
says X11Forwarding no than you need to change it to yes. Then you need to restart the
OpenSSH server. The easiest way is to look for its PID by typing: ps ax | grep sshd and
killing it's PID number. Then type: sshd to start the server again.
Then, from 'amos' just connect to 'andy' via SSH, like so:
ssh l [yourusername] andy
you'll be asked for your password. You log in and then you can run the X application
that you want. It will come up on your desktop on 'amos' courtesy of 'andy'. A final
word about Xwindow
The GUI applications for Linux are always changing, evolving and adapting to user
needs. Linux has come a long way in the past few years. It is becoming a serious
threat to the dominance of Microsoft Windows not only in the server market but on
the desktop as well. The important work done by the people in the GNOME and KDE
projects as well as other those carrying out development of other window managers
and XFree86 show the level of commitment there is to getting Linux on the desktops
of the worlds computers in offices and homes.
In this lesson we've given you a number of addresses of web pages of these types of
projects. The best thing to do to support these efforts is to check back on these
projects from time to time, install the latest version and talk to your friends about how
good you think they are. Also, contact the developers or join the mailing list for that
particular project and provide feedback, both positive and negative, about the software
you've tried. That's essentially what the Linux movement is all about. You can also
volunteer to do some work. You don't have to be a programmer to make a vital
contribution. You can translate the documentation or the graphic interface to your
native language, for example. In the end, any form of collaboration is good. That's
how Linux grew into the major operating system that it is and that's essentially what
the Linux movement is all about.
Lesson Twenty
The end of the beginning
This is the end of Getting Started with Linux, our beginner's introduction to this
operating system. What we have intended to do is take you from the point where
you've got some Linux CDs and a computer in front of you without Linux in it to
where you've installed and and you're using it productively. This means that you're
using it to maintain files, write documents , manage data, keep figures straight with a
spreadsheet, surf the web, write email, chat with friends. At the same time you're
listening to your favorite music in either MP3 or Ogg format, on a CD or streaming
over RealAudio.
The fact is that there is an endless amount of things that you can do with Linux. Our
aim here was to give you the basics. Now it's up to you to explore to try expanding on
the things that you've learned here. In the end, the point is to learn and to have a little
fun in the process.
Where do you go from here?
At this time we're working on our Intermediate Linux Course. This course, which is
still in development, will take you from the beginner level to the point where you feel
very comfortable with Linux. Our aim is not to make professional systems
administrators out of those who follow the course, but to make you independent
164
enough with your Linux machine that you don't need to seek outside help as
frequently as a novice does to solve the occasional problems that arise. Here are a few
of the topics that we'll be covering in the next course.
• general system administration
• security alerts
• Linux kernel compiling and installation of new kernels
• automating services and tasks
• use of Bash and Perl scripts
• firewalls
• setting up a web server with Apache
• setting up a mail server with sendmail
• Samba for Windows file sharing
• Professional databases MySQL and PostgreSQL
• Linux for the small business
If you are a registered user, we'll keep you posted on updates as to the availability of
the Intermediate Linux Course. If you're not registered, all you have to do is sign up
and you'll receive our newsletter with updates.
Author's Notes
Hello and welcome to the Beginner's Guide to Linux. I am the author, Michael Jordan.
I am also the webmaster of Linux Online. As was mentioned on the introduction page,
I welcome comments, suggestions and wellintentioned criticism. I'd ask you to take a
look at what's below before sending off an email about anything to do with the course.
You may have found your question answered below and will save us both some typing.
(or your wondering why you didn't get a response).
History of the course and rationale
In the spring of 2000, Michael McLagan, owner and General Manager of this website,
brought up the idea of doing various Linux courses of different levels to be offered
free of charge to the public. Initially, this task was to be handled by one of the web
developers. Unfortunately, this person had to be let go. The task then fell to me.
I earned a B.A. in history and teaching certification in 1987 and have been a
practicing classroom teacher since then. I have written online instructional materials
for teaching English as a foreign language as well, so when I got the nod to develop
the course, I was swimming in familiar waters.
Our deadline to get the course published was the Linux World Expo of August 2000 in
San Francisco. Some 'backend' Perl scripts were put into place about a month before
this event to handle both the authoring of the course and the public's access to the
material. The developer of the scripts also left Linux Online and the system proved
too difficult to work with. Without the developer here anymore, we decided to switch
over to basic HTML format. By early 2001, access to the first part of the course was
provided by Perl scripts while the remaining part was being offered in static HTML
files.
165
In the fall of 2002, we decided to end this hybrid system and convert everything to the
HTML format exclusively. This was completed in January 2003. I also took advantage
of the format change to totally rewrite some sections and to bring the course upto
date in general.
Plans for the Future
The course is now being offered from static HTML, but as the content is what matters,
we can adapt the text in these files to a future 'dynamic' content management system.
This system will make navigation easier and will let us also offer tests and quizzes.
Grades on these will be entered into registered users' accounts. Once the system is in
place, we can then offer certificates to those who have followed the course.
Dodati: umask, head, kratak opis servisa, exit codes, libraries...., tac, naredba
“runlevel”, /etc/inittab
zašto se ne može demountati: lsof, fuser
simlinkovi!
TODOs
p: 32 dodatni bash trikovi
p: 73 /etc/passwd
p: 98 /etc/fstab
p: 102 inittab, log files
p: 110 lekcija prekratka
p: 114 napisati ponovo
p: 120... sve prazno
166