在Linux邮件队列中显示消息的数量

有一个简单的命令来找出在linux邮件队列中的消息的当前数量? mailq转储出一个详细的列表,但它不方便快速浏览。

我使用的是Ubuntu和Postfix。

如果您只想知道延迟队列中的消息数量,那么以下内容应该会让您快速回答:

 find /var/spool/postfix/deferred -type f | wc -l 

还有三个队列。 有关详细信息,请参阅http://www.porcupine.org/postfix/queueing.html

你可以过滤输出,只显示最后一行:

 mailq | tail -n 1 

作为一个相关事项,您还可以通过使用命令“mail -headers”修改Brian Showalter的build议来获取以mbox格式存储的邮箱中的邮件数量。 例如,我在我的.bashrc文件中有这一行:

 if [ -s /var/mail/$(whoami) ] ; then echo -e "\nYou have $(ls -s -h /var/mail/$(whoami) | cut -d" " -f 1) of mail. Number of messages: $(mail --file /var/mail/$(whoami) --headers | wc -l) ($(mail --file /var/mail/$(whoami) --headers | sed '/^>* *[0-9]/d' | wc -l) unread)" ; fi