Before you can start using UNIX, your system administrator has to set up a UNIX account for you. 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 account name, you may also need to know the hostname (name) of the computer that has your account.
Each user communicates with the computer from a terminal or a window. To get into the UNIX environment, you first connect to the UNIX computer. (You may have a terminal that’s already connected to the computer.) Next, you start a session by logging in to your UNIX account. Logging in does two things: it identifies which user is in a session, and it tells the computer that you’re ready to start working. When you’ve finished working, you log out—and, if necessary, disconnect from the UNIX computer.
you can probably skip ahead to Section 1.1.2 later in this chapter. Otherwise, browse through the next few sections and find the one that applies to you. (We can’t cover every user’s situation exactly. If none of these suggestions helps you enough, ask another UNIX user or your system administrator.)
If you’re using a personal computer to connect to the UNIX system, you’ll probably need to start a terminal emulation program. Some common programs are procomm, qmodem, kermit, minicom, and telnet. (There are lots of others.)
If you start the program and get a UNIX “login:” prompt, you’re ready to log in. But if your screen stays blank or you get another message that you don’t understand, check with another user or your system administrator for help.
Your office may have a data switch, a port contender, or another system that allows you to select which computer you will connect to. Like a telephone switchboard, this connects your terminal to one of a number of computers. Enter your computer’s hostname or code number at the prompt—or choose from the menu of hosts.
If you have an X terminal or a workstation, you should read the introductory sections of Chapter 2 to help you find the right steps for logging in.
The process of making yourself known to the UNIX computer system and getting to your UNIX account is called logging in. Before you can start work, you must connect your terminal or window to the UNIX computer (see the previous sections). Then log in to UNIX and identify yourself. To log in, enter your username (usually your name or initials) and a private password. The password does not appear on the screen as you enter it.
When you log in successfully, you will get some system messages and finally the UNIX shell prompt (where you can enter UNIX commands). A successful login to the system named nutshell would look something like this:
O'Reilly & Associates, Inc. nutshell.oreilly.com: Solaris UNIX version 2.5 login:
johnPassword: Last login: Mon Nov 3 14:34:51 EST 1997 from joe_pc ------------- NOTICE TO ALL USERS ----------------- The hosts nutshell, mongo and cruncher will be down for maintenance from 6 to 9 PM tonight. --------------------------------------------------- My opinions may have changed, but not the fact that I am right. Tue Nov 4 12:24:48 EST 1997 %
In this example, the system messages include 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 start using UNIX commands.
Instead of a shell prompt, you may get a menu of choices (“email,” “news,” and so on). If one of the choices is something like “shell prompt” or “command prompt,” select it. Then you’ll be able to follow the descriptions and examples in this book.
The messages that appear when you log in differ from system to system
and day to day.
The shell prompt also differs.
The examples in this book use the percentage sign as a prompt (
Let’s summarize logging in, step by step:
If needed, connect your terminal or window to the UNIX system.
If you don’t have a “login:” prompt, press the RETURN key a few times until you see that prompt on the screen.
Type in your username in lowercase letters at the prompt. For example, if your login name is “john,” type:
The system should prompt you to enter your password. If passwords aren’t used on your system, you can skip the next step.
If you were assigned a password, type it at the prompt. For security, your password is not displayed as you type it:
Press the RETURN key after you finish typing your password.
The system verifies your account name and password, and, if they’re correct, logs you in to your account.
Wait a minute, since the system may just be slow. If you still don’t get anything, ask other users if they’re having the same problem.
Try logging in again, taking care to enter the correct name and password. 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 your system administrator to make sure you’re using the right username and password for your account.
\) before them.
You probably entered your username in uppercase letters. Type exit and log in again.
The computer you log in to may not be the computer you need to use. For instance, you might have a workstation on your desk but need to do some work on the main computer in another building. Or you might be a professor doing research with a computer at another university.
Your UNIX system can probably connect to another computer to let you work as if you were sitting at the other computer. To do this, you first log in to your local computer. Then you start a program on your local computer that connects to the remote computer. Some typical programs are telnet and rlogin (for connecting over a computer network) as well as cu and tip (for connecting through telephone lines using a modem). You use the remote system until you’re done; when you log off the remote computer, the remote-login program quits, and then returns you to your local computer.
The syntax for most remote-login programs is:
For example, if Dr. Nelson wanted to connect to the remote computer named biolab.medu.edu, she’d log in to her local computer (named fuzzy) first. Next, she’d use the telnet program to reach the remote computer. Her session might look something like this:
jenniferPassword: NOTICE to all second-floor MDs: meeting in room 304 at 4 PM. fuzzy%
telnet biolab.medu.eduMedical University Biology Laboratory biolab.medu.edu login:
jdnelsonPassword: biolab% . . . biolab%
exitConnection closed by foreign host. fuzzy%
Her accounts have shell prompts that include the hostname. This reminds her when she’s logged in remotely. If you use more than one system but don’t have the hostname in your prompt, references in Appendix A (UNIX Power Tools, for example), will show you how to add it.
Once you’ve logged in, you’re working with a program called a shell. The shell interprets the commands you enter, runs the program you’ve asked for, and generally coordinates what happens between you and the UNIX operating system. Common shells include Bourne (sh), Korn (ksh), and C (csh) shells, as well as bash and tcsh.
For a beginner, the differences between most shells are slight. If you plan to do a lot of work with UNIX, though, ask your system administrator which shell your account uses; you should learn more about your shell and its set of special commands.
Shell prompts usually contain
%. The prompt can
be customized, though, so your own shell prompt may be different.
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 (program name). Like most things in UNIX, command names are case-sensitive; if the command name is lowercase (and most are), you must type it in lowercase. Some simple command lines have just one word: the command name.
dateTue Nov 4 13:39:24 EST 1997 %
As you type a command line, the system simply collects your input from the keyboard. Pressing the RETURN key tells the shell that you have finished entering text and that it can start executing the command.
The who command can also tell you who is logged in at the terminal you’re using. The command line is who am i. This command line consists of the command (who) and arguments (am i). (Section 1.2 later in this chapter, explains arguments.)
who am icactus!john tty23 Nov 6 08:26 (rose)
The response shown in this example says that:
“I am” 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 November 6.
I started my login from another computer named “rose.”
Not all versions of who am i give the same information.
daredare: 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.
Most modern shells let you recall previous commands and edit command lines. If you’ll be doing 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. Ask other users for help or read a reference book for your shell (see Appendix A). We’ll concentrate on simple methods that work with all shells.
DELETE, DEL, or RUBOUT key
is called a control character.
To type a control character (for example,
hold down the
key while pressing the letter “h”.
(This is like the way you make an uppercase letter:
key while pressing a letter key.) In the text, we will write control
but in the examples, we will use the standard notation:
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.
Some other common control characters are:
Erases the whole input line; you can start over.
Pauses output from a program that is writing to the screen.
Restarts output after a pause by CTRL-S.
Used to signal end-of-input for some programs (like cat and mail; see Chapter 3) and return you to a shell prompt. If you type CTRL-D at a shell prompt, it may also log you out of the UNIX system.
Find the erase and interrupt characters for your account and write them down:
_______ Backspace and erase a character
_______ Interrupt a command
In Chapter 3, we’ll tell you how to change these characters if you like.
To end a UNIX session, you must log out. You should not end a session by just turning off your terminal! To log out, enter the command exit. (In many cases, the command logout will also work.) Depending on your shell, you may also be able to log out 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.
If you’re using a window system, the window will probably close. If you have additional windows open, you’ll need to log out or close them, too. You may also need to terminate the window system itself. (See Chapter 2.)
If you were connected to a remote computer, the system 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.
You’ve been using a subshell (a shell created by your original login shell). To end each subshell, type exit (or just type CTRL-D until you’re logged out.
Many UNIX systems have a feature called job control that lets you suspend a program temporarily while it’s running. One or more of the programs you ran during your session has not ended, but is stopped (paused). Enter fg to bring each stopped job into the foreground, then quit the program normally. (See Chapter 6.)