Read it Now!
Reprint Licensing

Running Linux
Running Linux, Fourth Edition

By Matt Welsh, Matthias Kalle Dalheimer, Terry Dawson, Lar Kaufman

Cover | Table of Contents | Colophon


Table of Contents

Chapter 1: Introduction to Linux
This is a book about Linux, a free, open source operating system that supports full multitasking, the X Window System, TCP/IP networking, and much more. Hang tight and read on: in the pages that follow, we describe the system in meticulous detail.
Linux has generated more excitement in the computer field than any other development of the past several years. It has spread surprisingly fast, and the loyalty it inspires recalls the excitement of do-it-yourself computing that used to characterize earlier advances in computer technology. Ironically, it succeeds by rejuvenating one of the oldest operating systems still in widespread use: Unix. Linux is both a new technology and an old one.
In narrow technical terms, Linux is just the operating system kernel, offering the basic services of process scheduling, virtual memory, file management, and device I/O. In other words, Linux itself is the lowest-level part of the operating system.
However, most people use the term "Linux" to refer to the complete system — the kernel along with the many applications that it runs: a complete development and work environment including compilers, editors, graphical interfaces, text processors, games, and more.
This book will be your guide to Linux's shifting and many-faceted world. Linux has developed into an operating system for businesses, education, and personal productivity, and this book will help you get the most out of it.
Linux can transform any personal computer into a high-end workstation and server. Corporations are installing Linux on entire networks of machines, using the operating system to manage financial and hospital records, distributed-user computing environments, telecommunications, and more. Universities worldwide are using Linux for teaching courses on operating system programming and design. And, of course, computing enthusiasts everywhere are using Linux at home, for programming, document production, and all-around hacking. People use Linux on high-end desktop machines, handheld PDAs, mobile laptops, and even old clunkers sitting in the closet doing nothing more than spooling print jobs.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
About This Book
This book is an overview and entry-level guide to the Linux system. We attempt to present enough general and interesting information on a number of topics to satisfy Unix novices and wizards alike. This book should provide sufficient material for almost anyone to install and use Linux and get the most out of it. Instead of covering many of the volatile technical details — those things that tend to change with rapid development — we give you enough background to find out more on your own.
This book is geared for those people who really want to exploit the power that Linux provides. Rather than gloss over all the tricky details, we give you enough background to truly understand how the various parts of the system work, so you can customize, configure, and troubleshoot the system on your own. Linux is not difficult to install and use. However, as with any implementation of Unix, there is often some black magic involved to get everything working correctly.
In this book, we cover the following topics:
  • What is Linux? The design and philosophy of this unique operating system, and what it can do for you.
  • Information on what you need to run Linux, including suggestions on what kind of hardware configuration is recommended for a complete system.
  • How to obtain and install Linux. We cover the Red Hat, SuSE, and Debian distributions in more detail than others, but the background here should be adequate to cover any release of the system.
  • For new users, an introduction to the Unix system, including an overview of the most important commands and concepts.
  • The care and feeding of the Linux system, including system administration and maintenance, upgrading the system, and how to fix things when they don't work.
  • Getting the most out of your Linux system, with "power tools" such as TEX, Emacs, KDE, GNOME, and more.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
