Skip to content

Instantly share code, notes, and snippets.

@crittermike
Last active June 2, 2024 17:50
Show Gist options
  • Save crittermike/dd12cfaa69d4d2299f6a907ea8667ed5 to your computer and use it in GitHub Desktop.
Save crittermike/dd12cfaa69d4d2299f6a907ea8667ed5 to your computer and use it in GitHub Desktop.
How to chmod only directories

Use chmod +X (as opposed to +x) which will make only directories executable and leave files alone.

This is great for recursively fixing a Drupal files directory. For example:

chmod -R 664 sites/default/files && chmod -R a+X sites/default/files

That will make all your files writeable by you and the server, but not executable, but will also make directories executable (i.e., listable).

@bankole874
Copy link

Thanks for this, You saved my ..

Copy link

ghost commented Mar 9, 2023

thank you very much sir

@antoniusmaxes
Copy link

antoniusmaxes commented Aug 11, 2023

Thank you! I had used an ugly command

sudo find sites/default/files  -type d -exec chmod 774 {} \; &&  # for directories
sudo find sites/default/files  -type f -exec chmod 664 {} \;     # for files

before I saw your elegant solution.
But I made it more restrictive

sudo chmod -R 660 sites/default/files && sudo chmod -R ug+X sites/default/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment