chmod -R makes files in child folders ureadable for some reason
I was adjusting the permissions when setting up some WordPress themes, and ran chmod 664 -R theme-dir/*
It worked fine on the files in the root of the directory, but all the files in subdirectories now read like this when I ls -l
:
?--------- ? ? ? ? ? core_functions.php
?--------- ? ? ? ? ? css
?--------- ? ? ? ? ? custom_functions.php
?--------- ? ? ? ? ? images
?--------- ? ? ? ? ? import_settings.php
?--------- ? ? ? ? ? js
?--------- ? ? ? ? ? options_trim.php
?--------- ? ? ? ? ? page_templates
?--------- ? ? ? ? ? post_thumbnails_trim.php
?---------+ ? ? ? ? ? shortcodes
I can't cd to any of the subdirectories, and I also can't delete them. I've never seen anything like this, anybody ever run into something similar?
Solution 1:
Accessing the contents (or more specifically file metadata except for filename) of a directory requires that the directory have the execute bit set.
Your recursive chmod removed that permission, so you lost that access. If you are using the -R
option of chmod
is better to avoid using the numeric version of the permissions, and instead run (using your desired state as an example) chmod -R ug=rwX,o=rX
. The capital X there means set the X bit only on directories or files that have at least one x
set. Also you might want to use 644 (u=rwX,go=rX
) unless you really need group users to write.
Solution 2:
From the Wordpress documentation:
If you have shell access to your server, you can change file permissions recursively by using the following commands:
For Directories:
find /path/to/your/wordpress/install/ -type d -exec chmod 755 {} \;
For Files:
find /path/to/your/wordpress/install/ -type f -exec chmod 644 {} \;