A Brief History of Linux
Unix is one of the most popular operating systems worldwide because of its large support base and distribution. It was originally developed as a multitasking system for minicomputers and mainframes in the mid-1970s. It has since grown to become one of the most widely used operating systems anywhere, despite its sometimes confusing interface and lack of central standardization. There is no single implementation of Unix. Originally developed by Bell Labs, Unix eventually forked into several versions, including a popular distribution from the University of California at Berkeley, called BSD. Over the years, many vendors have developed their own implementations of Unix, either from scratch or starting with another version. Linux was built from the ground up, although earlier versions included some code from BSD as well.
While Unix underwent a dip in market strength during the early 1990s, under the onslaught of the new Windows NT system, it came back strong and has become the mainstay of large computers.
Unix has quite a cult following in the operating systems community. Many hackers feel that Unix is the Right Thing — the One True Operating System. Hence, the development of Linux by an expanding group of Unix hackers who want to get their hands dirty with their own system. Moreover, Linux is not a "product" that ties you to a particular vendor or software developer. Because Linux is free, and all the source code is available (more on that later), anyone can modify the system to fit their own needs. Rather than waiting for some large company to release the latest features and service packs, the Linux user community is empowered to improve, adapt, and fix the system themselves. It's this empowerment that has helped Linux become so powerful.
Linux is a freely distributable version of Unix, originally developed by Linus Torvalds, who began work on Linux in 1991 as a student at the University of Helsinki in Finland. Linus now works for Transmeta Corporation, a company in Santa Clara, California, and continues to maintain the Linux
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Who's Using Linux?
Application developers, system administrators, network providers, kernel hackers, students, and multimedia authors are just a few of the categories of people who find that Linux has a particular charm.
Unix programmers are increasingly using Linux because of its cost — they can pick up a complete programming environment for a few dollars and run it on cheap PC hardware — and because Linux offers a great basis for portable programs. It's a modern operating system that is POSIX-compliant and looks a lot like System V, so code that works on Linux should work on other contemporary Unix systems.
Networking is one of Linux's strengths. It has been adopted with gusto by people who run large networks, due to its simplicity of management, performance, and low cost. Many Internet sites are making use of Linux to drive large web servers, e-commerce applications, search engines, and more. Linux supports common networking standards, such as Network File System (NFS) and Network Information Service (NIS), making it easy to merge a Linux machine into a corporate or academic network with other Unix machines. It's easy to share files, support remote logins, and run applications on other systems. Linux also supports the Samba software suite, which allows a Linux machine to act as a Windows file and print server. Many people are discovering that the combination of Linux and Samba for this purpose is faster (and cheaper) than running Windows 2000.
One of the most popular uses of Linux is in driving large enterprise applications, including web servers, databases, business-to-business systems, and e-commerce sites. A large number of businesses are discovering that Linux is an inexpensive, efficient, and robust system capable of driving the most mission-critical applications. The fact that Linux can be readily customized — even down to the guts of the kernel — makes the system very attractive for companies that need to exercise control over the inner workings of the system. Linux supports RAID, a mechanism which allows an array of disks to be treated as a single logical storage device, greatly increasing reliability. The combination of Linux, the Apache web server, the MySQL database engine, and the PHP scripting language is so common that it has its own acronym — LAMP. We'll cover LAMP in more detail in Chapter 18.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
System Features
Linux supports most of the features found in other implementations of Unix, plus quite a few not found elsewhere. This section provides a nickel tour of the Linux kernel features.
One potentially confusing aspect of Linux for newcomers is the way in which different pieces of software are assigned a version number. When you first approach Linux, chances are you'll be looking at a CD-ROM distribution, such as "Red Hat Version 7.1" or "SuSE Linux Version 6.0." It's important to understand that these version numbers only relate to the particular distribution (which is a prepackaged version of Linux along with tons of free application packages, usually sold on CD-ROM). Therefore, the version number assigned by Red Hat, SuSE, or Debian might not have anything to do with the individual version numbers of the software in that distribution.
The Linux kernel, as well as each application, component, library, or software package in a Linux distribution, generally has its own version number. For example, you might be using gcc Version 2.96, as well as the XFree86 GUI Version 4.0.3. As you can guess, the higher the version number, the newer the software is. If you install Linux in the form of a distribution (such as Red Hat and SuSE), all of this is simplified for you since the latest versions of each package are usually included in the distribution, and the distribution vendors make sure that the software on a particular distribution works together.
The Linux kernel has a peculiar version numbering scheme with which you should be familiar. As mentioned before, the kernel is the core operating system itself, responsible for managing all the hardware resources in your machine — such as disks, network interfaces, memory, and so on. Unlike Windows systems, the Linux kernel doesn't include any application-level libraries or GUIs. In some sense, as a user you will never interact with the kernel directly, but rather through interfaces, such as the shell or the GUI (more on this later).
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Software Features
In this section, we'll introduce you to many of the software applications available for Linux and talk about a number of common computing tasks. After all, the most important part of the system is the wide range of software available for it. What's even more impressive on Linux is that most of this software is freely distributable.
Virtually every utility you would expect to find on standard implementations of Unix has been ported to Linux. This includes basic commands such as ls, awk, tr, sed, bc, more, and so on. There are Linux ports of many popular software packages including Perl, Python, the Java Development Kit, and more. You name it, Linux has it. Therefore, you can expect your familiar working environment on other Unix systems to be duplicated on Linux. All the standard commands and utilities are there.
Many text editors are available, including vi (as well as "modern" versions, such as vim), ex, pico, and jove, as well as GNU Emacs and variants, such as XEmacs (which incorporates extensions for use under the X Window System) and joe. Whatever text editor you're accustomed to using has more than likely been ported to Linux.
The choice of a text editor is an interesting one. Many Unix users still use "simple" editors such as vi (in fact, the first edition of this book was written using vi under Linux). However, vi has many limitations due to its age, and more modern (and complex) editors, such as Emacs, are gaining popularity. Emacs supports a complete LISP-based macro language and interpreter, a powerful command syntax, and other fun-filled extensions. Emacs macro packages exist to allow you to read electronic mail and news, edit the contents of directories, and even engage in an artificially intelligent psychotherapy session (indispensable for stressed-out Linux hackers). In Chapter 9, we include a complete vi tutorial and describe Emacs in detail.
One interesting note is that most of the basic Linux utilities are GNU software. These
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
About Linux's Copyright
Linux is covered by what is known as the GNU GPL. The GPL, which is sometimes referred to as a "copyleft" license, was developed for the GNU project by the Free Software Foundation. It makes a number of provisions for the distribution and modification of "free software." "Free," in this sense, refers to freedom, not just cost. The GPL has always been subject to misinterpretation, and we hope that this summary will help you to understand the extent and goals of the GPL and its effect on Linux. A complete copy of the GPL is available at http://www.gnu.org/copyleft/gpl.html.
Originally, Linus Torvalds released Linux under a license more restrictive than the GPL, which allowed the software to be freely distributed and modified, but prevented any money changing hands for its distribution and use. The GPL allows people to sell and make profit from free software, but doesn't allow them to restrict the right for others to distribute the software in any way.
First, we should explain that "free software" covered by the GPL is not in the public domain. Public domain software is software that is not copyrighted and is literally owned by the public. Software covered by the GPL, on the other hand, is copyrighted to the author or authors. This means that the software is protected by standard international copyright laws and that the author of the software is legally defined. Just because the software may be freely distributed doesn't mean it is in the public domain.
GPL-licensed software is also not "shareware." Generally, shareware software is owned and copyrighted by the author, but the author requires users to send in money for its use after distribution. On the other hand, software covered by the GPL may be distributed and used free of charge.
The GPL also allows people to take and modify free software, and distribute their own versions of the software. However, any derived works from GPL software must also be covered by the GPL. In other words, a company could not take Linux, modify it, and sell it under a restrictive license. If any software is derived from Linux, that software must be covered by the
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Open Source and the Philosophy of Linux
When new users encounter Linux, they often have a few misconceptions and false expectations of the system. Linux is a unique operating system, and it's important to understand its philosophy and design in order to use it effectively. At the center of the Linux philosophy is a concept that we now call open source software.
Open source is a term that applies to software for which the source code — the inner workings of the program — is freely available for anyone to download, modify, and redistribute. Software covered under the GNU GPL, described in the previous section, fits into the category of open source. Not surprisingly, though, so does software that uses copyright licenses that are similar, but not identical, to the GPL. For example, software that can be freely modified but that does not have the same strict requirements for redistribution as the GPL is also considered open source. Various licenses fit this category, including the BSD License and the Apache Software License.
The so-called "open source" and "free software" development models started with the Free Software Foundation and were popularized with Linux. They represent a totally different way of producing software that opens up every aspect of development, debugging, testing, and study to anyone with enough interest in doing so. Rather than relying upon a single corporation to develop and maintain a piece of software, open source allows the code to evolve, openly, in a community of developers and users who are motivated by desire to create good software, rather than simply make a profit.
O'Reilly & Associates, Inc. has published a book, Open Sources, which serves as a good introduction to the open source development model. It's a collection of essays about the open source process by leading developers (including Linus Torvalds and Richard Stallman) and was edited by Chris DiBona, Sam Ockman, and Mark Stone.
Open source has received a lot of media attention, and some are calling the phenomenon the "next wave" in software development, which will sweep the old way of doing things under the carpet. It still remains to be seen whether that will happen, but there have been some encouraging events that make this outcome seem likely. For example, Netscape Corporation has released the code for its web browser as an open source project called Mozilla, and companies such as Sun Microsystems, IBM, and Apple have released certain products as open source in the hopes that they will flourish in a community-driven software development effort.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Sources of Linux Information
As you have probably guessed, many sources of information about Linux are available, apart from this book.
If you have access to the Internet, you can get many Linux documents via web and anonymous FTP sites all over the world. If you do not have direct Internet access, these documents may still be available to you; many Linux distributions on CD-ROM contain all the documents mentioned here and are often available off the retail shelf. Also, they are distributed on many other networks, such as Fidonet and CompuServe.
A great number of web and FTP archive sites carry Linux software and related documents. Appendix A contains a listing of some of the Linux documents available via the Internet.
Examples of available online documents are the Linux FAQ, a collection of frequently asked questions about Linux; the Linux HOWTO documents, each describing a specific aspect of the system — including the Installation HOWTO, the Printing HOWTO, and the Ethernet HOWTO; and the Linux META-FAQ, a list of other sources of Linux information on the Internet.
Most of these documents are also posted regularly to one or more Linux-related Usenet newsgroups; see Section 1.8.3 later in this chapter.
The Linux Documentation home page is available to web users at http://www.tldp.org. This page contains many HOWTOs and other documents, as well as pointers to other sites of interest to Linux users, including the Linux Documentation Project manuals (see the following section).
The Bibliography at the end of this book points you to a wealth of sources that will help you use your system. There are a number of published works specifically about Linux. In addition, a number of free books are distributed on the Internet by the Linux Documentation Project (LDP), a project carried out over the Internet to write and distribute a bona fide set of "manuals" for Linux. These manuals are analogs to the documentation sets available with commercial versions of Unix: they cover everything from installing Linux to using and running the system, programming, networking, kernel development, and more.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Getting Help
You will undoubtedly require some degree of assistance during your adventures in the Linux world. Even the most wizardly of Unix wizards is occasionally stumped by some quirk or feature of Linux, and it's important to know how and where to find help when you need it.
The primary means of getting help in the Linux world are Internet mailing lists and Usenet newsgroups, as described earlier. A number of businesses also provide commercial support for Linux. A "subscription fee" allows you to call consultants for help with your Linux problems. Several Linux distribution vendors provide online and telephone-based technical support, which can often be very helpful. However, if you have access to Usenet and Internet mail, you may find the free support found there just as good.
Keeping the following suggestions in mind should improve your experiences with Linux and guarantee you more success in finding help to your problems:
  • Consult all available documentation first. The first thing to do when encountering a problem is consult the various sources of information listed in the previous section and Appendix A. These documents were laboriously written for people like you — people who need help with the Linux system. Even books written for Unix in general are applicable to Linux, and you should take advantage of them. Impossible as it might seem, more than likely you will find the answer to your problems somewhere in this documentation.
    If you have access to the Web, Usenet news, or any of the Linux-related mailing lists, be sure to actually read the information there before posting for help with your problem. Many times, solutions to common problems are not easy to find in documentation and are instead well-covered in the newsgroups and mailing lists devoted to Linux. If you only post to these groups and don't actually read them, you are asking for trouble.
  • Use the search engines!
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 2: Preparing to Install Linux
This chapter represents your first step in installing Linux. We'll describe how to obtain the Linux software, in the form of one of the various prepackaged distributions, and how to prepare your system. We'll include ways to partition disks so that Linux can coexist with Windows, or another operating system.
As we have mentioned, there is no single "official" distribution of the Linux software; there are, in fact, many distributions, each serving a particular purpose and set of goals. These distributions are available via anonymous FTP from the Internet and via mail on CD-ROM and DVD, as well as in retail stores.
Because Linux is free software, no single organization or entity is responsible for releasing and distributing the software. Therefore, anyone is free to put together and distribute the Linux software, as long as the restrictions in the GPL are observed. The upshot of this is that there are many distributions of Linux, available via anonymous FTP or mail order.
You are now faced with the task of deciding on a particular distribution of Linux that suits your needs. Not all distributions are alike. Many of them come with just about all the software you'd need to run a complete system — and then some. Other Linux distributions are "small" distributions intended for users without copious amounts of disk space.
You might also want to consider that distributions have different target groups. Some are meant more for businesses, others more for the home user. Some put more emphasis on server use, others on desktop use.
The Linux Distribution HOWTO contains a list of Linux distributions available via the Internet as well as mail order.
How can you decide among all these distributions? If you have access to Usenet news, or another computer conferencing system, you might want to ask there for opinions from people who have installed Linux. Even better, if you know someone who has installed Linux, ask him for help and advice. In actuality, most of the popular Linux distributions contain roughly the same set of software, so the distribution you select is more or less arbitrary.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Distributions of Linux
Because Linux is free software, no single organization or entity is responsible for releasing and distributing the software. Therefore, anyone is free to put together and distribute the Linux software, as long as the restrictions in the GPL are observed. The upshot of this is that there are many distributions of Linux, available via anonymous FTP or mail order.
You are now faced with the task of deciding on a particular distribution of Linux that suits your needs. Not all distributions are alike. Many of them come with just about all the software you'd need to run a complete system — and then some. Other Linux distributions are "small" distributions intended for users without copious amounts of disk space.
You might also want to consider that distributions have different target groups. Some are meant more for businesses, others more for the home user. Some put more emphasis on server use, others on desktop use.
The Linux Distribution HOWTO contains a list of Linux distributions available via the Internet as well as mail order.
How can you decide among all these distributions? If you have access to Usenet news, or another computer conferencing system, you might want to ask there for opinions from people who have installed Linux. Even better, if you know someone who has installed Linux, ask him for help and advice. In actuality, most of the popular Linux distributions contain roughly the same set of software, so the distribution you select is more or less arbitrary.
If you don't have Internet access, you can get many Linux distributions via mail order CD-ROM or DVD. Many distributors accept credit cards as well as international orders, so no matter where you live, you should be able to obtain Linux in this way.
Linux is free software, but distributors are allowed by the GPL to charge a fee for it. Therefore, ordering Linux via mail order might cost you between U.S. $5 and U.S. $150, depending on the distribution. However, if you know people who have already purchased or downloaded a release of Linux, you are free to borrow or copy their software for your own use. Linux distributors are not allowed to restrict the license or redistribution of the software in any way. If you are thinking about installing an entire lab of machines with Linux, for example, you need to purchase only a single copy of one of the distributions, which can be used to install all the machines. There is one exception to this rule, though: in order to add value to their distribution, some vendors include commercial packages that you might not be allowed to install on several machines. If this is the case, it should be explicitly stated on the package.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Preparing to Install Linux
After you have obtained a distribution of Linux, you're ready to prepare your system for installation. This takes a certain degree of planning, especially if you're already running other operating systems. In the following sections, we'll describe how to plan for the Linux installation.
While each release of Linux is different, in general the method used to install the software is as follows:
  1. Repartition your hard drive(s). If you have other operating systems already installed, you will need to repartition the drives in order to allocate space for Linux. This is discussed in Section 2.2.4 later in this chapter. In some distributions, this step is integrated into the installation procedure. Check the documentation of your distribution to see whether this is the case. Still, it won't hurt you to follow the steps given here and repartition your hard drive in advance.
  2. Boot the Linux installation media. Each distribution of Linux has some kind of installation media — usually a "boot floppy" or a bootable CD-ROM — that is used to install the software. Booting this media will either present you with some kind of installation program, which will step you through the Linux installation, or allow you to install the software by hand.
  3. Create Linux partitions. After repartitioning to allocate space for Linux, you create Linux partitions on that empty space. This is accomplished with the Linux fdisk program, covered in Section 3.1.3 in Chapter 3, or with some other distribution-specific program, such as the Disk Druid, that comes with Red Hat Linux.
  4. Create filesystems and swap space. At this point, you will create one or more filesystems, used to store files, on the newly created partitions. In addition, if you plan to use swap space (which you should, unless you have really huge amounts of physical memory, or RAM), you will create the swap space on one of your Linux partitions. This is covered in the sections Section 3.1.4 and Section 3.1.3, both in Chapter 3.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 3: Installation and Initial Configuration
