Skip to content

Delete All root User Emails from a Shell in Linux

How do I remove all emails from root mailbox? How can I remove all emails using shell prompt on Linux system? Delete all root user emails in Linux

Covers
Email

Question. I am running a Linux system (Ubuntu) system. Its root user has 100K emails to their mailbox. How do I remove all emails from the root mailbox? How can I remove all emails using shell prompt on Linux system?

This tutorial will help you delete all root user emails from the shell in the Linux system. Here you will find two methods to remove user emails in a Linux system with a single command.

Method 1:

You can simply remove all emails of root or any other user on the Linux system using the following command.

echo 'd *' | mail -N

Method 2:

You can also empty the mailbox file for any user. Generally the Linux system keeps the email under /var/mail/root or /var/spool/mail/root (for root account).

> /var/mail/root
> /var/spool/mail/root

For any other user on the Linux system, Simply change the root with the other username.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

2 Comments

  1. Sometimes I first run commands by hand (on a test system) to find out the right ones, the right order, etc. In cases, I find it useful to automatically document what I type and be able to ‘replay’ it later on.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top