< Zurück | Inhalt | Weiter >

Part I

Getting Started

Chapter 1

An Embarrassment of Riches: The Linux Environment


The reader is introduced to the vast possibilities of the Linux command line, and excuses are made for its eclecticism.



Some basic shell commands are described in this chapter, especially those relat- ed to some common programming tasks. Used as a toolkit, they can be a handy collection of tools for everyday use.

Linux provides an incredible array of such tools, useful for any develop- ment effort, Java or otherwise. They will be important not only for the develop- ment of your Java code, but for all the hundreds of related housekeeping tasks associated with programming and with managing your development environ- ment. A few tools are described briefly in this chapter, to hint at what can be done and to whet your appetite for more.

We will also describe a command which will help you learn about other commands. Even so, it may be quite worth your while to have another book about UNIX/Linux handy. If there is something you, as a programmer, need


to do on a Linux system, chances are there is already a command (or a sequence of commands) which will do it.

Finally, we will discuss the extent of our remaining ignorance upon finishing the chapter.

Let us take a moment to explain that last comment. As readers of comput- er books ourselves, we are often frustrated when we discover how lightly a topic has been covered, but particularly so when other parts of the same book are found to fully explore their topics. When only some parts of a book are thor- ough, you often don’t know that you don’t know it all. We will introduce some basic shell concepts and commands here, and we may expand on some of these in later chapters, but each of our chapters covers topics that could each fill its own book. Therefore we need to leave out lots of material. We will also let you know when we have left things out because they are off-topic, or because we don’t have room. We’ll also try to tell you where to look for the rest of the knowledge. We try to sum this up in a final section of each chapter entitled What You Still Don’t Know. But we do have a lot of information to impart, so let’s get going.


One of the revolutionary things that UNIX (and thus Linux) did was to sepa- rate operating system commands from the operating system itself. The com- mands to display files, show the contents of directories, set permissions, and so on were, in the “olden days,” an integral part of an operating system. UNIX removed all that from the operating system proper, leaving only a small “kernel” of necessary functionality in the operating system. The rest became executables that lived outside of the operating system and could be changed, enhanced, or even replaced individually by (advanced) users without modifying the operating system. The most significant of these standalone pieces was the command processor itself, called the shell.

The shell is the program that takes command-line input, decides what program(s) you are asking to have run, and then runs those programs. Before there were Graphical User Interfaces, the shell was the user interface to UNIX. As more developers began working with UNIX, different shells were developed to provide different features for usability. Now there are several shells to choose from, though the most popular is bash. Some BSD/UNIX die hards

still swear by csh, a.k.a. the C-shell, though most of its best features have been incorporated into bash.


There are actually quite a few shells to choose from, and several editors for entering text. Our recommendation: If you learn only one shell, learn bash. If you learn only one editor, learn vi. Some basic shell scripting will go a long way to eliminating mundane, repetitive tasks. Some basic vi editing will let you do things so much faster than what GUI editors support. (More on editing in Chapter 2.)


Since commands could be developed and deployed apart from the operat- ing system, UNIX and Linux have, over the years, had a wide variety of tools and commands developed for them. In fact, much of what is called Linux is really the set of GNU tools which began development as Open Source long before Linux even existed. These tools, while not technically part of the operat- ing system, are written to work atop any UNIX-like operating system and pro- grammers have come to expect them on any Linux system that they use. Some commands and utilities have changed over the years, some are much the same as they first were in the early days of UNIX.

Developers, encouraged by the openness of Open Source (and perhaps having too much free time on their hands) have continued to create new utili- ties to help them get their job done better/faster/cheaper. That Linux supports such a model has helped it to grow and spread. Thus Linux presents the first time user with a mind-boggling array of commands to try to learn. We will describe a few essential tools and help you learn about more.


There are some basic Linux commands and concepts that you should know in order to be able to move around comfortably in a Linux filesystem. Check your knowledge of these commands, and if need be, brush up on them. At the end of the chapter, we list some good resources for learning more about these and other commands. Remember, these are commands that you type, not icons for clicking, though the windowing systems will let you set up icons to represent those commands, once you know what syntax to use.

So let’s get started. Once you’ve logged in to your Linux system, regardless of which windowing system you are using—KDE, Gnome, Window Maker, and so on, start up an xterm window by running xterm (or even konsole) and you’ll be ready to type these commands.1


1.3.1 Redirecting I/O

1.3.2 The ls Command

1.3.3 Filenames

1.3.4 Permissions

1.3.5 File Copying

1.3.6 Seeing Stars

1.3.7 File Contents

1.3.8 The grep Command

1.3.9 The find Command

1.3.10 The Shell Revisited

1.3.11 The tar and zip Commands

1.3.12 The man Command