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 '*,' -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 '*-org' -type f -not -path './pub/media/catalog/*' -delete
find . -iname '*.*bak' -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 '*.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 '*~' -type f -delete
find . -iname '*_' -type d \
    -not -path './pub/media/*' \
    -exec rm -rf {} \;
find . -iname '*-' \
    -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 '*/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 './pub/media/*' \
    -exec rm -rf {} \;
find . -iname '.*' -type d \
    -not -path '*/.config' \
    -not -path '*/.git*' \
    -not -path '*/.well-known' \
    -not -path '*/vendor/oyejorge/less.php/lib/Less/.easymin' \
    -not -path '*/vendor/symfony/finder/Tests/Fixtures/.dot' \
    -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\|xml\)'
ext2='\(bak\|css\|js\|json\|html\|inc\|php\|phtml\|xml\)'
find . -iregex '.*[0-9]+[\-]+[0-9\.\_\-]+\.'$ext'$' \
    -not -name 'moment-timezone-with-data-2012-2022.js' \
    -type f -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 './vendor/phpdocumentor/*' \
  -not -path './vendor/magento/framework/Phrase/*' \
  -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/*' -delete
find . -iregex '.*\.'$ext'[_\.\-]backup$' -type f -delete
find . -iregex '.*\.'$ext'\.swp$' -type f -delete
find . -iregex '.+[^/]+\.[^/\.]*[\-_]+[^/\.]*$' -type f -delete
rm -rf ./app/app
rm -rf ./generated_
bin/magento cache:clean

See also:

Cleanup

Archiving