At this point, you should have your Linux distribution and have disk space set aside for Linux. In this chapter, we present a general overview of the installation process. Each distribution has its own installation instructions, but armed with the concepts presented here, you should be able to feel your way through any installation. Appendix A, lists sources of information for installation instructions and other help, if you're at a total loss.
Different Linux distributions store files in different locations, which can make it hard to describe how to administer Linux. For instance, the same files may be found on Red Hat, SuSE, and Debian systems, but they may be under the /etc directory on one system and the /sbin directory on another. Gradually, the vendors are standardizing the set of locations listed in a document called the Filesystem Hierarchy Standard, but in this book we'll just try to deal with lagging discrepancies by listing the locations of the most important files in the version of each major distribution that we checked.
After resizing your existing partitions to make space for Linux, you are ready to install the software. Here is a brief overview of the procedure:
  1. Boot the Linux installation medium.
  2. Run fdisk under Linux to create Linux partitions.
  3. Run mke2fs and mkswap to create Linux filesystems and swap space. (You may need to use a different command than mke2fs if you want to install a different filesystem; available filesystems are listed in Section 6.1.1.)
  4. Install the Linux software and configure it.
  5. Finally, either install the LILO bootloader on your hard drive, or create a boot floppy in order to boot your new Linux system.
As we have said, most of these steps are likely to be automated for you by the installation procedure (or at least integrated into it), depending on the distribution of Linux you are using. Please consult your distribution's documentation for specific instructions.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Installing the Linux Software
After resizing your existing partitions to make space for Linux, you are ready to install the software. Here is a brief overview of the procedure:
  1. Boot the Linux installation medium.
  2. Run fdisk under Linux to create Linux partitions.
  3. Run mke2fs and mkswap to create Linux filesystems and swap space. (You may need to use a different command than mke2fs if you want to install a different filesystem; available filesystems are listed in Section 6.1.1.)
  4. Install the Linux software and configure it.
  5. Finally, either install the LILO bootloader on your hard drive, or create a boot floppy in order to boot your new Linux system.
