How to delete the cache and autogenerated content from the command line?

The script need to be executed in Magento 2 root folder.

  1. It deletes all the contents of var subfolder except var/session subfolder and except the.htaccess file
  • It deletes all the contents of pub/static subfolder except the.htaccess file
find var/* -type f -or -type d | grep -v 'session' | xargs rm -rf && \
rm -rf pub/static/*
1 Like

See also:

You can also to delete the cache with the Magento 2 embedded console command:

bin/magento cache:clean

You can delete the cache of a particular type only, e.g.:

bin/magento cache:clean config

How to delete the language translation cache from the command line?

How to delete the cache programmatically?