TIL about the conditional execute flag in chmod
The conditional execute flag X
(uppercase) is a special flag in chmod
that:
execute/search only if the file is a directory or already has execute
permission for some user (X)
In other words, it ignores any regular files that does not have the execute bit
x
set (non-executables). This is useful when trying to recursively chmod +x
a directory of files and sub-directories without having to distinguish between
the regular files and directories/executables.
# Usage
$ chmod -R u=rwX,g=rX,o=rX foo/
The above will set in foo/
and its sub-directories:
- The owner permissions to read and write in all cases, and execute for directories and executables only.
- The group and other permissions to read in all cases, and execute for directories and executables only.