Unix mail command
The mail
command is a Unix utility that allows users to send and receive email messages. Here are some basic commands and options:
Sending an email
mail [email protected]
- sends an email to the specified recipientmail -s "Subject" [email protected]
- sends an email with a specified subjectmail -c "CC: [email protected]" [email protected]
- sends an email with a carbon copy to the specified recipient
Reading email
mail
- reads the user's mailbox and displays the list of messagesmail -f
- reads the user's mailbox and displays the list of messages, with the most recent message firstmail -i
- reads the user's mailbox and displays the list of messages, with the most recent message first, and allows the user to interactively read and respond to messages
Deleting email
mail -d message_number
- deletes the specified messagemail -d
- deletes all messages in the mailbox
Replying to email
mail -r
- replies to the most recent message in the mailboxmail -r message_number
- replies to the specified message
Other options
mail -h
- displays help informationmail -v
- displays verbose outputmail -q
- quits the mail program
Example usage
Here's an example of how to use the mail
command to send an email:
$ mail -s "Hello" [email protected]
To: [email protected]
Subject: Hello
Hello,
This is a test email.
Best regards,
Your Name
$ mail -f
Mail version 8.1 6/6/93
Type? for help
"1 [email protected]" 1 message 1/1 1/1 1/1
1 [email protected] 1 1/1 1/1 1/1 "Hello"
In this example, the user sends an email to [email protected]
with the subject "Hello". The user then uses the mail -f
command to read their mailbox and displays the list of messages. The most recent message is highlighted.