Friday, June 20, 2008

Execute Permissions on Directories

Tom Schneider, who does cool stuff at the NIH, just passed me this question:
> Ok I used chmod a+X regulon. Didn't know that directories had to be
> executable, that's kinda odd.

I agree, it is odd. It would be interesting to know why that is the case.

I'll cc this to Jeff Haemer, my friend who may know.
Sho 'nuff.

It doesn't make sense to "execute" a directory, so Unix used the extra bit for something else: searchability. Watch:
$ mkdir /tmp/foo
$ echo Molecular machines > /tmp/foo/toms
$ chmod -r /tmp/foo
$ ls -l /tmp/foo
ls: cannot open directory /tmp/foo: Permission denied
$ chmod +r-x /tmp/foo
$ ls -l /tmp/foo
ls: cannot access /tmp/foo/toms: Permission denied
total 0
-????????? ? ? ? ?
? toms

1 comment:

Tom Schneider said...

Yes, thanks for the link. I'm not sure why you had the question marks
and 'toms'. I know that will happen. The question is about why it
was designed that way. Your explanation was that there is an extra
bit so why not use it for a second purpose. But that strikes me as
poor programming style. On the other hand, this was designed long ago
when bits were less cheap!