3

Say I'm the owner of a directory and I have read and write permissions, but not execute permissions, where the directory structure is like this:

x/           (drw-r--r--)
    y        (-rw-r--r--)
    z        (-rw-r--r--)

I know that without execute permissions, I can't cd to the directory, but I thought that renaming files within the directory would count as "writing" to the directory. Thus it surprised me that the following command gave a permission denied.

mv x/y x/w

Why does mv require execute permissions on the directory x? Is it something special about the mv command? Is mv using cd internally or something?

2

1 Answer 1

4

After looking at this answer to a related question, I think I understand.

A directory is a list of files, and "executing" that directory means following the links in the directory list to the files themselves. Thus, since I don't have execute permissions on x, I can't resolve the path x/y to the actual file y in the command mv x/y x/w. (In order to get the actual file y, the directory entry for y in x has to be followed, which is part of what "executing" x means.)

However, if we give the user execute but not write permissions on x, then we can copy a file from within x to outside x, like so:

chmod u+x-w x
cp x/y y

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .