0

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?

0

1 Answer 1

6

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 (see also the POSIX specification for chmod) mean respectively:

  • clear the execute bits for everyone (a-x),
  • set the permissions for everyone (a=) to
    • read (r),
    • executable if directory or executable (X),
  • add the writable bit for the owner (u+w).

The conditional part (executable if directory or executable) can’t be represented numerically.

The purpose of the sequential -x and =rX is to ensure that only directories have the execute bit set: since the execute bits are cleared, X can only match directories, not files with their execute bit set.

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.

0

Not the answer you're looking for? Browse other questions tagged .