chmod:仅当文件是目录时执行

Chmod: Execute only if the file is a directory

我知道 chmod -R u=rwX,g=rwX,o=r 将设置目录、子目录和文件,但要注意:

The capital X permission option tells chmod to grant execute access only if it makes sense -- if the item is a directory, or already has at least one execute access enabled (i.e. if it appears to be an executable file).

但是有没有办法强制 chmod(以类似的方式)只影响目录,而让所有文件保持原样?

Source

find my/path -type d -exec chmod u=rwX,g=rwX,o=r {} \;
        +          +   +     +   +------+------+ +   +
        |          |   |     |          |        |   +-> semicolon needed by -exec and escaped to avoid shell expansion
        |          |   |     |          |        +-----> current directory entry returned by find
        |          |   |     |          +--------------> your chmod options
        |          |   |     +-------------------------> the shell command you want to execute on each directory entry
        |          |   +-------------------------------> need to execute a command for each entry returned by find
        |          +-----------------------------------> look for directories only (not files/symlinks/etc)
        +----------------------------------------------> the path to look for entries in