I have these commands:

find /var/www/html/* -type d -exec chmod 755 {} \;
find /var/www/html/* -type f -exec chmod 644 {} \;

I understood from Stephen Kitt's answer here that I could combine them this way:

find /var/www/html/* -exec chmod a-x,a=rX,u+w {} \+

These chmod arguments are less comfortable for me to read, especially in the find syntax (I've yet to become familiar with the nix meaning of the combos like a-x, a=rX, and u+w and I don't have the time and peacefulness of mind to learn it in a serious way in the coming days).

Is it possible to use numbers there? If not, there might be a bit more comfortable way to unite the two commands even if a tiny bit longer than the particular one proposed?

| improve this question | | | | |

I would say you should use whatever you feel comfortable with; so

find /var/www/html/* -type d -exec chmod 755 {} \+
find /var/www/html/* -type f -exec chmod 644 {} \+

is fine (\+ instead of \;).

The a-x,a=rX,u+w chmod arguments mean respectively “clear the execute bits for everyone”, ”set the permissions for everyone to read (=r), executable if directory or executable (=X)”, and “add the writable bit for the owner”. The conditional part (executable if directory or executable) can’t be represented numerically.

It occurs to me that you don’t need find at all here:

chmod -R a-x,a=rX,u+w /var/www/html/*

will apply the same changes using chmod only.

| improve this answer | | | | |
  • Thanks, I'll search data in man chmod to read more on a-, a=, x in comparison to X, and u, and then comeback and read here again. – Arcticooling Jan 12 '18 at 5:07
  • Sadly I didn't find data in man chmod on these arguments. I assume they are are posix something? – Arcticooling Jan 12 '18 at 7:03
  • Look for “symbolic mode” in the description section of the page I linked to, paragraphs two through five. They are defined by POSIX, yes. – Stephen Kitt Jan 12 '18 at 7:35
  • @StephenKitt a-x,a=rX isn't the first argument (a-x) redundant in the sense a=rX` overwrite it? – user9303970 Feb 10 '18 at 15:14
  • @user9303970 no: a-x ensures that all files lose the execute bit, then a=rX sets the read bit everywhere, and execute on directories only. a=rX on its own, without a-x beforehand, will set the execute bit for all users on any executable file, as well as directories. You can see this for yourself by comparing the results of touch chmodtest; chmod 764 !$; stat !$; chmod a=rX !$; stat !$ v. touch chmodtest; chmod 764 !$; stat !$; chmod a-x,a=rX !$; stat !$. – Stephen Kitt Feb 10 '18 at 15:19

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