MAIL(1) General Commands Manual MAIL(1)
mail, Mail - read or send mail messages
Mail [ -deHinNUv ] [ -f [ filename | +folder ] ] [ -T file ]
[ -u user ]
Mail [ -dFinUv ] [ -h number ] [ -r address ] [ -s subject ]
mail is a comfortable, flexible, interactive program for composing,
sending and receiving electronic messages. While reading messages,
mail provides you with commands to browse, display, save, delete, and
respond to messages. While sending mail, mail allows editing and
reviewing of messages being composed, and the inclusion of text from
files or other messages.
Incoming mail is stored in the system mailbox for each user. This is a
file named after the user in /var/spool/mail. mail normally looks in
this file for incoming messages, but you can use the MAIL environment
variable to have it look in a different file. When you read a message,
it is marked to be moved to a secondary file for storage. This sec-
ondary file, called the mbox, is normally the file mbox in your home
directory. This file can also be changed by setting the MBOX environ-
ment variable. Messages remain in the mbox file until deliberately
If no recipient is specified, mail attempts to read messages from the
-d Turn on debugging output. (Neither particularly inter-
esting nor recommended.)
-e Test for presence of mail. If there is no mail, mail
prints nothing and exits (with a successful return code).
-F Record the message in a file named after the first recip-
ient. Override the record variable, if set.
-H Print header summary only.
-i Ignore interrupts (as with the ignore variable).
-n Do not initialize from the system default Mail.rc file.
-N Do not print initial header summary.
-U Convert uucp style addresses to Internet standards.
Overrides the conv environment variable.
-v Pass the -v flag to sendmail(8).
-f [filename] Read messages from filename instead of system mailbox.
If no filename is specified, the mbox is used.
-f +folder Use the file folder in the folder directory (same as the
folder command). The name of this directory is listed in
the folder variable.
-h number The number of network "hops" made so far. This is pro-
vided for network software to avoid infinite delivery
-r address Pass address to network delivery software. All tilde (~)
commands are disabled.
-s subject Set the Subject header field to subject.
-T file Print the contents of the article-id fields of all mes-
sages that were read or deleted on file (for the use of
network news programs if available).
-u user Read user's system mailbox. This is only effective if
user's system mailbox is not read protected.
Refer to for tutorial information about mail.
As it starts, mail reads commands from a system-wide file
(/usr/lib/Mail.rc) to initialize certain variables, then it reads from
a private start-up file called the .mailrc file (it is normally the
file .mailrc in your home directory, but can be changed by setting the
MAILRC environment variable) for your personal commands and variable
settings. Most mail commands are legal inside start-up files. The
most common uses for this file are to set up initial display options
and alias lists. The following commands are not legal in the start-up
file: !, Copy, edit, followup, Followup, hold, mail, preserve, reply,
Reply, replyall, replysender, shell, and visual. Any errors in the
start-up file cause the remaining lines in that file to be ignored.
You can use the mail command to send a message directly by including
names of recipients as arguments on the command line. When no recipi-
ents appear on the mail command line, it enters command mode, from
which you can read messages sent to you. If you list no recipients and
have no messages, mail prints the message: `No mail for username' and
When in command mode (while reading messages), you can send messages
using the mail command.
While you are composing a message to send, mail is in input mode. If
no subject is specified as an argument to the command a prompt for the
subject is printed. After entering the subject line, mail enters input
mode to accept the text of your message to send.
As you type in the message, mail stores it in a temporary file. To
review or modify the message, enter the appropriate tilde escapes,
listed below, at the beginning of an input line.
To indicate that the message is ready to send, type a dot (or EOF char-
acter, normally CTRL-D ) on a line by itself. mail submits the message
to sendmail(8) for routing to each recipient.
Recipients can be;
o local usernames
o Internet addresses of the form:
o uucp(1C) addresses of the form:
_ filenames for which you have write permission
o alias groups
If the name of the recipient begins with a pipe symbol (|), the remain-
der of the name is taken as a shell command to pipe the message
through. This provides an automatic interface with any program that
reads the standard input, such as lpr(1) to record outgoing mail on
paper. An alias group is the name of a list of recipients that is set
by the alias command, taken from the host's /etc/aliases file, or taken
from the Network Information Service (NIS) aliases domain. See
aliases(5) for more information about mail addresses and aliases.
The following tilde escape commands can be used when composing messages
to send. Each must appear at the beginning of an input line. The
escape character (~), can be changed by setting a new value for the
escape variable. The escape character can be entered as text by typing
Escape to the shell. If present, run shell-command.
~. Simulate EOF (terminate message input).
Perform the indicated mail command. Valid only when sending a
message while reading mail.
~? Print a summary of tilde escapes.
~A Insert the autograph string Sign into the message.
~a Insert the autograph string sign into the message.
~b name ...
Add the names to the blind carbon copy (Bcc) list. This is like
the carbon copy (Cc) list, except that the names in the Bcc list
are not shown in the header of the mail message.
~c name ...
Add the names to the carbon copy (Cc) list.
~d Read in the dead.letter file. The name of this file is listed
in the variable DEAD.
~e Invoke the editor to edit the message. The name of the editor
is listed in the EDITOR variable. The default editor is ex(1).
Forward the listed messages, or the current message being read.
Valid only when sending a message while reading mail; the mes-
sages are inserted without alteration (as opposed to the ~m
~h Prompt for the message header lines: Subject, To, Cc, and Bcc.
If the header line contains text, you can edit the text by
backspacing over it and retyping.
Insert the value of the named variable into the message.
Insert text from the specified messages, or the current message,
into the letter. Valid only when sending a message while read-
ing mail; the text the message is shifted to the right, and the
string contained in the indentprefix variable is inserted as the
leftmost characters of each line. If indentprefix is not set, a
TAB character is inserted into each line.
~p Print the message being entered.
~q Quit from input mode by simulating an interrupt. If the body of
the message is not empty, the partial message is saved in the
Read in text from the specified file or the standard output of
the specified shell-command.
Set the subject line to subject.
~t name ...
Add each name to the list of recipients.
~v Invoke a visual editor to edit the message. The name of the
editor is listed in the VISUAL variable. The default visual
editor is vi(1).
Write the message text onto the given file, without the header.
~x Exit as with ~q but do not save the message in the dead.letter
Pipe the body of the message through the given shell-command.
If shell-command returns a successful exit status, the output of
the command replaces the message.
When you enter command mode in order to read your messages, mail dis-
plays a header summary of the first several messages, followed by a
prompt for one of the commands listed below. The default prompt is the
&& (ampersand character).
Message are listed and referred to by number. There is, at any time, a
current message, which is marked by a >> in the header summary. For
commands that take an optional list of messages, if you omit a message
number as an argument, the command applies to the current message.
A message-list is a list of message specifications, separated by SPACE
characters, which may include:
. The current message.
n Message number n.
^ The first undeleted message.
$ The last message.
+ The next undeleted message.
- The previous undeleted message.
* All messages.
n-m An inclusive range of message numbers.
user All messages from user.
All messages with string in the subject line (case
:c All messages of type c, where c is one of:
d deleted messages
n new messages
o old messages
r read messages
u unread messages
Note: the context of the command determines whether this
type of message specification makes sense.
Additional arguments are treated as strings whose usage depends on the
command involved. Filenames, where expected, are expanded using the
normal shell filename-substitution mechanism.
Special characters, recognized by certain commands, are documented with
While in command mode, if you type in an empty command line (a RETURN
or NEWLINE only), the print command is assumed. The following is a
complete list of mail commands:
! shell-command Escape to the shell. The name of the shell to use is
listed in the SHELL variable.
# arguments Null command. This may be used as if it were a com-
ment in .mailrc files, but note that it must be sepa-
rated from its arguments (commentary) by white space.
= Print the current message number.
? Print a summary of commands.
alias [alias recipient...]
group [alias recipient...]
Declare an alias for the given list of recipients.
The list will be substituted when the alias is used
as a recipient while sending mail. When put in the
.mailrc file, this command provides you with a record
of the alias. With no arguments, the command dis-
plays the list of defined aliases.
alternates name ...
Declare a list of alternate names for your login.
When responding to a message, these names are removed
from the list of recipients for the response. With
no arguments, alternates prints the current list of
Change directory. If directory is not specified,
$HOME is used.
copy [message-list] [filename]
Copy messages to the file without marking the mes-
sages as saved. Otherwise equivalent to the save
Save the specified messages in a file whose name is
derived from the author of the message to be saved,
without marking the messages as saved. Otherwise
equivalent to the Save command.
Delete messages from the system mailbox. If the
variable autoprint is set, print the message follow-
ing the last message deleted.
Suppress printing of the specified header fields when
displaying messages on the screen, such as "Status"
and "Received". The fields are included when the
message is saved unless the variable alwaysignore is
set. The Print and Type commands display all header
fields, ignored or not.
Delete the specified messages from the system mail-
box, and print the message after the last one
deleted. Equivalent to a delete command followed by
a print command.
echo [string ...]
Echo the given strings (like echo(1V)).
Edit the given messages. The messages are placed in
a temporary file and the EDITOR variable is used to
get the name of the editor. The default editor is
xit Exit from mail without changing the system mailbox.
No messages are saved in the mbox (see also quit).
Quit from the current mailbox file and read in the
named mailbox file. Several special characters are
recognized when used as file names:
% Your system mailbox.
%user The system mailbox for user.
# The previous mail file.
&& Your mbox file (of messages previ-
+filename The named file in the folder direc-
tory (listed in the folder vari-
With no arguments, file prints the name of the cur-
rent mail file, and the number of messages and char-
acters it contains.
folders Print the name of each mail file in the folder direc-
tory (listed in the folder variable).
Respond to a message, recording the response in a
file, name of which is derived from the author of the
message (overrides the record variable, if set). See
also the Followup, Save, and Copy commands and the
Respond to the first message in the message list,
sending the message to the author of each message in
the list. The subject line is taken from the first
message, and the response is recorded in a file, the
name of which is derived from the author of the first
message (overrides the record variable, if set). See
also the followup, Save, and Copy commands and the
Print the header summary for the indicated messages
or the current message.
group alias name ...
Same as the alias command.
headers [message] Print the page of headers that includes the message
specified, or the current message. The screen vari-
able sets the number of headers per page. See also
the z command.
help Print a summary of commands.
Hold the specified messages in the system mailbox.
endif Conditional execution, where s will execute following
mail-command up to an else or endif, if the program
is in send mode, r executes the mail-command only in
receive mode, and t executes the mail-command only if
mail is being run from a terminal. Useful primarily
in the .mailrc file.
Same as the discard command.
inc Incorporate messages that arrive while you are read-
ing the system mailbox. The new messages are added
to the message list in the current mail session.
This command does not commit changes made during the
session, and prior messages are not renumbered.
list Prints all commands available. No explanation is
load [message] filename
Load the specified message from the name file. file-
name should contain a single mail message including
mail headers (as saved by the save command).
mail recipient ...
Mail a message to the specified recipients.
Arrange for the given messages to end up in the stan-
dard mbox file when mail terminates normally. See
also the exit and quit commands.
Take a message list and mark each message as not hav-
ing been read.
next message Go to next message matching message. A message-list
can be given instead of message, but only first valid
message in the list is used. (This can be used, for
instance, to jump to the next message from a specific
pipe [message-list] [shell-command]
| [message-list] [shell-command]
Pipe the message through shell-command. The message
is treated marked as read (and normally saved to the
mbox file when mail exits). If no arguments are
given, the current message is piped through the com-
mand specified by the value of the cmd variable. If
the page variable is set, a form feed character is
inserted after each message.
Same as the hold command.
Print the specified messages. If the crt variable is
set, messages longer than the number of lines it
indicates paged through the command specified by the
PAGER variable. The default paging command is
Print the specified messages on the screen, including
all header fields. Overrides suppression of fields
by the ignore and retain commands.
quit Exit from mail storing messages that were read in the
mbox file and unread messages in the system mailbox.
Messages that have been explicitly saved in a file
are deleted unless the variable keepsave is set.
Send a response to the author of each message in the
message-list. The subject line is taken from the
first message. If record is set to a filename, a
copy of the reply is added to that file. If the
replyall variable is set, the actions of
Reply/Respond and reply/respond are reversed. The
replysender command is not affected by the replyall
variable, but sends each reply only to the sender of
Reply to the specified message, including all other
recipients of that message. If the variable record
is set to a filename, a copy of the reply added to
that file. If the replyall variable is set, the
actions of Reply/Respond and reply/respond are
reversed. The replyall command is not affected by
the replyall variable, but always sends the reply to
all recipients of the message.
retain Add the list of header fields named to the retained
list. Only the header fields in the retain list are
shown on your terminal when you print a message. All
other header fields are suppressed. The set of
retained fields specified by the retain command over-
rides any list of ignored fields specified by the
ignore command. The Type and Print commands can be
used to print a message in its entirety. If retain
is executed with no arguments, it lists the current
set of retained fields.
save [message-list] [filename]
Save the specified messages in the named file. The
file is created if it does not exist. If no filename
is specified, the file named in the MBOX variable is
used, mbox in your home directory by default. Each
saved message is deleted from the system mailbox when
mail terminates unless the keepsave variable is set.
See also the exit and quit commands.
Save the specified messages in a file whose name is
derived from the author of the first message. The
name of the file is taken from the author's name,
with all network addressing stripped off. See also
the Copy, followup, and Followup commands and the
Define a variable. To assign a value to variable,
separate the variable name from the value by an `='
(there must be no space before or after the `='). A
variable may be given a null, string, or numeric
value. To embed SPACE characters within a value
enclose it in quotes.
With no arguments, set displays all defined variables
and any values they might have. See Variables for a
description of all predefined mail variables.
shell Invoke the interactive shell listed in the SHELL
Print the size in characters of the specified mes-
source filename Read commands from the given file and return to com-
Print the top few lines of the specified messages.
If the toplines variable is set, it is taken as the
number of lines to print. The default number is 5.
Touch the specified messages. If any message in mes-
sage-list is not specifically saved in a file, it
will be placed in the mbox upon normal termination.
See also the exit and quit commands.
Same as the print command.
Same as the Print command.
Restore deleted messages. This command only restores
messages deleted in the current mail session. If the
autoprint variable is set, the last message restored
Same as the new command.
unset variable ...
Erase the specified variables. If the variable was
imported from the environment (that is, an environ-
ment variable or exported shell variable), it cannot
be unset from within mail.
version Print the current version and release date of the
Edit the given messages with the screen editor listed
in the VISUAL variable. The default screen editor is
vi(1). Each message is placed in a temporary file
write [message-list] [filename]
Write the given messages onto the specified file, but
without the header and trailing blank line. Other-
wise, this is equivalent to the save command.
xit Same as the exit command.
z[+|-] Scroll the header display forward (+) or backward (-)
one screenfull. The number of headers displayed is
set by the screen variable.
To forward a specific message, include it in a message to the desired
recipients with the ~f or ~m tilde escapes. To forward mail automati-
cally, add a comma-separated list of addresses for additional recipi-
ents to the .forward file in your home directory. This is different
from the format of the alias command, which takes a space-separated
list instead. Note: forwarding addresses must be valid (as described
in aliases(5)), or the messages will "bounce." You cannot, for
instance, reroute your mail to a new host by forwarding it to your new
address if it is not yet listed in the NIS aliases domain.
The behavior of mail is governed by a set of predefined variables that
are set and cleared using the set and unset commands.
Values for the following variables are read in automatically from the
environment; they cannot be altered from within mail:
The user's home directory.
The name of the initial mailbox file to read (in lieu of
the standard system mailbox). The default is
The name of the personal start-up file. The default is
The following variables can be initialized within the .mailrc file, or
set and altered interactively using the set command. They can also be
imported from the environment (in which case their values cannot be
changed within mail). The unset command clears variables. The set com-
mand can also be used to clear a variable by prefixing the word no to
the name of the variable to clear.
Variables for which values are normally supplied are indicated with an
equal-sign (=). The equal-sign is required by the set command, and
there can be no spaces between the variable-name, equal-sign, and
value, using set to assign a value.
allnet All network names whose last component (login name) match
are treated as identical. This causes the message list
specifications to behave similarly. Default is noallnet.
See also the alternates command and the metoo variable.
alwaysignore Ignore header fields with ignore everywhere, not just
during print or type. Affects the save, Save, copy,
Copy, top, pipe, and write commands, and the ~m and ~f
append Upon termination, append messages to the end of the mbox
file instead of prepending them. Default is noappend but
append is set in the global start-up file (which can be
suppressed with the -n command line option).
askcc Prompt for the Cc list after message is entered. Default
asksub Prompt for subject if it is not specified on the command
line with the -s option. Enabled by default.
autoprint Enable automatic printing of messages after delete and
undelete commands. Default is noautoprint.
bang Enable the special-casing of exclamation points (!) in
shell escape command lines as in vi(1). Default is
Set the default command for the pipe command. No default
Convert uucp addresses to the address style specified by
conversion, which can be either:
This requires a mail delivery program conforming
to the RFC822 standard for electronic mail
Remove loops in uucp(1C) address paths (typically
generated by the reply command). No rerouting is
performed; mail has no knowledge of UUCP routes or
Conversion is disabled by default. See also sendmail(8)
and the -U command line option.
crt=number Pipe messages having more than number lines through the
command specified by the value of the PAGER variable
(more by default). Disabled by default.
The name of the file in which to save partial letters in
case of untimely interrupt or delivery errors. Default
is the file dead.letter in your home directory.
debug Enable verbose diagnostics for debugging. Messages are
not delivered. Default is nodebug.
dot Take a period on a line by itself during input from a
terminal as EOF. Default is nodot but dot is set in the
global start-up file (which can be suppressed with the -n
command line option).
editheaders Include message headers in the text to be edited by the
~e and ~v commands.
The command to run when the edit or ~e command is used.
Default is ex(1).
escape=c Substitute c for the ~ escape character.
The directory for saving standard mail files. User spec-
ified file names beginning with a plus (+) are expanded
by preceding the filename with this directory name to
obtain the real filename. If directory does not start
with a slash (/), the value of HOME is prepended to it.
There is no default for the folder variable. See also
header Enable printing of the header summary when entering mail.
Enabled by default.
hold Preserve all messages that are read in the system mailbox
instead of putting them in the standard mbox save file.
Default is nohold for mail and hold for mailtool(1).
ignore Ignore interrupts while entering messages. Handy for
noisy dial-up lines. Default is noignore.
ignoreeof Ignore EOF during message input. Input must be termi-
nated by a period (`.') on a line by itself or by the
`~.' command. Default is noignoreeof. See also dot
When indentprefix is set, string is used to mark indented
lines from messages included with ~m. The default is a
keep When the system mailbox is empty, truncate it to zero
length instead of removing it. Disabled by default.
keepsave Keep messages that have been saved in other files in the
system mailbox instead of deleting them. Default is
The command (and options) to use when listing the files
in the folder directory. The default is ls(1V).
The name of the file to save messages which have been
read. The xit command overrides this variable, as does
saving the message explicitly to another file. Default
is the file mbox in your home directory.
metoo If your login appears as a recipient, do not delete it
from the list. Default is nometoo.
no When used as a prefix to a variable name, has the effect
of unsetting the variable.
onehop When responding to a message that was originally sent to
several recipients, the other recipient addresses are
normally forced to be relative to the originating
author's machine for the response. This flag disables
alteration of the recipients' addresses, improving effi-
ciency in a network where all machines can send directly
to all other machines (that is, one "hop" away).
outfolder Locate the files used to record outgoing messages in the
directory specified by the folder variable unless the
pathname is absolute. Default is nooutfolder. See
folder above and the Save, Copy, followup, and Followup
page Used with the pipe command to insert a form feed after
each message sent through the pipe. Default is nopage.
The command to use as a filter for paginating output,
along with any options to be used. Default is more(1).
prompt=string Set the command mode prompt to string. Default is `&&'.
quiet Refrain from printing the opening message and version
when entering mail. Default is noquiet.
Record all outgoing mail in filename. Disabled by
default. See also the variable outfolder.
replyall Reverse the effect of the reply and Reply commands.
save Enable saving of messages in the dead.letter file on
interrupt or delivery error. See DEAD for a description
of this file. Enabled by default.
screen=number Set the number of lines in a screen-full of headers for
the headers command.
Alternate command for delivering messages. Note: in
addition to the expected list of recipients, mail also
passes the -i and -m, flags to the command. Since these
flags are not appropriate to other commands, you may have
to use a shell script that strips them from the arguments
list before invoking the desired command.
sendwait Wait for background mailer to finish before returning.
Default is nosendwait.
The name of a preferred command interpreter. Typically
inherited from the environment, the shell is normally the
one you always use. Otherwise defaults to sh(1).
showto When displaying the header summary and the message is
from you, print the recipient's name instead of the
The autograph text inserted into the message when the ~a
(autograph) command is given. No default (see also the
~i tilde escape).
The autograph text inserted into the message when the ~A
command is given. No default (see also the ~i tilde
The number of lines of header to print with the top com-
mand. Default is 5.
verbose Invoke sendmail with the -v flag.
The name of a preferred screen editor. Default is vi.
$HOME/.mailrc personal start-up file
$HOME/.forward list of recipients for automatic forwarding of mes-
$HOME/mbox secondary storage file
$HOME/dead.letter undeliverable messages file
/var/spool/mail directory for system mailboxes
/usr/lib/Mail.help* help message files
/usr/lib/Mail.rc global start-up file
/tmp/R[emqsx]* temporary files
biff(1), bin-mail(1), echo(1V), ex(1), fmt(1), ls(1V), mailtool(1),
more(1), sh(1), uucp(1C), vacation(1), vi(1), aliases(5),
mail is found in /usr/ucb/Mail, as a link to /usr/ucb/mail. If you
wish to use the original (version 7) UNIX mail program, you can find it
in /usr/bin/mail. Its man page is named bin-mail(1).
Where shell-command is shown as valid, arguments are not always
allowed. Experimentation is recommended.
Internal variables imported from the execution environment cannot be
Replies do not always generate correct return addresses. Try resending
the errant reply with onehop set.
mail does not lock your record file. So, if you use a record file and
send two or more messages simultaneously, lines from the messages may
be interleaved in the record file.
The format for the alias command is a space-separated list of recipi-
ents, while the format for an alias in either the .forward or
/etc/aliases is a comma-separated list.
The Network Information Service (NIS) was formerly known as Sun Yellow
Pages (YP). The functionality of the two remains the same; only the
name has changed.
19 December 1988 MAIL(1)