You have mail – this is a familiar message if you’ve ever used a Linux system that queues messages for local delivery. Below, we’ll explore how to view and manage your mailbox from the command line using the mail spool file and the mail
program.
View the Spool File
If you want to read mail for the currently logged-in user, you can inspect the spool file located in /var/mail/username
. Since $(whoami)
returns your current username, you can view your own mail like this:
sudo less /var/mail/$(whoami)
Use the ↑ and ↓ arrow keys to scroll. Press uppercase G to jump to the bottom and lowercase q to quit. If you need to read mail for a different user, replace $(whoami)
with the desired username:
sudo less /var/mail/username_here
Delete the Spool File
To remove all emails for a user, simply delete the associated spool file:
sudo rm /var/mail/$(whoami)
Using the mail Program
If you prefer an interactive approach, install the mail
command from the mailutils
package if it’s not already present:
sudo apt update && sudo apt install mailutils
Then, start the mail utility:
mail
The program will list messages with a corresponding number. After the ?
prompt, enter the message number and press ENTER
to read a specific mail.
Press ENTER
to scroll through a message line by line. Type q
and press ENTER
to return to the message list. To exit mail
, type q
again at the ?
prompt and hit ENTER
.
Delete All Messages using mail
After the ?
prompt, type d *
and press ENTER
to delete all messages in your mailbox. This is irreversible, so double-check before proceeding.
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.