home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeLearning the Unix Operating SystemSearch this book

Chapter 1. Getting Started

Before you can use Unix, a system staff person has to set up a Unix account for you. The account is identified by your username, which is usually a single word or an abbreviation. Think of this account as your office--it's your place in the Unix environment. Other users may also be at work on the same system. At many sites, there will be a whole network of Unix computers. So in addition to knowing your username, you may also need to know the hostname (name) of the computer that has your account. Alternatively, your account may be shared between all computers on the local network, and you may be able to log into any of them.

Once you've logged in to your account, you'll interact with your system by typing commands at a command line, to a program called a shell. You'll get acquainted with the shell, enter a few commands, and see how to handle common problems. To finish your Unix session, you'll log out.

1.1. Working in the Unix Environment

Each user communicates with the computer from a terminal. To get into the Unix environment, you first connect to the Unix computer. (Your terminal is probably already connected to a computer.[1] But Unix systems also let you log into other computers across a network. In this case, log into your local computer first, then use a remote login command to connect to the remote computer. See Section 6.1 in Chapter 6.)

[1] Some terminals can connect to many computers through a kind of switchboard called a port contender or data switch. On these terminals, start by telling the port contender which computer you want to connect to.

After connecting your terminal, if needed, you start a session by logging in to your Unix account. To log in, you need your username and a password. Logging in does two things: it identifies which user is in a session, and it tells the computer that you're ready to start work. When you've finished, log out--and, if necessary, disconnect from the Unix computer.

WARNING: If someone else has your username and password, they probably can log into your account and do anything you can. They can read private information, corrupt or delete important files, send email messages as if they came from you, and more. If your computer is connected to a network--the Internet or a local network inside your organization--intruders may also be able to log in without sitting at your keyboard! See Section 6.1 in Chapter 6 for one explanation of one way this can be done.

Anyone may be able to get your username--it's usually part of your email address, for instance. Your password is what keeps others from logging in as you. Don't leave your password anywhere around your computer. Don't give your password to anyone who asks you for it unless you're sure they'll preserve your account security. Also don't send your password by email; it can be stored, unprotected, on other systems and on backup tapes, where other people may find it and then break into your account.

If you suspect that someone is using your account, ask system staff for advice. If you can't do that, setting a new password may help; see Section 3.6 in Chapter 3.

Unix systems are case sensitive. Most usernames, commands, and filenames use lowercase letters (though good passwords use a mixture of lower- and uppercase letters). Before you log in, be sure your CAPS LOCK key is off.

1.1.2. Logging in Nongraphically

The process of making yourself known to the computer system and getting to your Unix account is called logging in. If you've connected to the Unix host from another operating system, you may have been logged into Unix automatically; in this case, you should be able to run Unix programs, as shown later in this chapter in Section 1.1.4 and Section 1.1.5. Otherwise, before you can start work, you must connect your terminal or terminal window to the computer you need (as in the previous section) and identify yourself to the Unix system.

There are generally two ways to log in: graphically and nongraphically. If your screen has a window or windows floating in it, something like Figure 2-2A, you probably need to log in graphically, as explained by Section 2.2.1 in Chapter 2.

Otherwise, to log in nongraphically, enter your username (usually your name or initials) and your private password. The password does not appear as you enter it.

When you have logged in successfully, you'll get some system messages and finally the shell prompt (where you can enter Unix commands). A successful login to the system named nutshell could look like Example 1-1.

In this example, the system messages include a maintenance notice, a "fortune," and the date. Although this example doesn't show it, you may be asked for your terminal type, accounting or chargeback information, and so on. The last line to appear is the Unix shell prompt. When you reach this point, you're logged in to your account and can use Unix commands.

Instead of a shell prompt, you may get a menu of choices ("email," "news," and so on). If one choice is something like "shell prompt" or "command prompt," select it. Then you'll be able to follow descriptions and examples in this book.

The messages you see at login time differ from system to system and day to day. Shell prompts can also differ. Examples in this book use the currency sign $ as a prompt.

Let's summarize logging in nongraphically, step by step:

  1. If needed, connect your terminal or terminal window to the Unix system.

  2. Get a "login:" prompt.

  3. Type in your username in lowercase letters at the prompt. For example, if your login name is "john," type:

    login: john
    

    Press the RETURN key.

    The system should prompt you to enter your password. If passwords aren't used on your system, you can skip the next step.

  4. If you were assigned a password, type it at the prompt. For security, your password is not displayed as you type it:

    Password:
    

    Press the RETURN key.

The system checks your account name and password, and if they're correct, logs you in to your account.

1.1.2.1. Problem checklist

Nothing seemed to happen after I logged in.
Wait a minute, since the system may just be slow. If you still get nothing, ask other users if they have the same problem.

The system says "login incorrect."
If you have a choice of computer to log into (as we explained at the start of this chapter in Section 1.1), check that you're connected to the right computer. If you have accounts on several computers, be sure you're using the correct username and password for this computer. Otherwise, try logging in again, taking care to enter the username and password correctly. Be sure to type your username at the "login:" prompt and your password at the "password:" prompt. Backspacing may not work while entering either of these; if you make a mistake, use RETURN to get a new "login:" prompt and try again. Also make sure to use the exact combination of upper- and lowercase letters your password contains.

