A Clean Slate: Clearing Magento 2 Generated and Cached Files

A Clean Slate: Clearing Magento 2 Generated and Cached Files

When Magento 2 behaves strangely after a deploy, stale generated files are a common cause. This command clears them while protecting what should stay.

What it does

  • Empties var, except var/session and its .htaccess.
  • Empties pub/static, except its .htaccess.

The command

Run it from the Magento root:

find var/* -type f -or -type d | grep -v 'session' | xargs rm -rf && \
rm -rf pub/static/*

Then redeploy static content and flush the cache. Avoid running it on a busy production store during trading hours.

Need a second pair of eyes on this? Our team handles Magento development every week. See how we can help.

Keep reading

Related articles

All articles

Need a hand?

Stuck on something similar?
We can fix it with you.

Send us the problem. A senior developer reads every message and replies within one working day.