How can I get number of messages count in Postfix's mailq? mailq command display entire mails in mailq but i would like to know count only.Is there any command for this. My OS is centos 5.5.


I use this:

mailq | grep -c "^[A-F0-9]"

You can pipe the output of mailq through various other filters such as uniq, sort and wc to get other statistics.

  • This is not accurate. When the Postfix queue is empty, then run 'mailq', we will get "Mail queue is empty" which also match "^[0-9A-Z]". And in such a situation it is not accurate. – andy Jul 7 '15 at 12:59
  • 1
    A better regex is ^[A-F0-9] which correctly results in 0 when the mail queue is empty. I've edited the answer. – Ladadadada Oct 6 '15 at 16:26
  • How silly, the last line of the output is the count – Geoffrey Jan 2 '17 at 23:37

either mailq | tail -n 1 or find /var/spool/postfix/deferred -type f | wc -l

both works

  • 1
    I get "682430 Kbytes in 26472 Requests." for the first one and "23" for the second one. – rob Dec 18 '17 at 13:28

Pipe the ouput to wc, if further refining is required, use grep.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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