The UNIX mail command is a fundamental utility on Unix-like operating systems used to send and receive electronic mail directly from the command line.
It functions as a Mail User Agent (MUA) that allows users to manage their mailbox, compose messages, and interact with recipients without a graphical interface.
Start / Exit
mail open mailboxq quit and SAVE changesx exit WITHOUT saving
Reading Mail
Enter next messagep print current messagen next message5 jump to message 5
Deleting Mail
d 1 2 3 delete specific messagesd 1-10 delete ranged * delete ALL messagesd . delete current messaged .-5 current + previous 5
Search and Delete
/word search messagesd /word delete matches
Examples:
d /crond /root
Smart Selectors
d :r delete all readd :n delete all newd :u delete all unread
Message Management
h show headersz next pagez- previous page
Sending / Replying
r replyR reply to allm user send mail
Saving Messages
s 5 file save message 5s 1-10 mbox save multiple
Undelete (before quitting)
u 3 undelete message 3u 1-5 undelete range
Quick Workflows
Delete first 50 + read mail:
maild 1-50d :rq
Delete everything:
maild *q
Delete by keyword:
maild /spamq
Notes
- Changes only apply after
q - Use
xto cancel all changes - You can combine multiple delete commands before quitting