I am aware that there are numerous guides about file permissions in linux out there. This post is not intended to be another tutorial. I just wanted to emphasize the use of uppercase X when modifying regular file or directory permissions. This info seems to be missing from most of those guides.
I am sure you have already tried, at least once, to set permissions recursively on a directory and all of its contents. I am also sure you have wondered how you could recursively set the executable attribute on the subdirectories, which in this case means “enter”, but not on regular files. Well, this is what uppercase X does.
For example, we issue the following chmod command on a directory:
# chmod -R u=rwX,g=rX,o=rX testdir/
Using the uppercase X, the above command sets the executable attribute according to the following two rules:
- If the file is a directory, then it sets the executable attribute for the owner, group and world, which means that they can enter this directory.
- If the file is a regular file, then it does not add the executable attribute to its permissions, unless it already has it enabled, in which case it retains it.
Using the lowercase x it would be impossible to achieve this result with one command only.