Tải bản đầy đủ (.pdf) (75 trang)

Sun Fundamentals of Solaris 7 Student Guide With Instructor Notes phần 10 ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (290.86 KB, 75 trang )

A
A-10 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
History in the C Shell
Command-Line Substitution
Use !! to execute the most recent command exactly as it was executed
previously. If you entered lpstat, sent some print jobs from other
terminal windows, and want to enter the lpstat command again
from the original terminal window, type !! at the shell prompt to
execute lpstat the second time. For example:
% lpstat -o
no entries
% !!
lpstat -o
sparky-3 root 15 Jun 9 14:55
filtered
printer1-5 root 573 Jun 9 13:14 on
printer 1
print1-6 root 545 Jun 9 08:10
filtered
%
Use !* to repeat all arguments of the previous command.
Use !$ to repeat the last argument of the previous command. For
example:
% cd
% mkdirabc
% ls !*
lsabc
a:
b:
c:


% rm -ir !$
rm -ir c
rm: examine files in dir c (y/n)? y
rm: remove c: (y/n)? y
%
A
Features of the C Shell A-11
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
History in the C Shell
Command-Line Substitution
% ls -l > /tmp/list.file
% more !$
more /tmp/list.file
total 90
-rw-r r 1 user2 other 72 Jun 21 15:07 dante
-rw-r r 1 user2 other 72 Jun 21 15:07 dante_1
drw-r r 5 user2 other 512 Sep 28 16:39 dir1
.
.
.
drw-r r 2 user2 other 512 Sep 29 09:45 letters
drw-r r 4 user2 other 512 Sep 29 10:01 practice
%
A
A-12 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
C Shell Features
Customizing Your Prompt
The C shell enables customization of your system prompt.
Command Format

set prompt=
value
Changing Your Prompt
% set prompt="What’s Next? "
What’s Next? set prompt="Hello, ‘hostname‘ "
Hello, venus set prompt="% "
%
When you change your current command prompt to something new,
the new prompt will remain until you change it again or until you log
out.
To make your change permanent, add the set prompt command to
the .cshrc file for the C shell.
A
Features of the C Shell A-13
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
C Shell Features
Aliases
Command aliases are available in the Korn and C shells, but they are
not available in the Bourne shell.
A command alias enables you to
● Substitute a short command for a long one
● Create a single command for a series of commands
● Create alternate forms of existing commands
● Change a command set
Command Format
alias
alias_name value
Setting Aliases
% alias c clear
% alias gohome ’cd;ls’

A
A-14 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
C Shell Features
Aliases
Use the unalias command when you want to remove an alias.
Command Format
unalias
alias_name
Unsetting an Alias
% unalias c
% c
c: Command not found
%
Aliases are only valid for the window in which they are created.
However, you can add the aliases to the .cshrc file for the C shell to
activate them whenever you invoke a shell.
B-1
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Command-LineMail
B
This appendix provides the following information for accessing mail
from the command line:
● Sending mail from the command line using the mailx program
● Reading and printing messages
● Creating and using a mail alias
B
B-2 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Introduction to mailx

The Solaris operating environment provides a program called mailx
for sending and receiving electronic mail (email). The mailx program
provides facilities for reading, writing, sending, receiving, saving, and
deleting messages from the command line.
The mailx program (utility) is not window-based; therefore, it can be
run in either a window environment or from any terminal.
B
Command-Line Mail B-3
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Command-Line Mail
Use the mailx program from the command-line when:
● You are using a command-line login shell
● You are using a terminal
● You remotely log in to your workstation to read your mail
Command Format
mailx
mailx
username@hostname
Each user has a mailbox file in which to receive mail. By default, this
mailbox is located in /var/mail/
username
, where
username
is your
login ID.
The mailx program notifies you when you receive mail and places the
mail in your mailbox. After you have read your mail, mailx
automatically places these letters in a storage file called mbox, which is
located in your home directory.
Reading Your Mail

