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.
Thank you, extremely helpful. __ from Ubuntu 22.04 LTS user
This was very helpful. Thanks for posting… using Debian 10
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.
thank you.
helped this newbie as i started to play with my first raspberry pi
thanks!
Useful for me on MacOS Catalina 🙂
Yes, helpful, indeed. New for me:
a) Where spool files lie.
b) Another usage of ‘less’
c) Another feature of whoami.