UNIX: The Complete Reference (2007)
Part I: Basic
Chapter 2: Getting Started
Chapter 1 gave you an overview of UNIX, including a history of the UNIX operating system and the UNIX variants available today. This chapter introduces you to the things you need to know to start using your UNIX system. In this chapter, you will learn:
§ How to access and log in to a UNIX system
§ How to select and change your password
§ How to run basic commands
§ How to communicate with other users
§ How to use a simple e-mail program
By the end of this chapter, you should be able to log in to the system, get some work done, and log out.
You can access a UNIX system in one of two general ways: either locally (that is, while sitting at the computer you are connected to), or remotely (by connecting to the computer over a network). Most of what you will learn in this book applies equally well to either case. In particular, the basic UNIX commands will work in exactly the same way Before you can start using those commands, however, you will need to know how to access your UNIX system.
To connect to a UNIX machine locally, you need to be physically at the computer. If that computer is a UNIX workstation, all you need to do is log in with your username and password. If you are using Mac OS X, you just need to run the Terminal application, available under Applications | Utilities, in order to access the UNIX command line that is built in to the operating system.
You can also run a version of UNIX, such as Linux, FreeBSD, or Solaris, on a PC. The next section describes where you can find one of these UNIX variants and how to get it running on your computer. Once it is installed, you just need to log in to the system, as on a UNIX workstation.
Installing a UNIX Variant on a PC
The process of installing a UNIX variant on a PC has become surprisingly straightforward. You will need a Pentium PC (or equally powerful machine), and you will probably want a CD-ROM drive so that you can install from a CD. Ideally, you will have a hard disk with at least 1 gigabyte free, but it is possible to run some versions of Linux (such as Knoppix) directly from the CD-ROM without installing to a hard drive at all.
You will also need to choose which UNIX variant to install. Chapter 1 discusses the different versions of UNIX that can be run on a PC. These include variants of Linux and BSD, as well as Solaris. Most of these variants can be purchased on a CD or downloaded for free. The downloads are typically in the form of an .iso file. This is a disk image that can be burned to a CD if you have a CD burner. Many of the UNIX variants listed in the next sections have guides on their web sites explaining exactly how to create an installation CD.
Once you have a CD with your UNIX variant on it, you can install by booting directly from the CD. If your computer does not boot from a CD, you have a few options. You may be able to get it to boot from a CD by changing a BIOS setting. If you are not comfortable modifying your BIOS, you can create a floppy boot disk that will allow you to install from a CD. Many of the UNIX variants have a “Getting Started” or “How to Install” section in their online documentation that explains how to do this. You could also try to find a variant that can be installed from floppy disks (such as FreeBSD, which has instructions on its web site for setting up the disks).
Once the installation program is running, you will be able to follow the directions on screen to complete the installation. The installation process will include setting up your hard drive and selecting which components of the operating system to install. You will also set up an account for system administration (often called the root account), and choose a separate login name and password for everyday use. For most of the variants listed in this chapter, this process is fairly straightforward. Even if you do not know much about installing an operating system, the installation program will suggest default settings that should work well for most users. In addition, the web sites for the UNIX variants include installation guides to step you through this process.
You can see examples of the installation process for many UNIX variants, including the versions of Linux discussed here, FreeBSD, and Solaris, at http://shots.osdir.com/. This web site, which also includes screenshots after installation is complete, can help you compare the feel of different versions before you choose which one to install.
Linux Distributions If you decide to install Linux, you should know that there is no single “official” version of Linux. Instead, there are many distributions of Linux, each produced by a different organization. In general, these distributions have more similarities than differences. The differences between distributions have to do with the target audience (beginner or advanced users), the installation process (simple or complex), the applications that are included by default (for example, which desktop environments the distribution comes with), and the package management systems (how new applications are installed). In addition, some distributions are known for being particularly up-to-date, or especially stable, or very well supported.
A good starting point for choosing a Linux distribution is http://distrowatch.com/. This web site tracks the different distributions of Linux that are currently available. For each distribution, it includes information on where to get an installation CD, or how to download the distribution so that you can create your own CD. It also has a “Major Distributions” page listing the distributions that are currently most popular, with comments indicating which are best suited for a beginning user.
At the time of this writing, these are some of the most common and highly recommended Linux distributions, according to DistroWatch:
§ Ubuntu (http://www.ubuntu.com/) is a relatively new Linux distribution, but it has become one of the most popular. Ubuntu is known for including up-to-date software and for being accessible even to new users. The variant Kubuntu includes the KDE desktop environment instead of GNOME (see Chapters 6 and 7 for information about desktop environments). Canonical, the sponsor of Ubuntu, has a policy of shipping free installation CDs on request. In addition to the installation CD, Ubuntu can be downloaded as a “Live CD” that allows you to run Ubuntu without installing it to the hard drive.
§ Xandros Desktop (http://www.xandros.com/) is highly recommended for Windows users who want to start using Linux. It is considered one of the most easy-to-use distributions for beginners. Besides the Open Circulation Edition, which can be downloaded for free, Xandros sells boxed versions of its operating system, including the Deluxe Edition, which can run Microsoft Office and certain other Windows applications.
§ Fedora Core (http://fedoraproject.org/) is sponsored by Red Hat, which is one of the most famous Linux brand names. It is one of the most widely used Linux variants, and is considered especially reliable.
§ SUSE Linux (http://www.opensuse.org/) is another very popular distribution.
§ Mandriva Linux (http://www.mandrivalinux.com/) is also popular and easy to use.
§ Debian GNU/Linux (http://www.debian.org/) is popular among advanced users, but it may be more challenging to install than the other distributions on this list. Many other Linux distributions are actually based on Debian, including Ubuntu, MEPIS, and Knoppix.
§ MEPIS Linux (http://www.mepis.org/) is a beginner-friendly distribution that can be run from a CD as well as installed on a hard drive. This allows new users to test the operating system before installing it, and to use the CD as a recovery disk if something goes wrong.
BSD Variants The BSD variants include FreeBSD, OpenBSD, and NetBSD. Of these, FreeBSD is the most popular. It can be downloaded from http://www.freebsd.org/. FreeBSD has a reputation for being a remarkably stable operating system, and is very popular for servers. It is highly compatible with Linux applications. Installing FreeBSD may be more challenging for a beginner than installing some of the Linux distributions listed above.
Solaris The Solaris 10 operating system, by Sun Microsystems, is now available as a free download. To download Solaris, go to http://www.sun.com/software/solaris/get.jsp. To buy Solaris 10 on CD for approximately $30, go to http://store.sun.com/ and click Operating Systems. Solaris is now largely open source and is mostly compatible with applications written for Linux.
When you connect to a UNIX system remotely, you are using your computer to access another system that is running UNIX. Typically, this system supports many users at once. For example, many large universities offer a UNIX account to all their students. The students log in to the system from their own computers, either through the Internet or over the university network.
In order to connect to a UNIX system like this, you will need Internet access from your own computer. (In some cases, you may be able to dial in directly to the UNIX system, but the details for how to do this depend on the specific system configuration.) You will also need a terminal emulator application. This is a program that allows you to interact with the UNIX system. Finally, you will need to know the hostname of the system you are going to connect to (for example, amber.university.edu), and your login name and password. You can get this information from the administrator of the UNIX system.
Accessing a UNIX System from a PC
Microsoft Windows comes with a terminal application called HyperTerminal. HyperTerminal allows you to use telnet to connect to a remote system. However, HyperTerminal does not support ssh, a secure method of connecting that prevents hackers from stealing your passwords or data when they are sent over the network. Many UNIX systems are configured to allow only ssh connections.
Two of the most commonly used terminal emulators for Windows are PuTTY and SecureCRT. Both of these support ssh, in addition to telnet. PuTTY is freely downloadable from http://www.chiark.greenend.org.uk/~sgtatham/putty/. SecureCRT has more features but is a commercial product. To download a trial version or buy the full version, go to http://www.vandyke.com/products/securecrt/.
When you first run your terminal application, you will need to create a new connection. Your application should explain how to do this. For example, when you run PuTTY, it automatically opens a dialog box so that you can enter your connection information. You will enter the hostname of the UNIX system, and your login name and password. Once you are connected, you will be able to enter and run commands, just as you would if you were physically at the remote computer.
Accessing a UNIX System from Mac OS X
The Terminal application in Mac OS X allows you to connect to a remote system. Just type ssh followed by the hostname of your system, as in
You will be prompted to enter your login name and password. Once you are connected, you can enter commands as though you were sitting at the remote machine.
Once you have access to your UNIX system, you will need to log in with your username and password. The UNIX operating system was designed for multiple users. Requiring each user to log in ensures that the system remains secure, and that each user’s files remain private.
Selecting a Login Name
Every UNIX system has at least one person, called the system administrator, whose job is to maintain the system. The system administrator is also responsible for adding new users to the system, and for setting up the initial work environment. If you are on a multiuser system, you will have to ask the system administrator to set up a login for you. If you are the only user on the system, you will be the system administrator. During the installation of your UNIX variant, you will be asked to select a login name and password.
In general, your login name can be almost any combination of letters and numbers, although there are a few constraints:
§ Your login name must be more than two characters long. If it is longer than eight, only the first eight characters are relevant.
§ It must contain only lowercase letters and numbers and must begin with a lowercase letter. No symbols or spaces are allowed.
§ It cannot be the same as another login name already in use. Some login names are customarily reserved for certain uses; for example, root is often a login name for the system administrator (sometimes called the superuser).
Choosing a login name is similar to choosing an e-mail address. In fact, your login name will become your e-mail address on the UNIX system. Try to pick a login name that is easy to spell and type, and that other users will associate with you. Names (nate), initials (raf), and combinations of names and initials (susanl, jfarber) are common. For example, a user named Marissa Silverman might choose marissa, msilver, mars, or mls as a login name. Of course, you could also choose something unrelated to your name, such as yoda01. Keep in mind that your login name is how you will be known on the system, so it is important to choose something that won’t become embarrassing or confusing later. In some cases the system administrator may select a login name for you.
Choosing a Password
If you begin by installing a UNIX variant on your own system, it will ask you to choose a password when you select a login name. If your account is on a remote system, your system administrator will probably assign you a temporary password, which you should change the first time you log in. UNIX places some requirements on passwords, typically including the following:
§ Passwords must have at least six characters.
§ Passwords must contain at least two alphabetic characters (uppercase or lowercase letters), and at least one number or symbol. Note that UNIX is sensitive to case, so WIZARD is a different password than w1zard.
§ Your login name with its letters reversed or shifted cannot be used as a password. For example, if your login name is msilver, you cannot choose silverm or revlism as a password.
The passwords 3hrts&3lyonz and R0wkS+@r are both valid, but kilipuppy (no numeric or special characters) and Red1 (too short) are not.
UNIX System Password Security
Your first contact with security on your UNIX system is choosing a password. Simple passwords are easily guessed. A large commercial dictionary contains about 250,000 words, which can be checked as passwords in less than two minutes of computer time. All dictionary words spelled backward takes about another minute. All dictionary words preceded or followed by the digits 0–99 can be checked in just a few more minutes. Similar lists can be used for other guesses.
Here are some guidelines:
§ Avoid easily guessed passwords, such as your name or the names of family members or pets.
§ Also avoid your address, your car’s license plate, and any other phrase that someone might associate with you.
§ Avoid words or names that exist in a dictionary (in any language, not just English).
§ Avoid trivial modifications of dictionary words. For example, normal words with replacement of certain letters with numbers: mid5umm3r, sn0wball, and so forth.
Pronounceable nonsense words can make good passwords, such as 38fizwik, 6nogbuf7, or met04ikal. These passwords are very difficult to guess, but because they can be pronounced, they are often easy for you to remember.
Resist the temptation to write your password down. In particular, do not stick it to your screen or leave it on your desk. If you have to write it down, keep it in a safe place. If someone gains access to the UNIX system with your password, they will have access to all of your work-they may even be able to find a way to access restricted parts of the system once they are logged in.
If you do forget your password, there is no way to retrieve it. Because it is encrypted, even your system administrator cannot look up your password. If you cannot remember it, the administrator will have to give you a new temporary password.
A Successful Login
When you successfully enter your login name and password, the UNIX system responds with a set of messages, similar to this:
Last login: Tues June 27 09:55:17 on tty1
* Welcome to amber! *
* Red Hat Linux release 9 (Shrike) Kernel 2.4.20–8 on an 1686 *
* Report system problems to action@amber *
* amber will be coming down on Sunday Aug 28, 2006 from *
* 8:00am until 12:00pm (noon) for system maintenance. *
* Please schedule your work accordingly. Thank you. *
You have new mail
At the top is a line that tells you when you last logged in. This is a security feature. If the time of your last login seems wrong, call your system administrator. This discrepancy could be an indication that someone has broken into the system and is using your login name.
This is followed by the message of the day (motd). Because every user has to log in, the login sequence is a natural place for your system administrator to put important messages. This sometimes includes general system information, such as the e-mail address for system problems, and often includes important announcements, such as system changes or shutdowns.
In some cases, you may also see other messages when you log in, like the line “You have mail” shown above. In Chapter 4, you will learn how to configure your account to display custom information, such as a list of other users who are currently logged in.
An Incorrect Login
If you make a mistake in typing either your login name or your password, the UNIX system will respond this way:
The system will prompt you to enter a password even if you type an incorrect login name. This prevents someone from guessing login names and learning which ones are valid by discovering the ones that yield the “Password:” prompt.
If you repeatedly type your login or password incorrectly (three to five times, depending on how your system administrator has set the default), the UNIX system may disconnect you, although you will not get locked out of your account. On some systems, the system administrator will be notified of erroneous login attempts as a security measure.
If you have problems logging in, you might check to make sure that your CAPS LOCK key has not been set. If CAPS LOCK has been turned on, you will inadvertently enter an incorrect login name or password, because in UNIX uppercase and lowercase letters are treated differently
The UNIX System Prompt
After you successfully log in, you will see the UNIX System command prompt at the far left side of the current line. The default prompt on many UNIX systems is the dollar sign:
This $ is the indication that the UNIX system is waiting for you to enter a command.
In the examples in this book, you will see the $ or other prompt at the beginning of a line as it would be seen on the screen, but you are not supposed to type it.
The default prompt may be different on your system. You may see a percent sign (%), or a string of characters, such as ~>, -bash-2.05b$, or corwin@amber:~%. The command prompt is frequently changed by users. In Chapter 4, you will learn how to customize the prompt for yourself.
On some systems, when you first log in you may be sent directly to the X Window environment. This is a graphical environment for UNIX. Chapters 6 and 7 of this book describe how to use and configure the most common versions of the X Window System.
It is also possible to set up X when you are using a remote connection to a UNIX system. To do this, you will need a tool like Cygwin/X or VNC (on a PC), or X11 (in Mac OS X). Chapter 18 has information on configuring these to run on your machine.
Many of the most powerful features of UNIX are best accessed through text commands. If you are using a graphical environment, you will need to open a terminal window to see the command prompt so that you can enter these commands. The name of the terminal program varies according to which environment you are using. One very common program is called xterm; others include konsole and gnome-terminal.
The UNIX System makes hundreds of programs available to the user. To run one of these programs you issue a command. When you type date, for example, you are really instructing the UNIX System command interpreter to execute a program with the name date, and to display the results on your screen.
The different variants of UNIX share a large common set of commands, but each variant also provides commands that are unique to that particular version of UNIX. In addition, sometimes different UNIX variants have slightly different versions of the same command-for example, the mailx command discussed later in this chapter varies slightly depending on which UNIX system you are using. The most commonly used commands, however, are typically constant across versions.
Command Options and Arguments
The UNIX System has a standardized command syntax that applies to almost all commands. Understanding these patterns makes it easier to learn new UNIX commands. Some commands are used alone, some require arguments that describe what the command is to operate on, and some provide options that let you specify certain choices. Here is an example of each type of command.
The date command is usually used alone:
Fri Apr 27 22:14:05 EDT 2007
As you can see, entering the command date prints the current day and time.
Many commands take arguments (typically filenames) that specify what the command operates on. For example, to view a file, you can type
$ cat notes
This tells the cat command to display the file notes.
Commands often allow you to specify options that influence the operation of the command. You specify options for UNIX System commands by using a minus sign followed by a letter or word. For example, the command ls by itself lists all the files in a directory If you enter
$ ls -l
the -l option says to print a long version of the list with details about each file.
Stopping a Command
You can stop a command by hitting CTRL-C. The UNIX System will halt the command and return to the system prompt. You can do this either while typing or after running a command. For example, you could use CTRL-C if you were in the middle of entering a command and realized that it was misspelled. Or you could use it to cancel ls if it were taking too long to list the contents of a very large directory
CTRL-C is an example of a control character. Control characters are entered by pressing CTRL (the CONTROL key, usually located in the lower-left corner of the keyboard), together with another key For example, CTRL-C is entered by holding down the CTRL key and pressing c. Many control characters do not appear on the screen when typed. When control characters do appear, they are represented using the caret symbol-for example, ^z is used to represent CTRL-Z.
The passwd Command
On some UNIX systems, you are forced to change your password after a certain length of time (determined by the system administrator) for security reasons. Even if your system doesn’t enforce this, you should remember to change it periodically You can do this with the passwd command. When you issue the command, it asks for your current password, and a new password, and then requires you to retype the new password to confirm it.
passwd: changing password for corwin
Re-enter new password:
The new password is effective the next time you log in. Ordinarily you can change your password whenever you want, but on some systems you must wait for a specific period of time after you change your password before you can change it again.
Note that when changing passwords, the new password must be significantly different from the old one. For example, the system will not allow you to change a password just by making lowercase characters uppercase, or by changing one or two of the characters.
The cal Command
The cal command prints a calendar for any month or year. If you do not give it an argument, it prints the current month. For example, on March 27, 2007, you would get the following:
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
If you give cal a single number, it is treated as a year, and cal prints the calendar for that year. So, for example, cal 2007 will display a calendar for all of 2007. If you want to print a specific month other than the current month, enter the month number first, then the year. To get the calendar for April 2008, use the following command:
$ cal 4 2008
Do not abbreviate the year (by entering 97 for 1997, for example). If you do, cal will give you the calendar for a year in the first century
The who Command
On a multiuser system among friends or coworkers, you may wonder who else is currently logged in. The UNIX System provides a standard command for getting this information:
dbp pts/10 Apr 2 09 52
etch pts/15 Apr 2 16 13
a-liu pts/16 Mar 29 23 21
corwin pts/18 Apr 2 06 33
raf pts/27 Apr 1 22 04
smullyan pts/31 Apr 2 16 48
For each user who is currently logged into this system, the who command provides one line of output. The first field is the user’s login name, the second is that user’s terminal ID number, and the third is the date and time when the user logged in.
The finger Command
The finger command provides you with more complete information about other users on the system. The command
$ finger corwin
will print out information about the user corwin. For example,
Login name: corwin Name: Eric Kruger
Last login Sun Aug 28 20:13:05 on pts/17
Project: Currently, I'm writing up my summer research project.
The last line of the output from finger is the contents of a file called .project. To create your own .project, type the command
$ cat > .project
My research is complete, and the results are up on my website.
and enter your own text. To end the command, enter CTRL-D on a line by itself.
If finger is used without an argument, one line of information will be printed out for each user currently logged in, similar to the who command. Note that finger can also be used to query remote computers for information about users on these remote computers. This will be discussed in Chapter 9.
The write Command
Once you know who is logged in, UNIX provides you with commands to communicate directly with other users. You can send a short message directly to another user with the write command.
The write command copies the text you type to the screen of another user who is logged in. If your login name is raf, the command
$ write corwin
Hey, are you busy?
will display the following message on corwin’s screen:
Message from raf
Hey, are you busy?
Note that corwin will see each line as you type it, rather than seeing the whole message at once. This means that you don’t have to type CTRL-D at the end of every line to send the message. In fact, if corwin responds with
$ write raf
after you begin to write, you can take turns entering lines of text until you both end the conversation with CTRL-D.
The talk Command
A problem with write is that your messages can overlap each other, which is awkward to read. The talk command is an enhanced communication program. If your login name is raf, and you type
$ talk corwin
the talk command notifies corwin that you wish to speak with him and asks him to approve. Corwin sees the following on his screen:
Message from Talk_Daemon@amber at 20:15 ...
talk: connection requested by raf@amber
talk: respond with: talk raf@amber
If corwin responds with talk raf@amber, talk splits your screen into upper and lower halves. The lines that you type appear in the top half, and the lines that corwin types appear in the lower half. Both of you can type simultaneously and see each other’s output on the screen without interrupting each other. When you wish to end the session, press CTRL-D.
An enhanced version of talk, ytalk, enables you to hold conversations among three or more people. If ytalk is not installed on your system, you can download it for free from the web site http://www.impul.se/ytalk/. Be aware, however, that installing a new program on a UNIX system can be rather tricky. You will learn how to install programs in Chapter 13.
The mesg Command
Both the write and talk commands allow someone to type a message that will be displayed on your screen. You may find it disconcerting to have messages appear unexpectedly while you are working. In order to control this, the UNIX System provides the mesg command, which allows you to accept or refuse messages sent via write and talk. Type
$ mesg n
to prohibit programs run by other people from writing to your screen. Anyone who tries to write you get the error message
Typing mesg n after someone has sent you a message will stop the conversation. The sender will see the message “Can no longer write to user.”
$ mesg y
reinstates permission to write to your screen. The command mesg by itself will report the current status (whether you are permitting others to write to your terminal or not). You can determine whether another user has denied permission for messages by using finger to obtain information about the user.
Getting Command Details
It can be hard to remember all the commands and how to use them. The UNIX operating system comes with a built-in manual so that you can look up the details for how to use each command. To view the manual page for a command, just type man followed by the command name. For example,
$ man ls
will display the man page for ls. In addition, many commands have some amount of built-in help. For example, ls --help will display a shorter version of the man page.
Unfortunately, the man pages contain a very large amount of information about each command-usually far more than you need. This can make them hard to read for a new user, although as you become more experienced with the UNIX System they will become easier to interpret. On some systems the command info (as in info ls) or apropos will give you better help. Some man pages also include examples at the bottom that may be helpful, but in many cases you will find it more useful to look up commands in a book or on the Internet.
Getting Started with Electronic Mail
UNIX allows you to use electronic mail to communicate with anyone on your system. If you are connected to the Internet, you can also use the UNIX mail programs to send e-mail to any e-mail address. This chapter covers only the simplest uses of e-mail. For a full discussion of e-mail in the UNIX System, including coverage of graphical mail applications, see Chapter 8.
A basic mail program is mail. Most systems also include an enhanced version of mail called mailx, or sometimes Mail. All three of these applications work in pretty much the same way This chapter will use the command mailx in the examples, but if you get an error message when you try to run mailx you can use Mail or mail instead.
It is easy to use mailx for simple tasks, such as reading and replying to mail messages, but doesn’t provide many advanced features (for example, it is very hard to send attachments in mailx). Although you will probably switch to a more complex mail program once you are comfortable using UNIX, mailx makes a good introduction to using e-mail on the UNIX System.
Notification of New Mail
When new mail arrives, you are notified by a simple announcement that is displayed on the command line.
$ You have new mail
This message is displayed when you first log in, if you have mail that has been delivered since your last session. It can also show up when the prompt is printed, after you enter a command. If you haven’t entered a command recently, you can press ENTER to see if you have new mail.
To view your messages, just type the mailx command, like this:
Mail version 8.1 6/6/93 Type ? for help.
"/var/spool/mail/raf": 8 messages 5 unread
>U 1 corwin Tue Oct 24 09 15 21/857 "concert this weekend"
2 email@example.com Tue Oct 24 11 23 29/930 "interesting math prob"
U 3 firstname.lastname@example.org Wed Oct 25 23 10 234/10953 "Online Gaming Article"
N 4 email@example.com Fri Oct 27 02 27 16/733 "Re: lunch next week?"
N 5 firstname.lastname@example.org Fri Oct 27 12 08 83/2558 "flight info"
N 6 etch Fri Oct 27 13 25 15/629 "Meeting"
N 7 dbp Fri Oct 27 13 27 16/634 "Re: Meeting"
N 8 email@example.com Fri Oct 27 17 05 20/812 "Re: dinner plans"
The mailx program will show you each message as a one-line heading with the following structure:
§ A single character that tells you the status of the message: N for new messages, U for unread messages (messages whose headers have been displayed before, but that you haven’t yet read), and Oor a blank space for old messages (messages you have read before).
§ The message number.
§ The date and time of delivery.
§ The size of the message, in lines and characters.
§ The subject of the message.
The current message is marked by a carat (>).
After this list, you will see a ? or & prompting you to enter a mail command. To see a list of all the commands you can enter, type in a question mark.
To read the current message, type p (for print) or t (for type). To read the next message, press ENTER or type n (next). To read other messages, type the message number, as in
Date: Fri, 27 Oct 2006 02:27:42 −0700
From: D Kraut <firstname.lastname@example.org>
Subject: Re: lunch next week?
Panda Cage sounds great.
See you Tues.
If a message is very long, you may have to press the SPACEBAR to make it scroll. After viewing a message, you can type h (header) to display the list of messages again.
Disposing of Messages
To delete the current message, type d. To delete any message, type d followed by the message number. You can delete several messages at once by entering a range:
? d 5–7
To restore a message, type u (for undelete) followed by the message number (or by a range of message numbers).
The command to save the current message is s followed by the name of a file to save it to. You can specify the message or messages to save by including the message numbers. So, for example,
? s 2 savemail
saves message 2 in the file savemail. To view the messages you have saved in this file, type
$ mailx -f savemail
from the command line.
To send a message, you use the mailx command with the address of the recipient as an argument. If you are sending mail to someone on your system, you can simply use the person’s login name as the address. The command
$ mailx dbp
tells mailx to deliver the message to user dbp on your system. To send mail to someone via the Internet, you have to enter their full e-mail address, as in
$ mailx email@example.com
This will only work if your system is configured correctly See Chapters 8 and 17 for more details about sending remote mail.
If you are already in mailx, you can send a message by typing m followed by the address at the prompt:
? m firstname.lastname@example.org
To send mail to many users at once, type all of the addresses separated by spaces.
After you enter the address, mailx will prompt you for a subject and then allow you to type in the body of the message. After you are finished, tell mailx to send the message by entering a line that contains only a single period.
$ mailx email@example.com
Subject: checking in
Thanks for taking care of Kili
while we're gone. I left a salad
in the fridge for you.
See you next week!
If you prefer, you can use CTRL-D instead of the period to terminate your input and send the message. To cancel a message without sending it, type CTRL-C (you may have to enter it twice).
The mailx program also enables you to reply to messages. To reply to the sender, type R. This takes the address from the current message and puts you into message creation mode. To include all the recipients of the message in your reply, type a lowercase r, instead. On some systems, the system administrator may have switched these two commands, so that R replies to all recipients. Be sure to check which addresses have been included in your mail before you send it.
To quit the mailx program, type q at the prompt. Any messages that you have read will be moved to the file mbox. To keep messages in your inbox, type the command pre followed by the message numbers before quitting mailx.
To exit without saving any of your changes, type x.
When you finish your work session and wish to leave the UNIX system, type exit (or CTRL-D) to log out. After a few seconds, your UNIX system will display the “login:” prompt:
This shows that you have logged out, and that the system is ready for another user to log in using your terminal.
Always log out when you finish your work session or when leaving your computer. An unattended session allows a passing stranger to access your work and possibly the work of others.
If you have a single-user system, it is important to remember that logging out is not the same as turning off your computer. To avoid problems, run the shutdown command (or on some systems, poweroff) before logging out in order to make it safe to turn off the machine. If you just turn the computer off without running shutdown, you run a real risk of damaging files or loosing data. Shutting down the system is described in Chapter 13.
In this chapter you have learned how to access and log in to a UNIX system. You now know how to use passwords, run basic commands, and communicate with other users on the system.
Table 2–1 summarizes the commands covered in this chapter.
Table 2–1: Command Summary
Change your password
Get the current date and time
Display a calendar
List all users who are currently logged in
Get information about username
Send a chat message to username
Open a chat session with username
Accept or block incoming messages
Get information about command
Read e-mail messages, or send an e-mail to address
Log out of the system
Turn off the machine
How to Find Out More
There are many resources for information about UNIX systems. Some universities have web sites designed to help their students get up and running with UNIX. Although these often include details about the particular systems at the university, they can still be very helpful for a new user. These sites include
As mentioned, the UNIX man pages can be difficult to interpret. This book is similar in style to the man pages but is a bit easier to read. It covers all the common UNIX commands:
· Robbins, Arnold. UNIX in a Nutshell 4th ed. Sebastopol, CA: O’Reilly Media, 2006.
In addition, the following web sites were mentioned in this chapter. Terminal applications for the PC (to connect to remote systems) can be downloaded from
· http://www. chiark.greenend.org. uk/~sgtatham/putty/
You can find out about different Linux distributions at
You can view screenshots of many UNIX variants at
Popular Linux distributions include
· http://www. xandros. com/
· http://fedoraproject. org/
· http://www. debian. org/
The homepage for FreeBSD is
You can acquire Solaris from