user3077497
user3077497

Reputation: 31

Difference b/w directory execute and file read permission

What is the difference between execute permission of directory and read permission inside that directory? As if both are set than can only we read the file.

Upvotes: 3

Views: 2446

Answers (3)

Jithin Pavithran
Jithin Pavithran

Reputation: 1351

  1. Read: allows the affected user to list the files in the directory
  2. Execute: allows the affected user to enter in to the directory. (that is, to make some directory your current working directory).
    Execute is needed on a directory to access the inode information of the files within.

The description can be confusing. I'm adding some examples to clarify this.

Say I have the following tree:

dir0
├── dir1
│   ├── dir2
│   │   └── test2.txt
│   └── test1.txt
└── testFile.txt
  • From dir0, I execute chmod 100 dir1/.
    Now the user has only execute permission ondir1.
    1. Now I can enter dir1 using cd command. But,
    2. ls will give me following error:
      ls: cannot open directory '.': Permission denied
      The user is able to enter the directory, But not able to list the contents inside
  • From dir0, I execute chmod 400 dir1/.
    Now user had only read permission on dir1.
    1. Now if I try cd dir1,
      I will get the following error:
      bash: cd: dir1/: Permission denied
    2. But, ls dir1 will work, though it will show error message along with the result.
      ls: cannot access 'dir1/test1.txt': Permission denied
      ls: cannot access 'dir1/dir2': Permission denied
      dir2 test1.txt
      Note that it has listed the contents correctly in the last line.
      The errors occur because without execute permission, the user cannot pass through the directory.

Upvotes: 2

Rajesh Kumar P
Rajesh Kumar P

Reputation: 61

Read permission lets us read the directory, obtaining a list of all the filenames in the directory. Execute permission lets us pass through the directory when it is a component of a pathname that we are trying to access.

For Example 1) if you have a directory with only execute permission, you can use that directory in path resolution for accessing a file name, but you wont be able to list/read the files on the directory. 2) if you have a directory with only read permission, you can list/read the files on the directory, but you are not allowed to use that directory for your path resolution.

Upvotes: 6

Ingo
Ingo

Reputation: 36329

If the read permission is set, you can read (list) the directory. If the x permission is set, you can use a path that goes through the directory.

Upvotes: 1

Related Questions