Delete old image versions

Permalink
Hello

How do I automatically delete unused image versions?

I have more than 4000 images each with 5-6+ versions. So they use 5 times more disk space. And going this manually will take ages to finish

How to delete the unused versions from the database and also from the thumbnails folders?

Thanks.