Finally! You’re Ready to Work
We wrap up this chapter with a little advice about hand-to-hand combat with the shell. You can give many commands to your shell. Every shell has about a dozen built-in commands, most of which aren’t very useful on a day-to-day basis. All the other commands are the names of other programs. The fact that every UNIX system has hundreds of programs lying around translates into hundreds of possible shell commands.One nice thing about UNIX shells is that, within a given shell, the way you type commands is completely consistent. If you want to edit a file called my-calendar , for example, and use an editor called e , you type this line:$ e my-calendar
Tip Ending command lines without hard feelings
Remember to end every command line by pressing Enter. UNIX is pretty dumb; in most cases, your pressing Enter is the only way UNIX can tell that you have finished doing something.With a few programs, notably the text editors vi , pico , and emacs , you don’t need to press Enter anywhere; we point out those exceptions. Everywhere else, remember to press the Enter key at the end of every line.
Now you know which kind of UNIX you are using, which shell you are using, and why you care. In the following sections, we show you a few UNIX (or shell) commands you can use to begin getting something done.As always, press Enter at the end of the line to tell the shell you have finished. The shell runs the e editor, which does whatever it does. When you finish, you return to the shell, where you can issue another command.Whenever you see a UNIX prompt (either $ or % ), a shell is running, waiting to do your bidding. Throughout this book, we usually refer to the entire package — UNIX plus shell — as UNIX. We say, "Use the ls command to get UNIX to display a list of files" rather than "Use the ls command to get the shell to get UNIX to display a list of files." Okay?
We could tell you the password, but then we’d have to kill you
When you logged in, you probably hated your password because someone else picked it. Hating your password is a good reason to change it. Another reason you may want to change it is that, to get this far, you enlisted the aid of some sort of expert and had to reveal your password. This section shows how to change your password: Use the passwd command.This stuff is easy. Just type this line:
passwd
As always, press Enter after typing the command. The passwd command asks you to type your current password to make sure that you are really you. (If it didn’t check, whenever you wandered off to get some more coffee, someone could sneak over to your desk and change your password. Not good.) Type your current password and press Enter. The password doesn’t appear on-screen as you type, in case someone is looking over your shoulder.
Then passwd asks for your new password. (Chapter 1 has lots of sage advice about how to choose a password.) You have to type the new password twice so that passwd is sure that you typed it correctly. Assuming that you type the new password twice in the same way, passwd changes your password. The next time you log in, you are expected to know it.Warning If you forget your password, you have no way to retrieve it; not even your system administrator can tell you what it is. The administrator can assign you a new one, though, and you can change it again, preferably to something more memorable than the one you forgot.
What’s my file?
This section discusses a command you use frequently: the ls command, which lists your files. Chapters 5 and 6 talk more about files, directories, and other stuff ls helps you with; for now, here’s ls Lesson 1. Type the following line (we’re not telling you to press Enter anymore because we know that you have the hang of it):
ls
The ls command lists the names of the files in the current directory. (Chapter 6 talks about directories.)
Oops!
If you are a world-class typist, you can skip this section. If you make thousands of typos a day, as we do, pay close attention. If you type something wrong, you can probably press the Backspace key to back up and retype it. If that doesn’t work, though, all is not lost. Try the Delete key, the # key (Shift-3), or Ctrl+H. One of these combinations should work to back you up.To give up and start the entire line over again (not usually necessary with nice, short commands, such as ls ), press Ctrl+U. If that doesn’t work, press the @ key (Shift+2).
Warning Don’t turn off the computer if you make a typo!
To repeat something we have hinted at: If you make a mistake and all is not going well, do not turn off the computer, unplug it, or otherwise get unnecessarily rough. Although PC users get used to just turning the darned thing off if things aren’t going well, UNIX computers don’t respond well to this approach.Instead, suggest politely to UNIX that it stop doing whatever it is you don’t like. To stop a command, press Ctrl+C, or, on some systems, the Break key or the Delete key.If the situation is out of control, UNIX is running a program you don’t want, and you can’t get it to stop, you can use some Advanced and Obscure Techniques to wrestle extremely recalcitrant programs into line. See Chapter 24 if you’re desperate.
Play it again, Sam
Sometimes, you may want to issue the same command again (because it was so much fun the first time). If you use the C shell, type this line:
!!
If you use the BASH shell, press the up-arrow key to see the last command you typed and then press Enter.In the Korn shell, you can type this line to reissue a command:
r
If you use the Bourne shell, you’re out of luck and must type your command again.
Everything you want to know about typing commands — but are afraid to ask
This list shows a wrap-up of what to do when UNIX displays a prompt (either $ or % ) and you want to type a command:
As you type, the cursor moves along to indicate where you are. The cursor looks like an underline or a box.
If you make a typing mistake, press Backspace (or try Delete, #, or Ctrl+H).
To cancel the entire command before you press Enter, press Ctrl+U (or try @).
When you finish typing a command, press Enter. (If you don’t, UNIX — and you — wait forever.)
If you issue a command that UNIX (actually, the shell) doesn’t know, you see a message like this:
blurfle: Command not found.
This message means that you typed the command wrong, you typed a command that UNIX doesn’t know (maybe a DOS command crept in), or someone hasn’t told UNIX the right places to look for programs.
Don’t stick extra spaces in the middle of commands, as in pass wd. Type the command exactly as we show it. On the other hand, do type a space after the name of the command but before any additional information you have to type on the line (read more about that subject in Chapter 5). Also, do not capitalize except where you know that the command has a capital letter.
You know that a command resembles a sentence, but you don’t end it with a period. UNIX doesn’t like the period, and UNIX is extremely unforgiving.
Tip The UNIX cast of special characters
One of the more exciting aspects of typing shell commands is that many characters are special. They have special meanings to UNIX; the next few chapters discuss some of them. Special characters include the ones in this list:
< | > | ‘ | “ | * |
{ | } | ^ | ! | \ |
[ | ] | # | | | & |
( | ) | $ | ? | ~ |
Spaces also are considered special because they separate words in a command. If you want to put special characters in a command, you must quote them. You quote something by putting quotation marks around it. Suppose that you have a file called c* (not a great idea, but sometimes you get these things by mistake). You can edit it by typing
e "c*"
You can use either single or double quotation marks, as long as you’re consistent. You can even quote single quotation marks with double quotation marks and quote double quotation marks with single quotation marks. Is that clear? Never mind.