$ mailx
No mail for user2
$

In the Solaris 7 environment, the
mail
utility offers two versions,
mailx
and
mail
. You can
use either one; however, the
mailx
version has more options. This appendix covers the
mailx
version.
/usr/ucb/mail
is symbolically linked to
/usr/bin/mailx
.
B
B-4 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Sending a Mail Message
To send mail:
1. Specify
username@hostname
as an argument to the mailx
command.
2. Enter the subject of your mail and press Return.

3. Enter the text of your message, and press the . (period) key or
Control-d (to transmit message) on a line by itself to signal the end
of the message.
For example:
$ mailx user3@saturn
Subject: lunch!
Hi there!
Do you have any plans for lunch today?
If not, would you care to join me?
user2
. (Type a dot [.] and press Return)
EOT
$
(EOT is an acronym for end of transmission.)
B
Command-Line Mail B-5
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Canceling a Mail Message
Press Control-c to cancel a mail message.
$ mailx user3@saturn
Subject: lunch!
Do you have any plans (press Control-c)
^C
(Interrupt one more to kill letter)
(press Control-c)
^C “/home/user2/dead.letter” 3/29
$
Note – Each line of text within your letter can be up to 256 characters
long. When you exceed this limitation, your screen will freeze. If this
occurs, press Control-c to abort your letter.

If you cancel a message, it is saved in your home directory under the
name dead.letter. Either remove this file or save the text under
another name for later transmission.
B
B-6 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Reading a Mail Message
If you have mail, mailx notifies you each time you log in with the
message:
You have mail. or
You have new mail.
To read your mail messages, invoke the mailx program.
$ mailx
mailx version 5.0 Thu Aug 5 10:36:57 PDT 1999 type ? for
help.
“/var/mail/user2”: 2 messages 2 new
>N1 user3Mon May 14 14:4416/334About lunch!
N2 user4Mon May 14 14:5314/326Your lunch
?
Note – The question mark (?) is the mail prompt.
When you have a large number of letters in your mailbox, the
displayed list may not show all of your mail headers. If this is the case,
type one of the following options:
Options
z+ Displays the next screenful of
mail headers
z- Displays the previous screenful
of mail headers
h Redisplays the list of mail
headers at any time

B
Command-Line Mail B-7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Reading a Mail Message
The output from the mailx command is called the
mail header
. The
mail header displays:
● The version of the program
● A question mark (?) for help with mail
● The location of the mail box (for example, /var/mail/
username
)
where your mail messages are saved
● The status of the mail box:
▼ The total number of messages in the mail box
▼ The number of new messages
▼ The status (new or unread) for each message
▼ The number of each message in the order it was received
▼ The sender (user and machine name)
▼ The time and date the message was sent
▼ The size of the message (the number of lines and number of
characters in the message)
▼ The subject of the message
Mail Headers
$ mailx
mailx version 5.0 Thu Aug 5 10:36:57 PDT 1999 type ?
for help.
“/var/mail/user2”: 2 messages 2 new
>N 1 user3 Mon May 14 14:4416/334 About lunch!

N 2 user4 Mon May 14 14:5314/326 Your lunch
?
B
B-8 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Reading a Mail Message
When a new message is received, or an old message was not read, one
of the following characters appears next to the applicable message:
To read the first mail message, press Return at the mail prompt (?).
The first (or current) message appears on your screen.
Press Return to read any subsequent messages.
If you want to select a specific mail message to read, type the number
of the mail message at the mail prompt and press Return.
Table B-1 Message Classification Characters
Character Message
N Indicates a new message
U Indicates a message that was received
earlier, but was not read before
quitting the mailx program
previously
R Indicates a new message that was read
during the current invocation of
mailx
O Indicates a message that was read
previously and is saved in the current
mail box
> Indicates current message
? Indicates which message number, or if
typed by user, listing of options to
look for

