Is it possible to represent the +X symbolic permission with an octal value

chmodpermissions

Is it possible to represent the +X symbolic permission with an octal value? The chmod(1) man page says:

execute/search only if the file is a directory or already has execute permission for some user

which means that chmod -R g+X will add the group execute permission only if there's already an execute bit set for user, group, or other. You could certainly do this the hard way with find:

find . -perm /ugo=x -exec chmod g+x {} \;

However, it's not obvious how one could do the same thing with an octal mode without using find or test to check the file permissions first. Is this possible, or are there some areas where symbolic and octal permissions just don't overlap?

Best Answer

The short story: it's not possible, no.

The longer story: octal permissions are states. The [+-][rwxXst] notation represents operations that culminate in changing states. Note, not the =[rwxXst] one, which sets state and is equivalent to the octal modes as Gilles said. The X one is the only conditional operation, the other ones are all unconditional.

When you chmod a file with octal permissions, you supply the final state of the permission bits verbatim. When you use the operations, you choose what you want done to the permission bits.

Your question is tantamount to asking if there's a single number that represents all square roots. The answers is obviously ‘no’: every square root yields a number (pedants: though it could be imaginary/irrational), but without the starting state (the number), you can't tell which.

Related Question