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 . -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 '*.bkup*' -type f -delete
find . -iname '*=' -type f -delete
find . -iname '*_old' -type d -exec rm -rf {} \;
find . -iname 'broken' -type d -exec rm -rf {} \;
find . -name '*,' -type f -delete
find . -name '*~' -type f -delete
find . -name '._*' -type f -delete
find . -name '[' -type f -delete
find . -iname '*.bk' -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 '*_original.*' -type f -not -path './pub/media/catalog/*' -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/*' \
	-not -path './vendor/rector/*' \
	-exec rm -rf {} \;
find . -iname '*--*' -type f \
	-not -path '*/images/*' \
	-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 '*/_' \
	-not -path '*/__MACOSX' \
	-not -path '*/__snapshots__' \
	-not -path '*/_cache' \
	-not -path '*/_data' \
	-not -path '*/_envs' \
	-not -path '*/_file' \
	-not -path '*/_files' \
	-not -path '*/_fixture' \
	-not -path '*/_module' \
	-not -path '*/_modules' \
	-not -path '*/_notes' \
	-not -path '*/_support' \
	-not -path './_my' \
	-exec rm -rf {} \;
find . -iname '.*' -type d \
	-not -path '*/.*ci' \
	-not -path '*/.cache' \
	-not -path '*/.config' \
	-not -path '*/.dot_directory' \
	-not -path '*/.easymin' \
	-not -path '*/.git*' \
	-not -path '*/.phive' \
	-not -path '*/.phpdoc' \
	-not -path '*/.platform' \
	-not -path '*/.psalm' \
	-not -path '*/.renditions' \
	-not -path '*/.scenarios.lock*' \
	-not -path '*/.well-known' \
	-not -path '*/vendor/symfony/finder/Tests/Fixtures/.dot' \
	-not -path './media/wysiwyg/.thumbs' \
	-not -path './node_modules/.bin' \
	-not -path './pub/media/*.thumb*' \
	-not -path './pub/media/.template-manager' \
	-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/*' \
	-not -path './pub/media/pdftemplates/files/*' \
	-not -path './skin/frontend/indigo/default/css/grid_*.css' \
	-not -path './vendor/rector/rector/vendor/rector/*/config/sets/*' \
	-not -path './vendor/symfony/intl/Resources/data/*' \
	-not -path './vendor/web-token/jwt-framework/src/EncryptionAlgorithm/Experimental/ContentEncryption/*' \
	-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 '*/iconpanels/_options.js' \
	-not -path '*/tests/*' \
	-not -path '*/vendor/fidry/cpu-core-counter/src/Finder/_NProcessorFinder.php' \
	-not -path '*testing*' \
	-not -path './app/design/frontend/Codazon/fastest/seavus/Magento_Email/email/*' \
	-not -path './node_modules/*' \
	-not -path './pub/media/amazon/*' \
	-not -path './vendor/mage2pro/core/Payment/Settings/_3DS.php' \
	-not -path './vendor/magento/framework/Phrase/*' \
	-not -path './vendor/mrclay/minify/builder/_index.js' \
	-delete
find . -iregex '.*/[^/]+_\.'$ext'$' -type f \
	-not -path '*/vendor/nikic/php-parser/*' \
	-not -path './app/code/Inchoo/Search/Controller/Results/*' \
	-not -path './node_modules/*' \
	-not -path './update/vendor/phpdocumentor/*' \
	-not -path './vendor/magento/framework/Phrase/*' \
	-not -path './vendor/phpdocumentor/*' \
	-not -path './vendor/psy/psysh/src/Reflection/ReflectionConstant_.php' \
	-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/*' \
	-not -path '*_mst_ORIG' \
	-not -path '*_mst_TMP' \
	-delete
rm -rf ./app/app
rm -rf ./generated_
bin/magento cache:clean

See also:

Cleanup

Archiving