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?

2 Answers
2

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.

Both you and @Gilles did a great job of answering the question. Even though GNU chmod supports a number of operator numeric modes, I thought your explanation of the difference between setting state and performing operations was a useful abstraction. Thank you both.
–
CodeGnomeJun 29 '12 at 8:15

1

Thanks! The operator numeric modes are what [rwxst] are internally translated to. E.g. x=1, r=2, w=4 shifted appropriately, then used to set or clear bits in the st_mode field. But X is implemented like if (f.st_mode & 0111) ..., so it's again special. It's not evident from the manual, but there's still no way you can do X with operator numeric modes.
–
AlexiosJun 29 '12 at 8:49

your 'x' in The x one is the only should be uppercase, yes?
–
lornixJun 30 '12 at 9:07

It should be! I checked, and it is. I think it's the relative size of the monospace font to the sans-serif one: XxXx. Which of course doesn't work in the comments because they use a smaller size. :)
–
AlexiosJun 30 '12 at 17:25

Symbolic modes are more expressive than octal modes, because octal modes can only express absolute changes. Relative changes, which means not only +X but any mode that doesn't specify all the new bits (such as g+x — or even a+rwx, which doesn't remove any setuid/setgid bit), cannot be expressed with octal modes.

Conversely, any octal mode can be expressed as a symbolic mode, in general by using =, e.g. 4750 = u+rwxs,g=rx,o-rwxt (or u=rwxs,g=rx,o= or many other combinations).