Unix Essentials Class
Introduction · Table of Contents · Unix vs. other operating systems · Getting Started · Fundamental UNIX Concepts · Unix Files · Directories · Introduction to the Korn Shell · The vi editor · Korn Shell Again · Hyper-Ad Home Page · Technical Tutoring Home Page · Recommended Books · Online StoreGetting started
Logging In · The Unix Command Line · Some basic commands · Changing a user password · Logging Out
The most irritating thing for UNIX beginners is getting started. There seems to be a lot one has to know just to use the system at all, unlike Windows where one can get away with intuition and pointing and clicking. We'll cover most of these little details in this section.
A. Logging In
The first irritation unfamiliar to Windows users is the concept of accounts. Every user of a UNIX system must log on to the computer using an existing account. Without an account (username/password) one cannot get on the system at all.
At the terminal in front of you, press the enter (return) key. You should get something like this:
This is the login prompt. You must enter the username of an existing account on the
system, then hit enter (we're going to assume from now on that hitting enter follows
typing any command). The system then immediately prompts for the password for that
Several things are worth noticing here. In the first place, when you typed in your password, the screen did not show the characters you typed. This is deliberate, and is a security feature typical of UNIX. Once you entered your password, the screen shows a dollar sign. This is called the command prompt, and means the computer is waiting for you to enter a command.
Had you logged on as the root user, you would have gotten a different
Suppose you screw up the password? Just try again!
Most systems will give you three tries to get your login right. If you mess up all three, either the terminal session locks up (requires the system administrator to intervene) or the remote access session dies, depending on how you are accessing the system. This is another deliberate security feature, one that forces most users to be careful when they are logging into a system. This feature makes guessing a password by trial and error very difficult.
Once you have logged in, you have started what is called a session. This is the interval between login and logout (exit). All work done on a UNIX computer happens during a session.
B. The Unix Command Line
As mentioned above, after you entered your password, the screen shows a
dollar sign, the command prompt. Anything you type is displayed and sent to the shell
program. If the shell recognizes what you typed, the program will perform some action (or
not - see examples below). The words you enter are called commands, and give
specific instructions to the shell. If you type nonsense, the shell tells you:
Sometimes a command will have no effect, and the result will simply be another command
prompt: This is actually good - you know you can enter another command. If you don't get a
command prompt back, the result can be confusing: Notice there is no command prompt - anything typed is just repeated, like an echo. What
has happened here is that we've invoked a program ("cat") that feeds the input
(whatever is typed) back to the output (what is written by the computer when we hit enter)
and we're still in the program! To get out of this program, hit control-D
(from now on, control <something> will be written ^<something>):
Sometimes a command will have no effect, and the result will simply be another command prompt:
This is actually good - you know you can enter another command. If you don't get a command prompt back, the result can be confusing:
Notice there is no command prompt - anything typed is just repeated, like an echo. What has happened here is that we've invoked a program ("cat") that feeds the input (whatever is typed) back to the output (what is written by the computer when we hit enter) and we're still in the program! To get out of this program, hit control-D (from now on, control <something> will be written ^<something>):
So using ^D is a way to exit a running program. In fact, you can exit the shell by hitting another ^D (but wait on this until a bit later).
C. Some basic commands
Now we can try some commands. Might as well start with the most basic:
The "whoami" command retrieves your username. This may seem trivial or silly, since you just logged in as student, but the command is surprisingly useful in a multi-user environment. One of the things UNIX operators have to do is become other users! Issuing many commands as many users can be confusing - you forget who you are, so this command is there to let you find the current user. A shorter command that returns the username plus some other info is "id":
This command returns the user id number or UID, the group id or GID of the user, and a list of all groups the user to which the user belongs.
So now we know who we are. What is the date and time?
Suppose we wanted to know who is currently logged onto the same computer?
Maybe we'd like to see this month's calendar:
Which computer am I on?
Clear the screen and put the prompt at the top:
Where am I in the filesystem?
This command stands for "present working directory" and tells you what directory you are currently in. Notice that we are in our home directory.
This is a very important and useful command - in navigating the vast UNIX filesystem, it is very common to forget where you are - so this command is there to remind you of your current location.
D. Changing a user password
To change your password, use the "passwd" command:
Make absolutely sure you remember what you typed in as your new password - you won't be able to change it back if you forget what you typed.
Let's try changing the password back to the original:
We're in trouble now - just type in the same (new) password:
Fortunately, we were able to recover. It will take the root user to override this and restore the original password. The point is security again. Most modern UNIX systems won't allow ordinary users to put in a password that is too easy to crack. There are often elaborate rules about the number of characters, how many have to be numerals, and so on - IBM has published password rules and makes you change passwords every six months or so.
Pick a good password that is easy to remember and fits the rules. One way to do this is to take a word you can easily remember that has the letters E, I and O, enough characters to satisfy the rules, and substitute 3, 1 and 0 for the above letters respectively. There are plenty of other ways to generate good passwords. It helps if your password can be typed fast, making it harder for other people to watch you type it and figure out your password.
At many work places, computer security is taken very seriously. You can get in trouble for breaking the rules, especially if some hostile person in the workplace gets your password and either uses it for mischief or gives it out to others. Never give anyone else your password! System administrators never need it, and won't ask for it. There are no good reasons to give it to anyone.
E. Logging Out
When you are done with your work, you should exit from the shell:
Exit is always available; some computers don't support ^D.
This ends your session and brings back the login prompt. If you leave the screen alone for a few minutes, it will blank out (a simple blank screen saver). Typing any key will bring up another login prompt - the shift key is often used for this, since it doesn't print any characters to the screen, although the enter key works, too.
In a multi-user environment, you should always log off if you are done or have to walk away from the computer for a few minutes. Failure to do this might very well allow some joker in your office to send your boss an embarrassing e-mail from you, destruction or alteration of your work, or other unfortunate disasters. Be advised: it is a security breach to leave an open session up on a computer. Don't do it, you'll regret it!