Reputation: 31
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
Reputation: 1351
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
dir0
, I execute chmod 100 dir1/
.execute
permission ondir1
.
dir1
using cd
command. But,ls
will give me following error:ls: cannot open directory '.': Permission denied
dir0
, I execute chmod 400 dir1/
.read
permission on dir1
.
cd dir1
,bash: cd: dir1/: Permission denied
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
Upvotes: 2
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
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