I have this issue that is driving me crazy and has me going around in circles. I am unable to find anything relating to a solution online so hoping someone here will be able to answer this.

We have a 2.3.5p1 store that we put in production mode to test and then back into developer mode.

Since then, I am trying to disable a module but I get:

"The directory "/home/redacted/public_html/generated/code/Magento" cannot be deleted Warning!rmdir(/home/redacted/public_html/generated/code/Magento): Directory not empty"

So I ran rm -rf generated/metadata/* generated/code/* and this clears almost all of the generated/code contents except /generated/code/Magento/Framework because "Directory not empty".

A philosopher would argue as to the need to delete a directory that was already empty, but hey...

Anyway, I can see all other folders are gone but as I refresh my view they all start popping up again until the full folder and file structure is back to how it was. Nobody is visiting the front end of the site in order to create generated code on the fly and the site is definitely in developer mode (as deploy:mode:show tells me and also as I see inside env.php).

So I am stuck needing to empty the generated directory in order to disable the extension and not being able to empty it because "it's not empty".

Grateful for your feedback.

  • If no body is on the store or accessing it, you're having it generated by the cron jobs most likely. Disable them first.
    – Mark Rees
    Dec 12, 2020 at 12:22

2 Answers 2


First Thing you to do is run rm -rf generated/* for two time

Second Give proper permission as mention in Magento doc or any post on magento.stackexchange.com related to permission

And also give try with this rm -rf var/cache/* var/generation/* var/page_cache/* var/view_preprocessed/*

then upgrade, deploy and cache flush

  • 1
    Thanks Nilesh. I had to run the commands to clear the var folders and then immediately the other command to clear the generated. I then had to almost instantly run the disable module command before the folders rebuilt themselves. Somehow this does not seem right to me that Magento requires you ti race against time to do this. I certainly did not have to do this at the beggingin, before putting the site into production mode for the first time.
    – Alex
    Dec 14, 2020 at 11:37

Most likely you have wrong permissions. Try this

sudo find var/ generated/ vendor/ pub/static/ pub/media/ app/etc/ -type f -exec chmod g+w {} \;
sudo find var/ generated/ vendor/ pub/static/ pub/media/ app/etc/ -type d -exec chmod g+ws {} \;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.