How to delete mail in mail command in ubuntu terminal

To delete a mail using the mail command in Ubuntu terminal, you can use the following syntax:

mail -s "delete" <message_number>

Here:

For example, if you want to delete the 5th message in your inbox, you would use the following command:

mail -s "delete" 5

If you want to delete multiple messages, you can specify a range of message numbers. For example, to delete messages 3 to 5, you would use:

mail -s "delete" 3-5

Note that the mail command only deletes messages from the current mailbox. If you want to delete messages from a specific mailbox, you need to specify the mailbox name along with the message number. For example:

mail -s "delete" <mailbox_name>/3

Replace <mailbox_name> with the name of the mailbox you want to delete messages from.

Also, note that the mail command does not permanently delete messages. Instead, it moves them to the "Trash" folder. If you want to permanently delete messages, you can use the rm command to delete the message files from the mailbox directory. For example:

rm /var/mail/<username>/message.1234

Replace <username> with your username and message.1234 with the name of the message file you want to delete.