How to delete garbage files?

find . -empty -type d \
	-not -path '*/.git/*' \
	-not -path '*/tests/*' \
	-not -path './_my/*' \
	-not -path './app/design/adminhtml/Magento' \
	-not -path './app/design/frontend/Magento' \
	-not -path './app/design/frontend/Magento' \
	-not -path './update/vendor/bin' \
	-not -path './var/*' \
	-not -path './vendor/*' \
	-delete
find . -name '*,' -type f -delete
find . -name '*~' -type f -delete
find . -name '._*' -type f -delete
find . -name '[' -type f -delete
find . -iname '*-*old' -type f -delete
find . -iname '*-back' -type f -delete
find . -iname '*-bkp' -type f -delete
find . -iname '*-bkp.*' -type f -delete
find . -iname '*-disable' -type f -delete
find . -iname '*-old' -type d -exec rm -rf {} \;
find . -iname '*-old' -type f -delete
find . -iname '*-org' -type f -not -path './pub/media/catalog/*' -delete
find . -iname '*.*bak' -type f -delete
find . -iname '*.back' -type f -delete
find . -iname '*.backup' -type f -delete
find . -iname '*.bak' -type f -delete
find . -iname '*.bak.*' -type f -delete
find . -iname '*.bkp' -type f -delete
find . -iname '*.modified' -type f -delete
find . -iname '*.old' -type f -delete
find . -iname '*.org' -type f -delete
find . -iname '*.orig' -type f -delete
find . -iname '*.original' -type f -delete
find . -iname '*.original.*' -type f -delete
find . -iname '*.phtml?*' -type f -delete
find . -iname '*.sav' -type f -delete
find . -iname '*.save' -type f -delete
find . -iname '*.test' -type f -not -path '*/Test/*' -not -path '*/test/*' -not -path '*/tests/*' -delete
find . -iname '*.xml.before' -type f -delete
find . -iname '*=bkp' -type f -delete
find . -iname '*_copy' -type f -delete
find . -iregex '.*/[0-9]' -type f -delete
find . -iregex '.*\.[x]+' -delete
find . -iname '*_' -type d \
	-not -path './media/*' \
	-not -path './pub/media/*' \
	-exec rm -rf {} \;
find . -iname '*--*' -type f \
	-not -path './.well-known/*' \
	-not -path './media/*' \
	-not -path './pub/media/*' \
	-not -path './var/cache/*' \
	-not -path './var/log/*' \
	-not -path './var/page_cache/*' \
	-delete
find . -iname '*-' \
	-not -path './media/*' \
	-not -path './pub/media/*' \
	-exec rm -rf {} \;
find . -iname '*_bak.*' -type f -delete
find . -iname '*_new' -type f -delete
find . -iname '*_original' -type f -delete
find . -iname '*_prev' -type f -delete
find . -iname '*_prev.css' -type f -delete
find . -iname '*bak' -type d -exec rm -rf {} \;
find . -iname '.DS_Store' -type f -not -path './vendor/shopialfb/*' -delete
find . -iname '_*' -type d \
	-not -path '*/Test/*' \
	-not -path '*/_cache' \
	-not -path '*/_envs' \
	-not -path '*/_files' \
	-not -path '*/_fixture' \
	-not -path '*/_notes' \
	-not -path '*/docs/*' \
	-not -path '*/test/*' \
	-not -path '*/tests/*' \
	-not -path '*/web/css/source/*' \
	-not -path './_my' \
	-not -path './app/design/frontend/Infortis/base/web/images/*' \
	-not -path './media/*' \
	-not -path './pub/media/*' \
	-exec rm -rf {} \;
find . -iname '.*' -type d \
	-not -path '*/.cache' \
	-not -path '*/.ci' \
	-not -path '*/.config' \
	-not -path '*/.easymin' \
	-not -path '*/.git*' \
	-not -path '*/.psalm' \
	-not -path '*/.scenarios.lock*' \
	-not -path '*/.well-known' \
	-not -path '*/vendor/symfony/finder/Tests/Fixtures/.dot' \
	-not -path './media/wysiwyg/.thumbs' \
	-not -path './pub/media/*.thumb*' \
	-exec rm -rf {} \;
