How to read the you have mail message in Linux Ubuntu

“You have mail” – How to Read Mail in Linux Command Line

Last updated on | 7 replies

This message indicates that there is a message in your spool file. Usually the spool file is in a very simple mbox format, so you can open it in a text viewer like less or with the mail program. In most cases, this is not a message from a long lost lover, but instead a system message generated by your Linux mail service. (sad)

View Spool File

Use the following command to read the mail for the currently logged in user. The $(whoami) variable returns the currently logged in user.

sudo less /var/mail/$(whoami)

You can use the and arrows on your keyboard to scroll through the spool file.

Press uppercase G to scroll to the bottom of the file and lowercase q to quit.

If you wish to read another user’s mail, just enter their user name.

sudo less /var/mail/username_here

Delete Spool File

You can simply delete the /var/mail/username file to delete all emails for a specific user. The $(whoami) variable returns the currently logged in user.

sudo rm /var/mail/$(whoami)

Using the mail Program

You can also use the mail program to easily list and view messages in your spool file. If mail is not installed, you can install it with sudo apt install mailutils.

mail

Messages will be listed with a corresponding number:

mail
"/var/mail/john": 6 messages 6 new
>N   1 Mail Delivery Syst Thu Feb 15 21:12  80/2987  Undelivered Mail Returned to Sender
 N   2 Mail Delivery Syst Fri Feb 16 00:09  71/2266  Undelivered Mail Returned to Sender
 N   3 Mail Delivery Syst Fri Feb 16 00:16  71/2266  Undelivered Mail Returned to Sender
 N   4 Mail Delivery Syst Fri Feb 16 00:21  71/2266  Undelivered Mail Returned to Sender
 N   5 Mail Delivery Syst Fri Feb 16 00:22  71/2266  Undelivered Mail Returned to Sender
 N   6 Mail Delivery Syst Fri Feb 16 00:24  75/2668  Undelivered Mail Returned to Sender
?

After the ? prompt, enter the number of the mail you want to read and press ENTER.

Press ENTER to scroll through the message line by line and press q and ENTER to return to the message list.

To exit mail, type q at the ? prompt and then press ENTER.

Delete All Messages using mail

To delete all messages using mail, after the ? prompt, type d * and press ENTER.

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

7 replies

Leave a reply

Your email address will not be published. Required fields are marked *

  1. Thanks! This really helped a lot. I knew MacOS had it preinstalled but not ubuntu. I thought it was installed as a part of postfix but guess not.

  2. Yes, helpful, indeed. New for me:
    a) Where spool files lie.
    b) Another usage of ‘less’
    c) Another feature of whoami.