If you still fail after trying to log in a few more times, check with the person who created your account to confirm your username and password.

All letters are in UPPERCASE and/or have backslashes (\) before them.
You probably entered your username in uppercase letters. Type exit at the shell prompt and log in again.

1.1.4. Shells in a Window System

If you're using a window system, as described in Chapter 2, get a shell by opening a terminal window--if you don't already have a terminal window open or iconified (minimized) somewhere, that is. (Figure 2-1 shows an example, but yours may look different; the important thing is that the window have a shell prompt in it.) Check your menus and icons for a command with "terminal" or "term" in its name, or a picture of a blank terminal (like a TV screen) in its icon; one common program is xterm.

1.1.6. Entering a Command Line

Entering a command line at the shell prompt tells the computer what to do. Each command line includes the name of a Unix program. When you press RETURN, the shell interprets your command line and executes the program.

The first word that you type at a shell prompt is always a Unix command (or program name). Like most things in Unix, program names are case sensitive; if the program name is lowercase (and most are), you must type it in lowercase. Some simple command lines have just one word, which is the program name. For more information, see Section 1.2, later in this chapter.

1.1.6.2. who

Another simple command is who. It displays a list of each logged-on user's username, terminal number, and login time. Try it now, if you'd like.

The who program can also tell you who is logged in at your terminal. The command line is who am i. This command line consists of the command (who, the program's name) and arguments (am i). (Arguments are explained in Section 1.2, later in this chapter.)

$ who am i
cactus!john     tty23   Oct  6 08:26      (rose)

The response shown in this example says that:

  • "I am" John (actually, my username is john).

  • I'm logged on to the computer named "cactus."

  • I'm using terminal 23.

  • I logged in at 8:26 on the morning of October 6.

  • I started my login from another computer named "rose."

Not all versions of who am i give the same information.

1.1.8. Correcting a Command Line

What if you make a mistake in a command line? Suppose you typed dare instead of date and pressed the RETURN key before you realized your mistake. The shell will give you an error message:

$ dare
dare: command not found
$

Don't be too concerned about getting error messages. Sometimes you'll get an error even if it appears that you typed the command correctly. This can be caused by typing control characters that are invisible on the screen. Once the prompt returns, reenter your command.

As we said earlier (in Section 1.1.7) most modern shells let you recall previous commands and edit command lines. If you'll do a lot of work at the shell prompt, it's worth learning these handy techniques. They take more time to learn than we can spend here, though--except to mention that, on those shells, the left-arrow and right-arrow keys may move your cursor along the command line to the point where you want to make a change. Here, let's concentrate on simple methods that work with all shells.

If you see a mistake before you press RETURN, you can use the erase character to erase and correct the mistake.

The erase character differs from system to system and from account to account, and can be customized. The most common erase characters are:

CTRL-H is called a control character. To type a control character (for example, CTRL-H), hold down the CTRL key, then press the letter "h." In the text, we will write control characters as CTRL-H, but in the examples, we will use the standard notation: ^H. This is not the same as pressing the ^ (caret) key, letting go, and then typing an H!

The key labeled DEL may be used as the interrupt character instead of the erase character. (It's labeled DELETE or RUBOUT on some terminals.) This key is used to interrupt or cancel a command, and can be used in many (but not all) cases when you want to quit what you're doing. Another character often programmed to do the same thing is CTRL-C.

Other common control characters are:

CTRL-U
Erases the whole input line; you can start over.

CTRL-S
Pauses output from a program that's writing to the screen. This can be confusing; we don't recommend using CTRL-S, but want you to be aware of it.

CTRL-Q
Restarts output after a pause by CTRL-S.

CTRL-D
Used to signal end-of-input for some programs (such as cat and mail, explained in Chapter 5 and Chapter 6) and return you to a shell prompt. If you type CTRL-D at a shell prompt, it may close your terminal window or log you out of the Unix system.

Find the erase and interrupt characters for your account and write them here:

_______ Backspace and erase a character

_______ Interrupt a program

1.1.9. Logging Out

To end a Unix session, you must log out. You should not end a session by just turning off your terminal!

If you're using a window system, first close open windows and then close the window system; see Section 2.9 in Chapter 2 for more information. If you logged in graphically, that should end your login session. But, if you logged in nongraphically before you started the window system, closing the window system should take you back to a shell prompt (where you originally typed xinit or startx). In that case, use the following steps to finish logging out.

If you aren't currently using a window system, you can log out by entering the command exit at a shell prompt. (In many cases, the command logout will also work.) Depending on your shell, you may also be able to log out simply by typing CTRL-D.

What happens next depends on the place from which you've logged in: if your terminal is connected directly to the computer, the "login:" prompt should appear on the screen. Otherwise, if you were connected to a remote computer, the shell prompt from your local computer should reappear on your screen. (That is, you're still logged in to your local computer.) Repeat the process if you want to log out from the local computer.

After you've logged out, you can turn off your terminal or leave it on for the next user. But, if the power switch for your terminal is the same as the power switch for the whole Unix computer system, do not simply turn off that power switch! Ask a local expert for help with shutting down your Unix system safely.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.