The easier method that I found is installing the module below and running these commands.
composer require ekouk/imagecleaner "dev-master"
Run in check only mode which will report the number and size in Mb of unused images.
Then run this command to delete the files.
bin/magento ekouk:cleanimages -d
This module will only remove jpg, png, jpeg images from
pub/media/catalog/product which are not referenced in the database. The default function without any switches will just report on unused files and NOT delete anything You must use the -d switch to remove files.
This module is provided free of charge with no warranty.
Please ensure you have a backup copy of your
pub/media/catalog directory just in case anything does go wrong.
I found it and started to use it from here.