chmod and the capital X

This is one very, very, very interesting piece of ancient wisdom.

Suppose you need to change permissions for some directories. Maybe the permissions are too strict, e.g. something like 700 for directories and 600 for files, and you need to give access to some other group and not just the owner.

As you know, execute permission on directories is required for traversal. So you might think doing something like:

chmod -R g+rx /var/somedirectory  

This would probably work, but would leave you in a sad state: you'll get the executable bit set on files that are not supposed to be executable at all, which may be just annoying but may get risky as well.

A great alternative is:

chmod -R g+rX /var/somedirectory  

the capital X means: set the executable bit only if the target a) is a directory b) has already at least one executable bit set for any one of user, group, others.

There's another alternative that may be appealing in some situations, at least when you want to give the group the same permissions as the owner:

chmod -R g=u /var/somedirectory  

This will give any file the group permissions identical to the user's permission.

Alan Franzoni

Read more posts by this author.

Trieste, Italy
comments powered by Disqus