Linux Delete All Root User Mails
This post will guide you how to delete all root user mail on Linux. How do I delete all root emails from a shell in Linux system. Or how to empty root inbox on Linux or Unix system.
Linux Delete All Root User Mails
If you want to delete all emails from root mailbox in Linux, you just need to remove mailbox file for root user, and this mail file is located in /var/spool/mail/root or /var/mail/root. Type the following command:
# > /var/mail/root # > /var/spool/mail/root
There is another way to delete all root user mails in Linux, you can use Mail or Mailx command to achieve the same result.
Install Mail Tool
The Mail package is not installed by default in Linux system, so you need to install it firstly.
For CentOS/RHEL Linux:
Type the following command:
# yum install mailx
Outputs:
[root@devops ~]# yum install mailx Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: mirrors.huaweicloud.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check ---> Package mailx.x86_64 0:12.5-19.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: mailx x86_64 12.5-19.el7 base 245 k Transaction Summary ================================================================================ Install 1 Package Total download size: 245 k Installed size: 466 k Is this ok [y/d/N]: y Downloading packages: mailx-12.5-19.el7.x86_64.rpm | 245 kB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mailx-12.5-19.el7.x86_64 1/1 Verifying : mailx-12.5-19.el7.x86_64 1/1 Installed: mailx.x86_64 0:12.5-19.el7 Complete!
For Ubuntu/Debian Linux:
You need to use the apt-get command to install mail package, type:
# apt install mailutils
For Fedora Linux:
Type the following command:
# dnf install mailx
Read Email about Root User Using Mail command
You just need to execute mail command directory in CLI, type:
Or
#mailx
Outputs:
[root@devops ~]# mail No mail for root
Delete Root Mails using Mail Command
You can remove all emails of root or any other user on Linux system using the following command:
# echo ‘d *’ | mail –N