Entering Commands


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:

 $ date 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 passwd: changing password for corwin Old password: New password: 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:

 $ cal      March 2007 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:

 $ who 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 Directory:/home/corwin                         Shell:/usr/bin/bash 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. ctrl-d

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? CTRL-D

will display the following message on corwin’s screen:

 Message from raf Hey, are you busy? EOF

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

 Permission denied

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

The command

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




UNIX. The Complete Reference
UNIX: The Complete Reference, Second Edition (Complete Reference Series)
ISBN: 0072263369
EAN: 2147483647
Year: 2006
Pages: 316

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net