Quotidien Shaarli

Tous les liens d'un jour sur une page.

May 15, 2021

Remove duplicate mails from a maildir - Christosoft Blog

In case somehow, you got duplicate mails in a maildir, like me, maybe this is helpful to you:
?
1

find /var/mail/user -type d -name cur -print0 | xargs -0 /usr/bin/fdupes -n | less

Of course you need fdupes installed. On debian:
?
1

apt-get install fdupes

The above command is the dry run, showing you the duplicates.

Then to delete the duplicates, leaving only the first found file:
?
1

find /var/mail/user -type d -name cur -print0 | xargs -0 /usr/bin/fdupes -ndN | less

Use the same thing again with “new” instead of “cur” if you have duplicate unread mails. This only looks at duplicates within the same folder, so you can also safely run it on /var/mail for all users.