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


Learning the Unix Operating System

Learning the Unix Operating SystemSearch this book
Previous: Acknowledgments Chapter 1 Next: 1.2 Syntax of UNIX Command Lines
 

1. Getting Started

1.1 Working in the UNIX Environment

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.

1.1.1 Connecting to the UNIX Computer

If you turn on your terminal and see a message from the UNIX computer that looks something like this:

login:

you can probably skip ahead to the section "Logging In" 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.)

1.1.1.1 Connecting from another operating system

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.

1.1.1.2 Connecting with a data switch

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.

1.1.1.3 Connecting from a window system

If you have an X terminal or a workstation, you should read the introductory sections of Chapter 2, Using Window Systems to help you find the right steps for logging in.

1.1.2 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: 

john


Password:
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:

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

  2. If you don't have a "login:" prompt, press the [RETURN] key a few times until you see that prompt on the screen.

  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 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.

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 don't get anything, ask other users if they're having the same problem.

The system says "login incorrect".

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.

All letters are in UPPERCASE and/or have backslashes ( \ ) before them.

You probably entered your username in uppercase letters. Type exit and log in again.

1.1.3 Remote Logins

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:

program-name remote-hostname

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:

login: 

jennifer


Password: 

NOTICE to all second-floor MDs: meeting in room 304 at 4 PM.

fuzzy% 

telnet biolab.medu.edu



Medical University Biology Laboratory

biolab.medu.edu login: 

jdnelson


Password:

biolab%
	.
	.
	.
biolab% 

exit


Connection 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, Reading List ( UNIX Power Tools , for example), will show you how to add it.

1.1.4 The UNIX Shell

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.

1.1.5 The Shell Prompt

When the system finishes running a command, the shell replies with a prompt to tell you that you can enter another command line.

Shell prompts usually contain $ or % . The prompt can be customized, though, so your own shell prompt may be different.

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 (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.

1.1.6.1 date

An example single-word command line is date . Entering the command date displays the current date and time:

% 

date


Tue 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.

1.1.6.2 who

Another simple command is who . It lists each logged-on user's username, terminal number, and login time.

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 ). (The section "Syntax of UNIX Command Lines," later in this chapter, explains arguments.)

% 

who am i


cactus!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.

1.1.7 Correcting a Mistake

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.

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.

If you see a mistake before you press [RETURN] , you can use the [BACKSPACE] key to erase the mistake and put in the correction.

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

  • [BACKSPACE]

  • [DELETE] , [DEL] , or [RUBOUT] key

  • [CTRL-H]

[CTRL-H] is called a control character . To type a control character (for example, [CTRL-H] , hold down the [CTRL] key while pressing the letter "h". (This is like the way you make an uppercase letter: hold the [SHIFT] key while pressing a letter key.) 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] .

Some other common control characters are:

[CTRL-U]

Erases the whole input line; you can start over.

[CTRL-S]

Pauses output from a program that is writing to the screen.

[CTRL-Q]

Restarts output after a pause by [CTRL-S] .

[CTRL-D]

Used to signal end-of-input for some programs (like cat and mail ; see Chapter 3, Your UNIX Account ) 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.

1.1.8 Logging Out

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.

1.1.8.1 Problem checklist

The first few times you use UNIX, you aren't likely to have any of the following problems. However, you may have these problems later, as you start doing more advanced work.

You get another shell prompt or the system says ": not login shell."

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.

The system says "There are stopped jobs."

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, Multitasking .)


Previous: Acknowledgments Learning the Unix Operating System Next: 1.2 Syntax of UNIX Command Lines
Acknowledgments Book Index 1.2 Syntax of UNIX Command Lines

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System