Harley Hahn's Guide to
Introduction to Unix
This book is about using Unix: a family of operating systems that are used throughout the world and that run on virtually all types of computers. This book is also about Linux, a type of Unix.
We'll talk about the details in Chapter 2. For now, all you have to know is that an operating system is a master control program that runs a computer.
There are many types of Unix: some are Linux; some aren't. As a general rule, all types of Unix are similar enough so that, for practical purposes, if you know how to use one type of Unix, you know how to use them all.
The first Unix system was developed in 1969 by a programmer at AT&T's Bell Labs so that he could run a program called Space Travel(*). Today, Unix is nothing less than a worldwide culture, comprising many tools, ideas and customs.
Space Travel simulated the movements of the Sun and planets, as well as a spaceship that you could land in various locations. The programmer in question was Ken Thompson who, with various other people at AT&T's Bell Labs, went on to develop the first full-fledged Unix operating system (presumably, after they got tired of playing Space Travel).
Modern Unix in its entirety is very large and complicated. Indeed, there is no single person who knows everything about Unix in general or even everything about one specific type of Unix. In fact, there is no single person who knows even most of Unix.
I realize this might seem strange. After all, if Unix is that complex, how did it come to exist at all? Who creates and enhances Unix? And who changes it and fixes problems when things go wrong?
I'll answer these questions in Chapter 2, when we talk a bit about the history of Unix and about how Unix is maintained today.
For now, what I want you to appreciate is that Unix is much more than an operating system: it is nothing less than a culture. So as you read this book and think about what you are learning, realize that you are doing more than simply learning how to use yet another computer tool. You are becoming a member of the global Unix/Linux community, the largest collection of smart people in the history of the world.
If you have never used Unix before, you are in for some pleasant surprises. Unix is not easy to learn, but it is well-designed, extremely powerful, and — once you get used to it — a great deal of fun.
As with all computer systems, there will be times when you are puzzled by a problem whose solution is not obvious. There will also be times when you will be frustrated or discouraged. However, no matter what happens, I can promise you one thing: you will never be bored.
The Unix culture, which you are about to enter, contains an enormous number of tools for you to learn about and use. You can create and manipulate information text files, documents, images, music, video, databases, spreadsheets, and so on in more ways than you can imagine; you can access the Internet to use the Web, email, file transfer, and discussion groups; you can play games; you can design your own Web pages and even run your own Web server; and you can write computer programs using a variety of different languages and programming tools.
Of course, you can do all these things using other operating systems, such as Windows, so why learn Unix?
There are lots of reasons but, at this point, they will seem rather technical, so let me give the four most important reasons to learn Unix.
The first is choice. With Unix, you will decide how you want to use your computer and how deep you want to get into the details. You are not stuck with using your computer the way anyone else (such as Microsoft or Apple or your mother) thinks you should use it. You can customize your system as you see fit, and you can choose from many well-designed tools and applications.
Second, using Unix will change how you think, and for the better. I believe that if you learn how to read Shakespeare, listen to Mozart, or appreciate the paintings of Van Gogh, you will, in some sense, be a better person. The same is true for learning how to use Unix.
At this point, I don't blame you if you don't believe me, but when you have finished the book, come back to this chapter, reread this section, and see if I am not right.
Third, as a member of the global Unix community, you will learn how to use some of the best tools ever invented by human beings.
In addition, you will be working with a computer system that can run for months without rebooting. You won't have to worry about your computer crashing, freezing or stopping unexpectedly, and unless you are administering a large network you won't need to care about such irritations as computer viruses, spyware, programs that run amok, or mysterious rituals that must be carried out to keep your computer running smoothly.
Finally, if you are a programmer (or if you want to learn how to be a programmer), you will find a wonderful selection of Unix-based tools to develop, test and run programs: text editors with language-specific plugins, script interpreters, compilers, cross-compilers, debuggers, emulators, parser generators, GUI builders, software configuration managers, bug-tracking software, build managers, and documentation tools. Moreover, for most types of programming, there are active communities with their own Web sites, mailing lists and discussion groups, as well as comprehensive software archives.
Of course, I can't teach you all the details of the Unix culture in one book. If I tried, both of us would be overwhelmed. Rather, I will teach you the basics. By the time you finish this book, you will understand the most important concepts, and you will be able to use the most important tools. You will also be able to teach yourself whatever else you want to know as the need arises. To start, all you need is access to any computer that runs some type of Unix (such as Linux), an Internet connection, and a lot of time and patience.
And, oh yes, one more thing: in most cases, everything including software upgrades is free.
Around the world, the first language of Unix is American English. Nevertheless, Unix systems and documentation have been translated into many other languages, so it is not necessary to know English, as long as your system works in your language. However, as you explore the worldwide Unix-based community, you will find that much of the information and many of the discussion groups are in English.
In addition, the Unix community has introduced many new words of its own. In this book, I will pay particular attention to such words. Every time I introduce a new word, I will use CAPITAL LETTERS. I will make sure to explain the word and show you how it is used. For easy reference, all the definitions are collected into a glossary at the end of the book.
When I come to a name with a particularly colorful history, I will give a special explanation like this.
What's in a Name?
In the 1960s, a number of researchers from Bell Labs (a part of AT&T) worked at MIT on a project called Multics, an early time-sharing operating system. Multics was a collaborative effort involving programmers from MIT, GE and Bell Labs. The name Multics was an acronym for "Multiplexed Information and Computing Service". ("Multiplex" refers to combining multiple electronic signals into a single signal.)
By the late 1960s, the management at Bell Labs decided not to pursue Multics and moved their researchers back into the lab. In 1969, one of these researchers, Ken Thompson, developed a simple, small operating system for a minicomputer. In searching for a name, Thompson compared his new system to Multics.
The goal of Multics was to offer many features to multiple users at the same time. Multics was large and unwieldy and had many problems.
Thompson's system was smaller, less ambitious and (at least at the beginning) was used by one person at a time. Moreover, each part of the system was designed to do only one thing and to do it well. Thompson decided to name his system Unics (the "Uni" meaning "one", as in unicycle), which was soon changed to Unix.
In other words, the name Unix is a pun on the name Multics.
Throughout the book, I print certain names in boldface, usually the names of commands. This allows you to see immediately that a word is a special Unix term. Here is an example:
"To copy a file, you use the Unix cp command. To remove (delete) a file, you use the rm command."
As you read this book, you will notice many hints for learning Unix. These are ideas and shortcuts I have found to be important for newcomers and experienced users alike. To emphasize these hints, I present them in a special format that looks like this:
Unix is fun.
What type of person uses Unix?
Taken literally, there is no definitive answer to this question. Unix systems are used by a vast number of people around the world, so it would be very difficult to generalize. However, that never stopped me, so let's have a go at it.
Broadly speaking, we can divide the world of Unix users into two parts: those who know they are using Unix and those who don't.
Most of the people who use Unix don't know they are doing so. This is because Unix is used with many different types of computer systems, and those systems work so well that the people using them aren't even aware they are using Unix.
For example, most Web servers run some type of Unix. When you visit Web sites, more often than not you are using Unix, at least indirectly. Unix is also used by many businesses, schools, and organizations. When you have occasion to use their computer systems, say, to make a reservation, look up information, control a machine, register for a class, or do office work, you are also using Unix without even knowing it.
In addition, Unix is used to run all kinds of machines: not only computers of all sizes (from the largest mainframes to the smallest handheld devices), but the so-called "embedded" or "real-time" systems: appliances, cable modems, cell phones, robots, karaoke machines, cash registers, and so on.
Finally, most of the machines that support the Internet run Unix. For example, the computers that pass data from one point to another (routers) all use some type of Unix, as do most mail servers (which store email) and Web servers (which send out Web pages). Once you understand Unix, a lot of the idiosyncrasies that you find while using the Net will make sense. For example, you will understand why you must pay attention to case that is, small letters and capital letters when you type Web addresses. (As I mentioned, most Web servers run under some type of Unix and, as you will see, Unix is case sensitive.)
To me, the most interesting group of people who use Unix without knowing it is the Macintosh users. Millions of people using a Mac with OS X have no idea that, underneath, OS X is actually based on a type of Unix called FreeBSD. (We'll talk more about OS X in Chapter 2.) This is why Macs are so reliable, especially when compared to PCs running Windows (which is definitely not based on Unix).
What about the people who do know that they are running Unix? In other words, what type of person voluntarily chooses to learn Unix?
In my experience, such people (like you and I) have four basic characteristics.
First, Unix people are smarter than average, in most cases, a lot smarter than average.
Second, Unix people are both lazy and industrious. They don't like to do busy work for no reason, but when they have a problem that interests them, they will work hour after hour looking for a solution.
Third, Unix people like to read. In a world in which most people have trouble mustering up an attention span longer than five minutes, Unix people will actually read the manual when they have a problem.
Finally, when Unix people use a computer, they want to be in control of the experience; they don't want to feel as if the computer is controlling them.
Are you wondering about yourself? If so, don't worry. The fact that you are reading this book and have got this far qualifies you as a Unix person.
I have designed this book to make it easy for you to find what you need quickly. Before you start, take a moment to examine the various parts of the book. (I know when I say that, most of you won't want to do it, but please do it anyway.)
First, look at the Quick Index of Unix Commands on the inside back cover. This is a list of the most important commands covered in the book and where to look for the discussion and examples.
Next, take a look at the glossary. This will give you an overview of the important concepts I will be teaching you in this book. Notice there is a lot to learn.
Third, take a glance at the Quick Index for the vi Text Editor. Once you learn how to use the program (Chapter 22), you will find this index especially helpful.
Now take a look at the general index. Spend a few minutes skimming it (always a good idea with a new book). This will give a rough feeling for the new ideas you will be meeting and what I will be emphasizing.
Aside from the glossary and the indexes, there are two summaries of Unix commands, also at the back of the book. These summaries contain one-line descriptions of each command I cover in the book.
One summary lists the commands in alphabetical order; the other summary groups the commands by category. These summaries are a good place to check if you want to do something and are not sure what command to use. Once you have found your command, check with the Quick Index of Unix Commands (inside back cover) to see what page to read.
If you want to find the discussion of a particular topic, you can, of course, use the general index. Alternatively, you can look up the appropriate term in the glossary. Along with each definition, you will find a reference to the chapter in which that term is explained. Once you know the chapter you want, a quick look at the table of contents will show you what section to read.
In this book, I make two important assumptions as to what type of Unix system you are using.
First, as you will see in Chapter 2, there are many versions of Unix. Today, the most popular Unix systems are of a type called Linux. Most Unix systems contain the same basic elements so, for the most part, it doesn't matter what type of Unix you are using. However, at times, there will be a choice between Linux or non-Linux functionality. In such cases, I will lean toward the Linux conventions as these are the most popular.
Second, as you will see in Chapter 4, the program that reads and interprets the commands you type is called the "shell". In Chapter 11, I will explain that there are various shells you might choose to use. Almost all the time, it doesn't really matter what shell you use. However, in those few places where it does matter, I will use a particular shell named "Bash". If you want to use another shell, that is fine. A few details may be different, but you won't have any real problems.
If you are an experienced computer user who wants to learn about Unix, this book will get you started and provide you with a firm background in all the important areas.
However, I do not assume that you have any prior experience. It's okay if you have never really used a computer. You do not need to know anything about Unix. You do not need to be a programmer, nor do you need to know anything about electronics or mathematics.
I will explain everything you need to know. Work at your own speed and enjoy yourself.
Before we start, it is important to realize that the world of Unix is bursting with information. To get started, read the first seven chapters of the book. They will introduce you to Unix and teach you the basic skills.
It is impossible to learn everything about Unix. Concentrate on what you need and what you think you will enjoy.
After you are oriented to Unix, and you know how to start and stop a work session, enter commands, and use the keyboard, you can read the rest of the book in any order you want.
Although every effort has been made to make each chapter as independent as possible, you should realize that each topic is dependent on other topics. There is no perfect place to start learning Unix and no perfect order in which to study the various topics.
For example, say that you want to customize your work environment. Naturally, it would make sense to start by reading about the Unix working environment (Chapter 6). You then need to understand what we call the "shell" (Chapter 11), as well as the details of using the shell (Chapters 12, 13 and 14). At this point, you can customize your work environment by modifying certain files.
However, in order to modify files, it is handy to already know how to use a text editing program (Chapter 22). Since you need to save these files, you should already understand the file system (Chapter 23), the commands to display your files (Chapter 21), and the commands to manipulate your files (Chapters 24 and 25). And, of course, before you can type in messages, you need to understand how to start a work session (Chapters 4 and 5) and how to use the keyboard with Unix (Chapter 7).
Obviously, this sort of approach leads nowhere fast, but it does underscore the most important principle that you need to understand at the outset: Unix was not designed to be learned; Unix was designed to be used. In other words, it can be confusing and time-consuming to learn Unix. However, once you have mastered the skills you need for whatever work you want to do, working with Unix is fast and easy.
If you think back to when you learned how to drive a car, you will remember that it was anything but simple. Once you had some experience, though, your actions became smooth and automatic. By now, you can probably drive all day with one hand on the wheel as you listen to the radio and talk to other people.
Let us embody this idea as the following hint:
Unix is easy to use, but difficult to learn.
Remember, once you have read the first few chapters of this book, you can teach yourself any topic in any order. If you come across an idea or skill you do not yet understand, you can either pause for a quick look at another chapter, or skip the part that confuses you and learn it later. This is how people learn Unix in real life: a bit at a time, depending on what they need at the moment.
Don't worry about memorizing every detail. In some chapters, I treat topics in depth. Learn what seems interesting and useful to you and just skim the rest. If you know the basics and you have an idea as to what is available, you can always return to the details when you need them.
Start by learning the basics. Then learn whatever you want, in whatever order you want.
Review Question #1:
When was the first Unix system developed? Where was the work done?
Review Question #2:
What are four important reasons to learn Unix?
Review Question #3:
What is the origin of the name "Unix"?
For Further Thought #1:
Prior to 2001, the operating system used by Apple for Macintosh desktop computers was completely proprietary. In 2001, Apple introduced a new operating system (OS X) based on Unix. What are three advantages to changing to a Unix-based operating system? What are three disadvantages?
© All contents Copyright 2023, Harley Hahn