1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Discuss in my forum

Example uses of the Linux Command mail

An Introductory Tutorial


The following examples illustrate typical uses of the command mail for sending and receiving email.

This command starts up the mail utility and prints a summary line for each email message currently in your mail box. There is now a new prompt (&), at which you can enter any of the mail commands. The output looks something like this:
 Mail version 8.1.2 01/15/2001. Type ? for help.
 "/var/mail/jhaas": 2 messages 2 unread
 >U 1 jhaas@beethoven Sun Nov 11 15:31 17/500 test2
 U 2 jhaas@beethoven Sun Nov 11 15:34 17/500 test4
You can show the full content of a particular message by entering the message number. For example, the following command displays the content of the second message:
 & 2 
You can reply to this message by entering "r" and hitting the return key:
 & r 
This will display the automatically generated "To" and "Subject" fields of the message, and will allow you to type in your message. When you are finished you hit Ctrl-d to exit the editor. The system then gives you the option specify "Cc" recepients. Hitting "return" will send the message off.

To send a message to a particular recipient you type "mail" followed by the email address of the recepient:
 & mail goofy@domain.com 
As in the case of "reply", this will display the automatically generated "To" and "Subject" fields of the message, and will allow you to type in and send your message.

You can get a list of all the commands with:
 & list 
This command lists all commands you can use in this mail utility:
Commands are:
 next, alias, print, type, Type, Print, visual, top, touch, preserve, delete, dp, dt, undelete, unset, mail, mbox, pipe, |, more, page, More, Page, unread, !, copy, chdir, cd, save, source, set, shell, version, group, write, from, file, folder, folders, ?, z, headers, help, =, Reply, Respond, reply, respond, edit, echo, quit, list, xit, exit, size, hold, if, else, endif, alternates, ignore, discard, retain, saveignore, savediscard, saveretain, core, #, inc, new 

Complete syntax of the command: mail
  1. About.com
  2. Technology
  3. Linux

©2014 About.com. All rights reserved.