Click on any of the 687 commands below to get a description and list of available options. All links in the command summaries point to the online version of the book on Safari Bookshelf.
Read mail or send mail to other users. The mail utility allows you to compose, send, receive, forward, and reply to mail. mail has two main modes: compose mode, in which you create a message, and command mode, in which you manage your mail.
While mail is a powerful utility, it can be tricky for a novice user. It is most commonly seen nowadays in scripts. Most Linux distributions include several utilities that are richer in features and much easier to use: mailers built into browsers such as Mozilla and Firefox, graphical mail programs distributed with GNOME (Evolution) and KDE (Kmail), and the terminal-based, full-screen utilities pine and elm. The GNU Emacs editor can also send and receive mail.
This section presents mail commands, options, and configuration options. To get you started, here are two of the most basic commands.
To enter interactive mail-reading mode, type:
mail
To begin writing a message to user, type:
mailuser
Enter the text of the message, one line at a time, pressing Enter at the end of each line. To end the message, enter a single period (.) in the first column of a new line and press Enter.
You can also provide much of the information on the command line, as shown in the following example:
mail james -s "System Log" </var/log/messages
This command sends a message to the user james, with a subject line of System Log, and the text of the message read from the system logfile, /var/log/messages.
Command-line options
-blist
Set blind-carbon-copy field to comma-separated list.
-clist
Set carbon-copy field to comma-separated list.
-d
Print debugging information.
-f [file]
Process contents of file instead of /var/spool/mail/$user. If file is omitted, process mbox in the user's home directory.
-i
Do not respond to tty interrupt signals.
-I
Run interactively even if the input is not from a terminal.
-n
Do not consult /etc/mail.rc when starting up.
-N
When printing a mail message or entering a mail folder, do not display message headers.
-p
Read mail in POP mode.
-ssubject
Set subject to subject. Use quotes around subjects that contain spaces.
-uuser
Process contents of /var/spool/mail/$user for the specified user.
-v
Verbose; print information about mail delivery to standard output.
-P
Disable POP mode.
Compose-mode commands
~!command
Execute a shell escape from compose mode and run the specified command.
~?
List compose-mode escapes.
~bnames
Add names to or edit the Bcc: header.
~cnames
Add names to or edit the Cc: header.
~d
Read in the dead.letter file.
~e
Invoke text editor.
~fmessages
Insert messages into message being composed.
~Fmessages
Similar to ~f, but include message headers.
~h
Add to or change all headers interactively.
~mmessages
Similar to ~f, but indent with a tab.
~Mmessages
Similar to ~m, but include message headers.
~p
Print message header fields and message being sent.
~q
Abort current message composition.
~rfilename
Include file in current message.
~sstring
Change Subject: header to string.
~tnames
Add names to or edit the To: list.
~v
Invoke editor specified with the VISUAL environment variable.
~|command
Pipe message through command.
~:mail-command
Execute mail-command.
~~string
Insert string in text of message, prefaced by a single tilde (~). If string contains a ~, it must be escaped with a \.
Command-mode commands
?
List summary of commands (help screen).
!
Execute a shell command.
- [nm]
Print numth previous message; defaults to immediately previous.
alias (a)
Print or create alias lists.
alternates (alt)
Specify remote accounts on remote machines that are yours. Tell mail not to reply to them.
chdir (c)
cd to home or specified directory.
copy (co)
Similar to save, but do not mark message for deletion.
delete (d)
Delete message.
dp (dt)
Delete current message and display next one.
edit (e)
Edit message.
exit (ex, x)
Exit mail without updating folder or user's system mailbox.
file (fi)
Switch folders.
folder (fold)
Read messages saved in a file. If no file is specified, display the name of the current file. In addition to filenames, the following are allowed:
#
Previous file
%
System mailbox
%user
user's system mailbox
&
mbox
+folder
File in folder directory.
folders
List folders.
from (f)
Print headers for messages.
headers (h)
List message headers at current prompt.
headers+ (h+)
Move forward one window of headers.
headers- (h-)
Move back one window of headers.
help
Same as ?.
hold (ho)
Hold messages in system mailbox.
ignore
Append list of fields to ignored fields. With no arguments, list currently ignored fields.
mailuser (m)
Compose message to user.
mbox
Move specified messages to mbox on exiting (the default).
next (n)
Type next message or next message that matches argument.
preserve (pr)
Synonym for hold.
print [list] (p)
Display each message in list.
Print [list] (P)
Similar to print, but include header fields.
quit (q)
Exit mail and update folder.
reply (r)
Send mail to all on distribution list.
Reply (R)
Send mail to author only.
respond
Same as reply.
retain
Always include this list of header fields when printing messages. With no arguments, list retained fields.
save (s)
Save message to folder.
saveignore
Remove ignored fields when saving.
saveretain
Override saveignore to retain specified fields.
set (se)
Set or print mail options.
shell (sh)
Enter a new shell.
size
Print size of each specified message.
source
Read commands from specified file.
top
Print first few lines of each specified message.
type (t)
Same as print.
Type (T)
Same as Print.
unalias
Discard previously defined aliases.
undelete (u)
Restore deleted message.
unread (U)
Mark specified messages as unread.
unset (uns)
Unset mail options.
visual (v)
Edit message with editor specified by the VISUAL environment variable.
write (w)
Write message, without headers, to file.
xit (x)
Same as exit.
z
Move mail's attention to next windowful of text. Use z- to move it back.
Configuration options
These options are set inside the user's .mailrc configuration file. The syntax is setoption or unsetoption. The system default configuration is in /etc/mail.rc.
append
Append (do not prepend) messages to mbox.
ask, asksub
Prompt for subject.
askbcc
Prompt for blind-carbon-copy recipients.
askcc
Prompt for carbon-copy recipients.
autoprint
Print next message after a delete.
crtnum
Use the default pager to display a message of more than num lines. Defaults to the height of the terminal screen.
debug
Same as -d on command line.
dot
Interpret a solitary . as an EOF.
escapechar
Specify escape character to use instead of a tilde (~).
folderdir
Define directory to hold mail folders.
hold
Keep message in system mailbox upon quitting.
ignore
Ignore interrupt signals from terminal. Print them as @.
ignoreeof
Do not treat ^D as an EOF.
indentprefixstring
Use the specified string with ~m as the prefix for indented messages.
metoo
Do not remove sender from groups when mailing to them.
noheader
Same as -N on command line.
nosave
Do not save aborted letters to dead.letter.
Replyall
Switch roles of Reply and reply.
quiet
Do not print version at startup.
recordfile
Use file as the path to record outgoing mail. If not set, outgoing mail is not saved.
searchheaders
When given the specifier /x:y, expand all messages that contain the string y in the x header field.
toplinesnum
Print num lines of message with the top command. Default value is 5.