You removed a photo from the product gallery. The file often stays in pub/media/catalog/product. Over years that folder grows, backups get heavy, and the server still holds files Magento no longer lists. This CLI walks that directory, checks the media gallery table, and flushes files that have no row.
Mock first. Flush when the list looks right.
A live run asks you to confirm. --run-mock prints every path it would delete and never touches the disk. Both runs report megabytes and file count.
A file on disk is not the same as a file Magento still knows. The command looks for files under pub/media/catalog/product when the gallery table has already forgotten them.
There is no Admin button. Run it from Magento CLI on staging, then production, with a backup in your pocket. Keep it off the storefront and out of daily merchandising.
One customer described clearing more than 120 GB from a catalog images directory that had grown past 500 GB. How much you recover depends on how many unreferenced files your Magento install still holds.
See it first--run-mock prints every path it would delete. Nothing is removed until you run without that flag and confirm.
Confirm to flushThe live command is the same one without --run-mock. Type yes at the prompt.
MB and file countEach path is written to the terminal. The summary is unused size in MB and how many files were processed.
Recover storageLeftover product image files in pub/media/catalog/product after gallery edits, imports, and deleted products.
What stays, and what goes
Still in the gallery tableA matching value in catalog_product_entity_media_gallery means the file is referenced. It stays on disk, including cache copies of those images.
On disk, no gallery rowUnder pub/media/catalog/product with no corresponding gallery record. These are the leftovers after gallery edits, imports, and deleted products.
Cache of kept imagesCache copies of referenced product images stay. This flush is not Magento’s Flush Catalog Images Cache button.
Use it when
Media is fat and Magento already forgot the files.
You replaced or removed product images for years.
A catalog import left unused files on disk.
Backups and disk usage are climbing on pub/media.
You can run a mock on staging first.
Do not use it when
The file is still the live gallery image.
You have no filesystem or media backup.
You need to delete one SKU’s images from Admin. Use the product gallery.
A CDN or another server holds media Magento’s table does not know about.
You have not run --run-mock and read the list.
Back up media first. A live flush deletes files. There is no restore in the module. Snapshot pub/media, or the whole disk, mock on staging, then production.
Before you run it
Still-used imagesIt keeps files that still have a media gallery row. Always mock first and read the list.
Preview before deleteYes. --run-mock reports the paths and never deletes.
Admin buttonNo. Magento CLI over SSH only. This is not a merchandising tool.
RestoreNo. A live flush is permanent. Keep a media backup. There is no recycle bin.
One product’s imagesAdmin gallery edits one SKU. This finds files Magento’s gallery table no longer references. There is no “delete this product’s images” screen.
Which directoryProduct media under pub/media/catalog/product.
Five steps. Read the mock list.
1Enable Emmo_FlushImages and run setup:upgrade. Unzip the package as app/code/Emmo/FlushImages.
2Copy pub/media/catalog/product, or take a server backup.
3bin/magento emmo:images:flush-unused --run-mock
4Same command without --run-mock. Type yes at the prompt.
5Open a few products. Confirm gallery images still render. Note the MB freed.
SSH
bin/magento emmo:images:flush-unused
Flush unused images? Type yes.
No Admin button. No recycle bin. No screen that deletes one product’s images. It only removes files Magento’s media gallery table no longer references. Magento Open Source and Adobe Commerce. PHP 8.1–8.5. CLI and SSH. Command: emmo:images:flush-unused, with --run-mock to preview. Support: [email protected]
More Information
More Information
Follow Meta Tag
Please Select
Reviews
Zoe
Overall Rating
100%
Excellent Extension
Revamped my store by clearing out loads of unused product images. The support team swiftly tackled an installation hiccup. Thumbs up
Clarke
Overall Rating
100%
unique extension
Absolutely unique extension! It's the first of its kind that I've come across. Incredibly useful—I'm excited to use it, I wasted plenty of money buying additional space on server! but, now it allowed me to empty the media folder from unwanted images. Awesome, thanks EMMO team.
Grace
Overall Rating
100%
This extension is a lifesaver!
This extension is a lifesaver! It effortlessly removes unwanted images, boosting my store's performance. Installing it was easy, and it worked like a charm right out of the box, so no need to reach out to support. Highly recommended
Emma Martinez
Overall Rating
100%
a real time-saver
Handling our website's media is now super easy! This tool is a real time-saver, streamlining the backend tasks effortlessly
Geidu
Overall Rating
100%
A reliable module that works just as needed
Great product and great support, highly recommended
Myra
Overall Rating
100%
Fixed my media directory
My media directory was messed up! this saved my life. The extension is good and the support is quick and efficient.
Powel
Overall Rating
100%
Removed more than 120GB
Our catalog images directory was huge and more than 500GB was used by images only. We were able to remove more than 120GB with this extension. Support was really quick to guide us on it's usage