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?


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 Mar 3 '16 at 14:02
  • @trolkura Well, if you configure your mail system to use maildir, it is rather simple: ls -1 ~/Maildir/new |wc -l :-) – Radovan Garabík Mar 3 '16 at 16:03

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.