0

If I have a directory on which user has read permission why is it not possible to check if there is a file in that directory. For example, let's say I have folder /myfolder with permission read. That folder has some file 'garbage.txt' with permission read (for the user). When I try to use stat /myfolder/garbage.txt I get permission denied error. If I add execute permissions for /myfolder then I can check if garbage.txt exists.

Why is it that I need execute permissions to check if a file in a folder exists. I expected that read permissions on directory/folder would be enough.

2 Answers 2

0

In Linux folders permissions are:

The write bit allows the affected user to create, rename, or delete files within the directory, and modify the directory's attributes

The read bit allows the affected user to list the files within the directory

The execute bit allows the affected user to enter the directory, and access files and directories inside

The sticky bit states that files and directories within that directory may only be deleted or renamed by their owner (or root)

More info:

http://www.firewall.cx/linux-knowledgebase-tutorials/introduction-to-linux/299-linux-file-folder-permissions.html

0

Execute permissions on a directory allow you to traverse that directory. And you need to be able to traverse into the directory to use stat on that file.

See also https://stackoverflow.com/questions/790686/understanding-linux-directory-permissions-reasoning

You must log in to answer this question.

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