find . -iname 'Thumbs.db' -type f -delete
find . -iname 'error_log' -type f -delete
find . -iname 'vssver2.scc' -type f -delete
find . -iname __MACOSX -exec rm -rf {} \;
ext='\(bak\|css\|js\|json\|html\|inc\|less\|php\|phtml\|txt\|xml\)'
ext1='\(bak\|css\|js\|json\|html\|inc\|less\|php\|phtml\|xml\)'
ext2='\(bak\|css\|js\|json\|html\|inc\|php\|phtml\|xml\)'
find . -iregex '.*[-_]+[0-9][0-9][0-9\._-]+\.'$ext1'$' -type f \
	-not -name 'moment-timezone-with-data-2012-2022.js' \
	-not -name 'olegnax_athlete2_login_recaptcha_msp_231.xml' \
	-not -name 'subs_win-1252.php' \
	-not -path '*/Test/*' \
	-not -path '*/Tests/*' \
	-not -path '*/Zend/Locale/Data/*' \
	-not -path '*/data/*_setup/*' \
	-not -path '*/i18n/*' \
	-not -path '*/sql/*_setup/*' \
	-not -path '*/tests/*' \
	-delete
find . -iregex '.*[-_]+[0-9][0-9][0-9\._-]+\-\w+\.'$ext1'$' -type f \
	-not -path './var/*' \
	-delete
find . -iregex '.*/_[^/]+\.'$ext2'$' -type f \
	-not -path '*/Test/*' \
	-not -path '*/tests/*' \
	-not -path '*testing*' \
	-not -path './app/design/frontend/Codazon/fastest/seavus/Magento_Email/email/*' \
	-not -path './pub/media/amazon/*' \
	-not -path './vendor/mage2pro/core/Payment/Settings/_3DS.php' \
	-not -path './vendor/magento/framework/Phrase/*' \
	-delete
find . -iregex '.*/[^/]+_\.'$ext'$' -type f \
	-not -path './app/code/Inchoo/Search/Controller/Results/*' \
	-not -path './update/vendor/phpdocumentor/*' \
	-not -path './vendor/magento/framework/Phrase/*' \
	-not -path './vendor/phpdocumentor/*' \
	-delete
find . -iregex '.*[_\.]backup\.'$ext'$' -type f -delete
find . -iregex '.*[_\.]bkp\.'$ext'$' -type f -delete
find . -iregex '.*[_\.]old\.'$ext'$' -type f \
	-not -path './app/code/Mageplaza/Shopbybrand/view/adminhtml/templates/catalog/product/attribute/*' \
	-not -path './dev/tests/*' \
	-not -path './lib/web/mage/*' \
	-not -path './pub/static/*' \
	-not -path './vendor/magento/magento2-base/*' \
	-not -path './vendor/mageplaza/magento-2-shop-by-brand/view/adminhtml/templates/catalog/product/attribute/*' \
	-delete
find . -iregex '.*[_\.]orig\.'$ext'$' -type f -delete
find . -iregex '.*\.'$ext'(.*' -type f -delete
find . -iregex '.*\.'$ext'*[0-9\._-]+$' -type f \
	-not -path '*/.git/*' \
	-not -path '*/mkcss/*' \
	-delete
find . -iregex '.*\.'$ext'[_\.-]backup$' -type f -delete
find . -iregex '.*\.'$ext'\.swp$' -type f -delete
find . -iregex '.+[^/]+\.[^/\.]*[-_]+[^/\.]*$' -type f \
	-not -path '*/mkcss/*' \
	-delete
rm -rf ./app/app
rm -rf ./generated_
bin/magento cache:clean

See also:

Cleanup

Archiving