As we have said, most of these steps are likely to be automated for you by the installation procedure (or at least integrated into it), depending on the distribution of Linux you are using. Please consult your distribution's documentation for specific instructions.
The first step is to boot the Linux installation medium. In most cases, this is either a boot floppy, which contains a small Linux system, or a bootable CD-ROM. Upon booting the floppy or the CD-ROM, you are presented with an installation menu of some kind that leads you through the steps of installing the software. On other distributions, you are presented with a login prompt when booting this floppy. Here, you usually log in as root or install to begin the installation process.
The documentation that comes with your particular distribution will explain what is necessary to boot Linux from the installation medium.
Most distributions of Linux use a boot floppy that allows you to enter hardware parameters at a boot prompt to force hardware detection of various devices. For example, if your SCSI controller is not detected when booting the floppy, you will need to reboot and specify the hardware parameters (such as I/O address and
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Post-Installation Procedures
After you have completed installing the Linux software, you should be able to reboot the system, log in as root, and begin exploring the system. (Each distribution has a different method for doing this; follow the instructions given by the distribution.)
Before you strike out on your own, however, there are some tasks you should do now that may save you a lot of grief later. Some of these tasks are trivial if you have the right hardware and Linux distribution; others may involve a little research on your part, and you may decide to postpone them.
In order to start using your system, you need to create a user account for yourself. Eventually, if you plan to have other users on your system, you'll create user accounts for them as well. But before you begin to explore you need at least one account.
Why is this? Every Linux system has several preinstalled accounts, such as root. The root account, however, is intended exclusively for administrative purposes. As root you have all kinds of privileges and can access all files on your system.
However, using root can be dangerous, especially if you're new to Linux. Because there are no restrictions on what root can do, it's all too easy to mistype a command, inadvertently delete files, damage your filesystem, and so on. You should log in as root only when you need to perform system administration tasks, such as fixing configuration files, installing new software, and so on. See Section 5.1 in Chapter 5 for details.
For normal usage, you should create a standard user account. Unix systems have built-in security that prevents users from deleting other users' files and corrupting important resources, such as system configuration files. As a regular user, you'll be protecting yourself from your own mistakes. This is especially true for users who don't have Unix system administration experience.
Many Linux distributions provide tools for creating new accounts. These programs are usually called
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Running into Trouble
Almost everyone runs into some kind of snag or hang-up when attempting to install Linux the first time. Most of the time, the problem is caused by a simple misunderstanding. Sometimes, however, it can be something more serious, such as an oversight by one of the developers or a bug.
This section will describe some of the most common installation problems and how to solve them. It also describes unexpected error messages that can pop up during installations that appear to be successful.
In general, the proper boot sequence is:
  1. After booting from the LILO prompt, the system must load the kernel image from floppy. This may take several seconds; you know things are going well if the floppy drive light is still on.
  2. While the kernel boots, SCSI devices must be probed for. If you have no SCSI devices installed, the system will "hang" for up to 15 seconds while the SCSI probe continues; this usually occurs after the line:
    lp_init: lp1 exists (0), using polling driver
    appears on your screen.
  3. After the kernel is finished booting, control is transferred to the system bootup files on the floppy. Finally, you will be presented with a login prompt, or be dropped into an installation program. If you are presented with a login prompt such as:
    Linux login:
    you should then log in (usually as root or install — this varies with each distribution). After you enter the username, the system may pause for 20 seconds or more while the installation program or shell is being loaded from floppy. Again, the floppy drive light should be on. Don't assume the system is hung.
When attempting to boot the installation medium for the first time, you may encounter a number of problems. Note that the following problems are not related to booting your newly installed Linux system. See Section 3.3.4 for information on these kinds of pitfalls.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 4: Basic Unix Commands and Concepts
If you've come to Linux from Windows or another non-Unix operating system, you have a steep learning curve ahead of you. We might as well be candid on this point. Unix is a world all its own.
In this chapter, we're going to introduce the rudiments of Unix for those readers who have never had exposure to this operating system. If you are coming from Microsoft Windows or other environments, the information in this chapter will be absolutely vital to you. Unlike other operating systems, Unix is not at all intuitive. Many of the commands have seemingly odd names or syntax, the reasons for which usually date back many years to the early days of this system. And, although many of the commands may appear to be similar to their counterparts in the Windows command-line interpreter, there are important differences.
Dozens of other books cover basic Unix usage. You should be able to go to the computer section of any chain bookstore and find at least several of them on the shelf. (A few we like are listed in the Bibliography.) However, most of these books cover Unix from the point of view of someone sitting down at a workstation or terminal connected to a large mainframe, not someone who is running his own Unix system on a personal computer. A popular introduction to Unix usage that also covers Linux is Learning the Unix Operating System by Grace Todino, John Strang, and Jerry Peek, published by O'Reilly.
Also, these books often dwell upon the more mundane aspects of Unix: boring text-manipulation commands, such as awk, tr, and sed, most of which you will never need unless you start doing some serious Unix trickery. In fact, many Unix books talk about the original ed line editor, which has long been made obsolete by vi and Emacs. Therefore, although many of the Unix books available today contain a great deal of useful information, many of them contain pages upon pages of humdrum material you couldn't probably care less about at this point.
Instead of getting into the dark mesh of text processing, shell syntax, and other issues, in this chapter we strive to cover the basic commands needed to get you up to speed with the system if you're coming from a non-Unix environment. This chapter is far from complete; a real beginner's Unix tutorial would take an entire book. It's our hope that this chapter will give you enough to keep you going in your adventures with Linux, and that you'll invest in a good Unix book once you have a need to do so. We'll give you enough Unix background to make your terminal usable, keep track of jobs, and enter essential commands.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Logging In
Let's assume that your installation went completely smoothly, and you are facing the following prompt on your screen:
Linux login:
Many Linux users are not so lucky; they have to perform some heavy tinkering when the system is still in a raw state or in single-user mode. But for now, we'll talk about logging into a functioning Linux system.
Logging in, of course, distinguishes one user from another. It lets several people work on the same system at once and makes sure that you are the only person to have access to your files.
You may have installed Linux at home and are thinking right now, "Big deal. No one else shares this system with me, and I'd just as soon not have to log in." But logging in under your personal account also provides a certain degree of protection: your account won't have the ability to destroy or remove important system files. The system administration account (covered in the next chapter) is used for such touchy matters.
If you connect your computer to the Internet, even via a modem, make sure you set nontrivial passwords on all your accounts. Use punctuation and strings that don't represent real words or names.
Note that some distributions install a so-called graphical login manager right away, so you might not be greeted by the somewhat arcane login: prompt in white letters on black background, but with a fancy graphical login screen, possibly even presenting you with the user accounts available on your system as well as different modes to log into. The basic login procedure is the same as described here, however; you still type your username and password.
You were probably asked to set up a login account for yourself when you installed Linux. If you have such an account, type the name you chose at the Linux login: prompt. If you don't have an account yet, type root because that account is certain to exist. Some distributions may also set up an account called install or some other name for fooling around when you first install the system.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Setting a Password
If you don't already have a password, we recommend you set one. Just enter the command passwd. The command will prompt you for a password and then ask you to enter it a second time to make sure you enter it without typos.
There are standard guidelines for choosing passwords so that they're hard for other people to guess. Some systems even check your password and reject any that don't meet the minimal criteria. For instance, it is often said that you should have at least six characters in the password. Furthermore, you should mix uppercase and lowercase characters or include characters other than letters and digits.
To change your password, just enter the passwd command again. It prompts you for your old password (to make sure you're you) and then lets you change it.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Virtual Consoles
As a multiprocessing system, Linux gives you a number of interesting ways to do several things at once. You can start a long software installation and then switch to reading mail or compiling a program simultaneously.
Most Linux users, when they want this asynchronous access, will employ the X Window System. But before you get X running, you can do something similar through virtual consoles. This feature appears on a few other versions of Unix, but is not universally available.
To try out virtual consoles, hold down the left Alt key and press one of the function keys, F1 through F8. As you press each function key, you see a totally new screen complete with a login prompt. You can log in to different virtual consoles just as if you were two different people, and you can switch between them to carry out different activities. You can even run a complete X session in each console. The X Window System will use the virtual console 7 by default. So if you start X and then switch to one of the text-based virtual consoles, you can go back again to X by typing Alt-F7. If you discover that the Alt-+ function key combination brings up an X menu or some other function instead of switching virtual consoles, use Ctrl + Alt + function key.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Popular Commands
The number of commands on a typical Unix system is enough to fill a few hundred reference pages. And you can add new commands too. The commands we'll tell you about here are just enough to navigate and to see what you have on the system.
As with Windows, and virtually every modern computer system, Unix files are organized into a hierarchical directory structure. Unix imposes no rules about where files have to be, but conventions have grown up over the years. Thus, on Linux you'll find a directory called /home where each user's files are placed. Each user has a subdirectory under /home. So if your login name is mdw, your personal files are located in /home/mdw. This is called your home directory. You can, of course, create more subdirectories under it.
If you come from a Windows system, the slash (/) as a path separator may look odd to you because you are used to the backslash (\). There is nothing tricky about the slash. Slashes were actually used as path separators long before people even started to think about MS-DOS or Windows. The backslash has a different meaning on Unix (turning off the special meaning of the next character, if any).
As you can see, the components of a directory are separated by slashes. The term pathname is often used to refer to this slash-separated list.
What directory is /home in? The directory named /, of course. This is called the root directory. We have already mentioned it when setting up filesystems.
When you log in, the system puts you in your home directory. To verify this, use the "print working directory" or pwd command:
$ pwd 
/home/mdw
The system confirms that you're in /home/mdw.
You certainly won't have much fun if you have to stay in one directory all the time. Now try using another command, cd , to move to another directory:
$ cd /usr/bin 
$ pwd 
/usr/bin 
$ cd
            
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Shells
As we said before, logging into the system in console mode puts you into a shell. If your system is configured with a graphical login, logging in brings you to the graphical interface where you can open an xterm (or similar) window in order to get a shell. The shell interprets and executes all your commands. Let's look a bit at different shells before we keep going, because they're going to affect some of the material coming up.
If it seems confusing that Unix offers many different shells, just accept it as an effect of evolution. Believe us, you wouldn't want to be stuck using the very first shell developed for Unix, the Bourne shell. While it was a very powerful user interface for its day (the mid-1970s), it lacked a lot of useful features for interactive use — including the ones shown in this section. So other shells have been developed over time, and you can now choose the one that best suits your way of working.
Some of the shells available on Linux are:
bash
Bourne Again shell. The most commonly used (and most powerful) shell on Linux. POSIX-compliant, compatible with Bourne shell, created and distributed by the GNU project (Free Software Foundation). Offers command-line editing, history substitution, and Bourne shell compatibility.
csh
C shell. Developed at Berkeley. Mostly compatible with the Bourne shell for interactive use, but has a very different interface for programming. Does not offer command-line editing, although it does have a sophisticated alternative called history substitution. On Linux, csh is just another name for the newer tcsh.
ksh
Korn shell. Perhaps the most popular on Unix systems generally, and the first to introduce modern shell techniques (including some borrowed from the C shell) into the Bourne shell. Compatible with Bourne shell. Offers command-line editing.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Useful Keys and How to Get Them to Work
When you type a command, pressing the Backspace key should remove the last character. Ctrl-U should delete the line from the cursor to the beginning of the line, thus this key combination will delete the whole line if the cursor is at the end of the line. When you have finished entering a command, and it is executing, Ctrl-C should abort it, and Ctrl-Z should suspend it. (When you want to resume the suspended program, enter fg for "foreground.")
Ctrl-S stops the terminal output until you turn it off again with Ctrl-Q. This is probably less useful today, as most terminal emulations provide scrolling facilities anyway, but it's important to know if you have hit Ctrl-S by accident and the terminal all of a sudden "becomes unresponsive." Just hit Ctrl-Q to make it respond again; it was just waiting for you.
If any of these keys fail to work, your terminal is not configured correctly for some reason. You can fix it through the stty command. Use the syntax:
stty function 
            key
         
where function is what you want to do, and key is the key that you press. Specify a control key by putting a circumflex (^) in front of the key.
Here is a set of sample commands to set up the functions described earlier:
$ stty erase ^H 
$ stty kill ^U 
$ stty intr ^C 
$ stty susp ^Z
         
The first control key shown, ^H, represents the ASCII code generated by the Backspace key.
By the way, you can generate a listing of your current terminal settings by entering stty -a. But that doesn't mean you can understand the output: stty is a complicated command with many uses, some of which require a lot of knowledge about terminals.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Typing Shortcuts
If you've been following along with this tutorial at your terminal, you may be tired of typing the same things over and over again. It can be particularly annoying when you make a mistake and have to start over again. Here is where the shell really makes life easier. It doesn't make Unix as simple as a point-and-click interface, but it can help you work really fast in a command environment.
This section discusses command-line editing. The tips here work if your shell is bash, ksh, tcsh, or zsh. Command-line editing treats the last 50 or so lines you typed as a buffer in an editor. You can move around within these lines and change them the way you'd edit a document. Every time you press the Return key, the shell executes the current line.
First, let's try something simple that can save you a lot of time. Type the following, without pressing the Return key:
$ cd /usr/inc
            
Now press the Tab key. The shell will add lude to complete the name of the directory /usr/include. Now you can press the Return key, and the command will execute.
The criterion for specifying a filename is "minimal completion." Type just enough characters to distinguish a name from all the others in that directory. The shell can find the name and complete it — up to and including a slash, if the name is a directory.
You can use completion on commands too. For instance, if you type:
$ ema
            
and press the Tab key, the shell will add the cs to make emacs (unless some other command in your path begins with ema).
What if multiple files match what you've typed? If they all start with the same characters, the shell completes the word up to the point where names differ. Beyond that, most shells do nothing. bash has a neat enhancement: if you press the Tab key twice, it displays all the possible completions. For instance, if you enter:
$ cd /usr/l
            
and press the Tab key twice,
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Filename Expansion
Another way to save time in your commands is to use special characters to abbreviate filenames. You can specify many files at once by using these characters. This feature of the shell is sometimes called "globbing."
The Windows command-line interpreter offers a few crude features of this type. You can use a question mark to mean "any character" and an asterisk to mean "any string of characters." Unix provides these wildcards too, but in a more robust and rigorous way.
Let's say you have a directory containing the following C source files:
$ ls 
inv1jig.c   inv2jig.c   inv3jig.c   invinitjig.c   invpar.c
To list the three files containing digits in their names, you could enter:
$ ls inv?jig.c 
inv1jig.c   inv2jig.c   inv3jig.c
The shell looks for a single character to replace the question mark. Thus, it displays inv1jig.c, inv2jig.c, and inv3jig.c, but not invinitjig.c because that name contains too many characters.
If you're not interested in the second file, you can specify the ones you want using brackets:
$ ls inv[13]jig.c 
inv1jig.c   inv3jig.c
If any single character within the brackets matches a file, that file is displayed. You can also put a range of characters in the brackets:
$ ls inv[1-3]jig.c 
inv1jig.c   inv2jig.c   inv3jig.c
Now we're back to displaying all three files. The hyphen means "match any character from 1 through 3, inclusive." You could ask for any numeric character by specifying 0-9, and any alphabetic character by specifying [a-zA-Z]. In the latter case, two ranges are required because the shell is case-sensitive. The order used, by the way, is that of the ASCII character set.
Suppose you want to see the init file, too. Now you can use an asterisk because you want to match any number of characters between the inv and the jig:
$ ls inv*jig.c 
inv1jig.c   inv2jig.c   inv3jig.c   invinitjig.c
The asterisk actually means "zero or more characters," so if a file named
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Saving Your Output
System administrators (and other human beings too) see a lot of critical messages fly by on the computer screen. It's often important to save these messages so that you can scrutinize them later, or (all too often) send them to a friend who can figure out what went wrong. So, in this section, we'll explain a little bit about redirection, a powerful feature provided by Unix shells. If you come from Windows, you have probably seen a similar, but more limited, type of redirection in the command-line interpreter there.
If you put a greater-than sign (>) and a filename after any command, the output of the command will be sent to that file. For instance, to capture the output of ls, you can enter:
$ ls /usr/bin > ~/Binaries
         
A listing of /usr/bin will be stored in your home directory in a file named Binaries. If Binaries had already