B
Command-Line Mail B-9
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Reading a Mail Message
Reading a Specific Message
$ mailx
mailx version 5.0 Thu Aug 5 10:36:57 PDT 1999 Type?
for help.
"/var/mail/user2": 2 messages 2 new
>N 1 user3 Mon May 14 14:4416/334About lunch!
N 2 user4 Mon May 14 14:5314/326Your lunch
? 2
Message 2:
From user4@jupiter Mon Aug 2 14:53 PST 1999
Date: Mon, 2 Aug 1999 14:53:31 PST
From: user4@jupiter
To: user2@venus
Subject: Your lunch
Hi user2!
I heard you are going out to lunch.
Mind if I join you?
user4
?
B
B-10 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Deleting and Undeleting a Mail Message
Use the d (delete) command within mailx to delete mail messages.
d[
number range

]
● To delete the current message
? d
● To delete a non-current message
? d
number
● To delete several messages at a time
? d135
● To delete a range of messages
? d 1-5
● To undelete mail messages
? u
number
? u
number number. . .
? u
number-number
Note – You can undelete messages only until you quit mailx.
B
Command-Line Mail B-11
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Replying to a Mail Message
Use the r command within mailx to reply to the current message. For
example:
$ mailx
mailx version 5.0 Thu Aug 5 10:36:57 PDT 1999 Type? for help.
"/var/mail/user2": 2 messages 2 new
>N 1 user3 Mon Aug 2 14:44 16/334 About lunch!
N 2 user4 Mon Aug 2 14:53 14/326 Your lunch
? 1

Message 1:
From user3@saturn Mon Aug 2 14:44 PST 1999
Date: Mon, 2 Aug 1999 14:45:31 PST
From: user3@saturn
To: user2@venus
Subject: About lunch!
I have no plans for lunch and would be happy
to join you.
user3
? r
To: user3@saturn
Subject: Re: About lunch!
Great! Let’s meet in the lobby after class.
user2
.
EOT
?
B
B-12 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Replying to a Mail Message
To reply to a non-current message, type:
? r
number
Your reply will be sent to the sender of the message.
To reply to the sender and everyone who received the current
message, type:
? R
To reply to the sender and everyone who received a non-current
message, type:

? R
number
Note – Be careful about using R to reply if you are sending any
confidential information. Mail messages are frequently sent to large
groups of people that you may not want receiving the contents of your
reply.
B
Command-Line Mail B-13
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Saving a Mail Message
To save a current message, type:
? s
filename
This will save the message in the specified file in your home directory.
A saved message can be read using the cat or more commands, or
edited using vi, the CDE Text Editor, or any editor your system uses.
To save a non-current message, type:
? s <
message number
>
filename
B
B-14 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Printing a Mail Message
Use the lp command with the pipe (|) symbol to print a mail message
within mailx.
Command Format
? |
number

lp
Sending a Message to the Printer
? 1
Message 1:
From user3@saturn Mon Aug 2 14:44 PST 1999
Date: Mon, 2 Aug 1999 14:45:21 PST
From: user3@saturn
To: user2@venus
Subject: About lunch!
I have no plans for lunch, and would be happy
to join you.
user 3
? |1 lp
Pipe to: "lp"
request id is printer1-9 (standard input)
"lp" 16/334
?
The mail message is printed to your default printer.

You can specify a destination printer by using the
lp -d
printername option.
B
Command-Line Mail B-15
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Quitting Mail
Use the q (quit) command to save changes and exit mailx. Read and
unread messages are automatically stored.
If you exit using q, unread messages remain in
/var/mail/

