I use the following command to delete the exim mail queues

exiqgrep -i | xargs exim -Mrm


# following commands seems to work faster compared to the above.
exim -bpru | awk {'print $3'} | xargs exim -Mrm

But the above commands do not work when the mail queue size is more than 100,000. It get stuck. So, I am using the following script which works fine regardless of the number of mails in the queue.

My question is, will it delete correctly ?

/etc/init.d/exim stop;
sleep 10;
killall -9 exim eximd
sleep 5;

#clean out the mail queue
find /var/spool/exim -mindepth 2 -type f -exec rm -rfv {} \;

#clean out the mail db files
find /var/spool/exim/db -type f -exec rm -rvf {} \;

/etc/init.d/exim restart
  • Have you tried the --max-args or --max-lines (-L) options for xargs?
    – OrangeDog
    Jul 19, 2021 at 12:21

4 Answers 4


I believe you are looking for this...

service exim stop
rm -fvr /var/spool/exim/input
service exim restart

However a slightly more sane method is to remove the messages on a per user basis...

egrep -Rl "((`pwd | cut -d / -f3`|$(grep `pwd | cut -d / -f3` /etc/userdomains | cut -d : -f1 | tr '\n' '|' | sed 's/|$//g'))|/home/`pwd | cut -d / -f3`)|X-Failed-Recipients" /var/spool/exim/input --include='*-H' | awk -F "/" '{gsub("-[A-Z]$","");print$NF}' | xargs exim -Mrm 

In addition, to delete the emails of a specific user:

grep -lr 'user@domain.com' /var/spool/exim/input/ | \
    sed -e 's/^.*\/\([a-zA-Z0-9-]*\)-[DH]$/\1/g' | \
    xargs exim -Mrm

exim -bp | \
    grep "user_email-account" | \
    awk '{print $3}' | \
    xargs exim -Mrm

To remove all messages from the queue, enter:

# exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | bash
  • This is worse performance than the version in the question.
    – OrangeDog
    Jul 19, 2021 at 12:19

I have had success with the following, even when there are millions of emails in queue.

for i in $(exim -bp | awk '{print $3}'); do exim -Mrm $i; done

  • Note that the question contains an explicit question, "My question is, will it delete correctly ?", about a piece of code.
    – Kusalananda
    Oct 11, 2022 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.