Why can the `ls` command of Ubuntu list the files of a directory with no execution permission set?

3.4k views Asked by At

Why can the ls command of Ubuntu list the files of a directory with no execution permission set ?

The Test directory has read and write permissions set but no execution permission set. I understand that the x attribute of the directory specify whether the directory can be accessed, and if it is not set then it doesn't matter whether r or w is set (please correct me if I'm wrong).

The cd and cat commands works as expected, i.e. that cannot do their job, since they cannot access the directory.

enter image description here

2

There are 2 answers

6
Patrick Tucci On

Edit:

Apologies, after re-reading the original post, I have a better understanding of the question. The files can be listed even though there is no execute permission because you have read permission on the directory. The x bit controls access to the inode, which contains the file metadata such as permissions info. This is why the files can be listed, but no permission data is available.

https://askubuntu.com/questions/83788/accessing-files-in-a-directory-without-x-permission

See also:

https://unix.stackexchange.com/questions/21251/how-do-directory-permissions-in-linux-work

4
jeanfrancoisim On

Having +r but not +x on a directory allows reading its contents, but not making it the current directory. Conversely, having +x on a directory but not +r will allow you to make it your current directory but not list it.

In other words, on a directory:

  • r: The read bit allows you to read the contents of that directory
  • w: The write bit allows you to create, rename and delete files
  • x: The execute bit allows you to chdir into that directory