username
. By default, read messages are stored in the
mbox file in your home directory.
It is good practice to save messages that contain important information
in a separate file and to clean out your mbox on a regular basis as it can
grow quite large.
Use the x command to exit mailx without saving changes.
To access messages stored in your mbox file, type:
$ mailx -f
mailx version 5.0 Thu Aug 5 10:36:57 PDT 1999 Type? for help.
"/export/home/user2/mbox": 5 messages
>0 1 user1 Mon Aug 14 09:08 15/342 News
0 2 user5 Mon Aug 14 10:25 90/555 Meeting
0 3 user3 Mon Aug 14 10:52 33/912 Project
0 4 user1 Mon Aug 14 11:58 45/215 Deadline
0 5 user4 Mon Aug 14 12:02 16/347 Interview
0 6 user3 Mon Aug 14 14:45 16/334 About lunch!
0 7 user4 Mon Aug 14 14:53 14/326 Your lunch
?
B
B-16 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Sending a File Using Mail
Use the mailx command and standard input redirection to send
someone a file. For example:
$ mailx user3@saturn < dante
$
Using the above command with the -s option allows you to include a
subject line.
$ mailx -s "myfile" user3@saturn < dante

$
Note – When writing mail messages, remember to press Return at the
end of each line. There is no automatic line wrap with mail.

Note – A piece of email is not a single file. A piece of email is made into pages, which are
appended into one file. By default, the storage area for all mail messages is
/var/mail/username.
B
Command-Line Mail B-17
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Creating a Mail Alias
A mail alias is a group of user names (login IDs) in a single file. Use
mail aliases when you want to send the same message to a group of
users. A mail alias is also called a distribution list.
Command Format
mailx
aliasname
Use an editor to add mail aliases to your.mailrc file, which is located
in your home (or login) directory. The .mailrc file is used to store
private mail aliases and variables relating to the mail program. Your
system administrator can set up public mail aliases, available for any
user on the system to use, in the /etc/aliases file.
You can use any editor to create or add mail aliases to the .mailrc file.
Create one mail alias per line, and then save the changes. For example:
$ cd
$ vi .mailrc
alias
class
user3@saturn user4@jupiter user5@earth
~

~
~
".mailrc" [newfile]
:wq
$ mailx class
Subject: test!
This is a test of my newly created alias
user2
.
EOT
B
B-18 Fundamentals of Solaris 7
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Using Tilde Commands
While composing a letter, you can use tilde commands to perform a
variety of functions.
Command Format
~
single character
[
string
]
Table B-2 lists some of the more useful tilde commands.
Note – If you want to include a literal tilde character in a letter, type
two tildes in succession. Only one tilde will be displayed.
Table B-2 Tilde Commands and Functions
Command Function
~!
command
Escapes to a shell command

~. Simulates pressing Control-d to mark end of file
~? Lists a summary of tilde commands
~b
username
Adds user name(s) to the blind carbon copies (Bcc:) list
~c
username
Adds user name(s) to the carbon copies (Cc:) list
~f
number
Forwards the specified letter; valid only when sending a message
while reading mail
~h Prompts for header lines: Subject, To, Cc, and Bcc
~r
filename
Reads in the text from the specified file
~t
name
Adds the specified name(s) to the To list
~p Prints the message being entered to the screen
~s
string
Changes the subject line to string
~t
name
Adds the specified name(s) to the To list
~m
number
Inserts text from the specified letter into the current letter; valid
only when sending a message while reading mail

B
Command-Line Mail B-19
Copyright 1999 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1999, Revision D
Using Tilde Commands
The following example demonstrates the use of some of the tilde
commands to make a change to the Subject line (~s
string
) and to
refresh and print the message being entered to the screen (~p):
$ mailx all_staff_alias
Subject: Meeting Today
There will be a staff meeting at 3:00 p.m. today
~s Staff meeting 3:00 p.m. Today
in the large conference room.
Please be prompt.
~p

Message contains:
To: all_staff_alias
Subject: Staff Meeting 3:00 p.m. Today
There will be a staff meeting at 3:00 p.m. today
in the large conference room.
Please be prompt.
(continue)
.
EOT

×