I am learning file mode permissions
666: for non-executable ordinary files
777: for executable ordinary files
777: for directories
Reference to the executable mode,
I could understand that a program file has executable mode, but have
no ideas about why a directory also has a 'executable mode`.
I found it make no sense. a directory entry cannot be executed and cannot set all the files within a directory 'executable` by just set their directory.
How to understand a executable directory entry?
This has been covered in a related post on Unix&Linux:
An example:
This also prevents from creating/removing files:
The execute permission actually should be called "access" permission, since when there is no
x
bit set on file or directory, it results inEACCES
error. You can see that when performingstrace bash -c 'cd test_access/
On the lower level, this particular permission in
stat.h
standard Unix library is defined asWhere search of course refers to directories. Note that reading what directory contains is covered by the
r
bit in the permissions. Thus, I can stillls
the directory, but cannot navigate there if there's nox
bit but there isr
bit:If you look at
strace
output forrm
andtouch
, you'll soon find out that these commands also use variation ofstat()
andopenat()
syscalls, which also return EACCESSide note on ls
Note that on Debian systems with default
/bin/bash
as user's interactive shell,ls
is often an alias tols --color=auto
. Where that's the case, you will see an error such as this:The reason behind that lies in the POSIX definition of
EACCES
:Specifically, if you run
strace ls --color=auto test_access/
you will see thatls
attempts to performlstat()
system call to determine the directory entry type, which is where the EACCES occurs