I recently started using mails via UNIX.

I would like to create a script , that would write (every time I log in ) something like

"The content of your mailbox has changed since last checkup"


"The content of your mailbox is same since last checkup"

I read a documentation on mail and mailx

I came up with script

ls -l "var/mail/USER" | awk '{print $5}'

This basically print the size of the file. How can I create script that will check this number when I log in and compare it to the number I previously logged in?

1 Answer 1


Not the literal answer to your question, but check the mailcheck(1) utility. In addition to other existing more or less standard tools, it can check maildirs as well.

  • i want to write by myself , i shouldnt be that hard , but my knowledge of some things isnt that good.
    – trolkura
    Commented Mar 3, 2016 at 14:02
  • @trolkura Well, if you configure your mail system to use maildir, it is rather simple: ls -1 ~/Maildir/new |wc -l :-) Commented Mar 3, 2016 at 16:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .