How to remove specific user mails by linux command

To remove specific user emails using a Linux command, you can use the mail command with the -d option to delete a specific message. Here are a few examples:

Example 1: Delete a specific message by message ID

mail -d <message_id> <username>

Replace <message_id> with the actual message ID of the email you want to delete, and <username> with the username of the email account.

Example 2: Delete a specific message by subject

mail -s <subject> -d <username>

Replace <subject> with the subject of the email you want to delete, and <username> with the username of the email account.

Example 3: Delete all emails from a specific sender

mail -s <sender_email> -d <username>

Replace <sender_email> with the email address of the sender you want to delete emails from, and <username> with the username of the email account.

Example 4: Delete all emails with a specific keyword in the subject

mail -s "*<keyword>*" -d <username>

Replace <keyword> with the keyword you want to search for in the subject, and <username> with the username of the email account.

Example 5: Delete all emails from a specific folder

mail -f <folder_name> -d <username>

Replace <folder_name> with the name of the folder you want to delete emails from, and <username> with the username of the email account.

Note: The mail command is not the most user-friendly way to manage email, and it's generally recommended to use a more modern email client like mutt or msmtp instead.

Also, be careful when using these commands, as they will permanently delete the specified emails without prompting for confirmation. Make sure to use the correct message ID, subject, sender email, or folder name to avoid deleting the wrong emails.