Learning Red Hat Linux [With 2 CDROMs]by Bill McCarty
The Linux success story is well known: firmly established as an operating system in widespread use, its worldwide installations are still increasing at phenomenal rates. Much of this success has been on the server side, but more and more PC users are turning to Linux on the desktop, as well. For those grounded in Microsoft Windows or older versions of Apple's
The Linux success story is well known: firmly established as an operating system in widespread use, its worldwide installations are still increasing at phenomenal rates. Much of this success has been on the server side, but more and more PC users are turning to Linux on the desktop, as well. For those grounded in Microsoft Windows or older versions of Apple's Macintosh OS, the first look at Unix-style operating system can be daunting. Learning Red Hat Linux provides a clear, no-nonsense introduction to the popular Red Hat distribution of Linux.The third edition of Learning Red Hat Linux will ease into the world of Linux, guiding you through the process of installing and running Red Hat Linux on your PC. Written in a friendly, easy-to-understand style, this book contains all you need to get started, including the complete Red Hat 8.0 distribution on CDs. With new tutorials covering OpenOffice Tools and the desktop, this book is excellent for first-time Linux users who want to install the operating system on a new PC or convert an existing system to Linux.Highlights of the book include:
- Preparing your system for installing Linux
- Installing and configuring your Linux system and the two popular desktop environments, GNOME and KDE
- Linux fundamentals: understanding the basic concepts
- Using Linux productivity tools like Open Office
- Configuring and administering a multi-user Linux system
- Connecting to the Internet
- Burn CDs and sync a PalmPilot
- Setting up a networked workstation
- Setting up Internet services
- Understand and write shell scripts so you can peek under the hood and extend the power of Linux
- O'Reilly Media, Incorporated
- Publication date:
- Edition description:
- Third Edition
- Product dimensions:
- 7.08(w) x 9.24(h) x 0.90(d)
Read an Excerpt
Chapter 13: Advanced Shell Usage and Shell ScriptsLike an MS-DOS Prompt window, the Unix shell is a command interpreter that lets you issue and execute commands. By means of the shell, you use and control your system. If you're accustomed to the point-and-click world of graphical user interfaces, you may question the value of learning to use the Linux shell. Many users initially find the shell cumbersome, and some retreat to the familiar comfort of the graphical user interface (GUI), avoiding the shell whenever possible. However, as this chapter explains, the shell unlocks the true power of Linux.
The Power of the Unix ShellWhile it's true that the shell is an older style of interacting with a computer than the GUI, the graphical user interface is actually the more primitive interface. The GUI is easy to learn and widely used, but the shell is vastly more sophisticated. Using a GUI is somewhat like communicating in American Indian sign language. If your message is a simple one, like "We come in peace," you can communicate it by using a few gestures. However, if you attempted to give Lincoln's Gettysburg address--a notably short public discourse--you'd find your task quite formidable.1
The designer of a program that provides a GUI must anticipate all the possible ways in which the user will interact with the program and provide ways to trigger the appropriate program responses by means of pointing and clicking. Consequently, the user is constrained to working only in predicted ways. The user is therefore unable to adapt the GUI program to accommodate unforeseen tasks and circumstances. In a nutshell, that's why many system administration tasks are performed using the shell: system administrators, in fulfilling their responsibility to keep a system up and running, must continually deal with and overcome the unforeseen.
The shell reflects the underlying philosophy of Unix, which provides a wide variety of small, simple tools (that is, programs), each performing a single task. When a complex operation is needed, the tools work together to accomplish the complex operation as a series of simple operations, one step at a time. Many Unix tools manipulate text, and since Unix stores its configuration data in text form rather than in binary form, the tools are ideally suited for manipulating Unix itself. The shell's ability to freely combine tools in novel ways is what makes Unix powerful and sophisticated. Moreover, as you'll learn, the shell is extensible: you can create shell scripts that let you store a series of commands for later execution, saving you the future tedium of typing or pointing and clicking to recall them.
The contrary philosophy is seen in operating systems such as Microsoft Windows, which employ elaborate, monolithic programs that provide menus, submenus, and dialog boxes. Such programs have no way to cooperate with one another to accomplish complex operations that weren't anticipated when the programs were designed. They're easy to use so long as you remain on the beaten path, but once you step off the trail, you find yourself in a confusing wilderness.
Of course, not everyone shares this perspective. The Usenet newsgroups, for example, are filled with postings debating the relative merits of GUIs. Some see the Unix shell as an arcane and intimidating monstrosity. But, even if they're correct, it's inarguable that when you learn to use the shell, you begin to see Unix as it was intended (whether that's for better or for worse).
When you are performing common, routine operations, a GUI that minimizes typing can be a relief, but when faced with a complex, unstructured problem that requires a creative solution, the shell is more often the tool of choice. Creating solutions in the form of shell scripts allows solutions to be stored for subsequent reuse. Perhaps even more important, shell scripts can be studied to quickly bone up on forgotten details, expediting the solution of related problems.
Filename GlobbingBefore the shell passes arguments to an external command or interprets a built-in command, it scans the command line for certain special characters and performs an operation known as filename globbing. Filename globbing resembles the processing of wildcards used in MS-DOS commands, but it's much more sophisticated. Table 13-1 describes the special characters used in filename globbing, known as filename metacharacters.
In filename globbing, just as in MS-DOS wildcarding, the shell attempts to replace metacharacters appearing in arguments in such a way that arguments specify filenames. Filename globbing makes it easier to specify names of files and sets of files.
For example, suppose the current working directory contains the following files: file1, file2, file3, and file04. Suppose you want to know the size of each file. The following command reports that information:
ls -l file1 file2 file3 file04
However, the following command reports the same information and is much easier to type:
ls -l file*
As Table 13-1 shows, the * filename metacharacter can match any string of characters. Suppose you issued the following command:
ls -l file?
The ? filename metacharacter can match only a single character. Therefore, file04 would not appear in the output of the command.
Similarly, the command:
ls -l file[2-3]
would report only file2 and file3, because only these files have names that match the specified pattern, which requires that the last character of the filename be in the range 2-3.
You can use more than one metacharacter in a single argument. For example, consider the following command:
ls -l file??
This command will list file04, because each metacharacter matches exactly one filename character.
Most commands let you specify multiple arguments. If no files match a given argument, the command ignores the argument. Here's another command that reports all four files:
ls -l file0* file[1-3]
TIP: Suppose that a command has one or more arguments that include one or more metacharacters. If none of the arguments matches any filenames, the shell passes the arguments to the program with the metacharacters intact. When the program expects a valid filename, an unexpected error may result.
The tilde (~) metacharacter lets you easily refer to your home directory. For example, the following command:
would list the files in your home directory.
Filename metacharacters don't merely save you typing. They let you write scripts that selectively process files by name. You'll see how that works later in this chapter.
Shell AliasesShell aliases make it easier to use commands by letting you establish abbreviated command names and by letting you prespecify common options and arguments for a command. To establish a command alias, issue a command of the form:
where command specifies the command for which you want to create an alias and name specifies the name of the alias. For example, suppose you frequently type the MS-DOS command dir when you intend to type the Linux command ls -l. You can establish an alias for the ls -l command by issuing this command:
alias dir='ls -l'
Once the alias is established, if you mistakenly type dir, you'll get the directory listing you wanted instead of the default output of the dir command, which resembles ls rather than ls -l. If you like, you can establish similar aliases for other commands.
Your default Linux configuration probably defines several aliases on your behalf. To see what they are, issue the command:
If you're logged in as root, you may see the following aliases:
alias cp='cp -i' alias dir='ls -l' alias ls='ls --color' alias mv='mv -i' alias rm='rm -i'
Notice how several commands are self-aliased. For example, the command rm -i is aliased as rm. The effect is that the - i option appears whenever you issue the rm command, whether or not you type the option. The - i option specifies that the shell will prompt for confirmation before deleting files. This helps avoid accidental deletion of files, which can be particularly hazardous when you're logged in as root. The alias ensures that you're prompted for confirmation even if you don't ask to be prompted. If you don't want to be prompted, you can issue a command like:
rm -f files
where files specifies the files to be deleted. The - f option has an effect opposite that of the - i option; it forces deletion of files without prompting for confirmation. Because the command is aliased, the command actually executed is:
rm -i -f files
The - f option takes precedence over the - i option, because it occurs later in the command line.
If you want to remove a command alias, you can issue the unalias command:
where alias specifies the alias you want to remove. Aliases last only for the duration of a login session, so you needn't bother to remove them before logging off. If you want an alias to be effective each time you log in, you can use a shell script, which we'll discuss later in the chapter....
Meet the Author
Bill McCarty is associate professor of management information systems in the School of Business and Management of Azusa Pacific University, Azusa, California, and was previously associate professor of computer science, in which capacity he taught for ten years in Azusa Pacific's Master of Applied Computer Science program. Bill holds a Ph.D. in the management of information systems from the Claremont Graduate University, Claremont, California, and worked for 15 years as a software developer and manager.
and post it to your social network
Most Helpful Customer Reviews
See all customer reviews >
The book is outdated. McCarty discusses installing Red Linux 6.0 on a machine supposedly running Windows versions prior to XP. Since XP uses NTFS (New Technology File System as opposed to FAT, FAT16, or FAT32), you shouldn't use Windows utilities to partition the hard-drive, as McCarty instructs his readers to do, since the partition cannot be read in Red Hat Linux. So, assuming a hard-drive partition on a machine running Windows XP, the reader is own his/her own from the very beginning. While the rest of the book is helpful, it doesn't discuss the most recent release of Red Hat Linux. I found the tutorials, how-tos, and online manuals that redhat.com provides to be more helpful than the book.
This book is a nice 'user's guide' to Red Hat Linux. Red Hat is probably the most popular version of Linux, although readers who use other Linux' operating systems can also glean lots of valuable information from this book. Written in the usual O'Reilly style, the book is easy to follow and features lots of figures that show how different screens should look for example, during install procedures, or what the X-Window screen should look like or even what various Linux applications or games should look like. Chapters in the book take on topics like installing Linux and X-Windows, Linux applications, games, setting up Linux-based LANs and WANs, and connecting to the Internet. The appendixes describe the Linux 'directory tree,' main files, a Linux command quick reference and a detailed appendix about the Red Hat Package Manager tool. Anyone with a familiarity with Unix knows Linux is quite similar. In fact, I'd forgotten about that, so reading about Linux seemed extra familiar to me. However, even Linux novices shouldn't have too much trouble following the instructions and information here. Truly a very informative book.
Thanks to a recommendation from fellow MCP, CCNA, and Linux expert Ronnie Gonzalez, I bought this book to learn Linux. I just started reading it and goes great with the included Red Hat Linux on CD. O'Reilly books are great!