I have read this and this, and found that my problem is different and more specific.
I understand the following points.
- +x on the directory grants access to files inodes through this specific directory
- meta information of a file, which is used by
ls -l
, is stored in its i-node, but file name does not belong to that
From the 2 points above, since ls
without -l
does not need to access the i-nodes of the files in the directory, it should successfully list the file names and return 0.
However, when I tried it on my machine, the file names are listed, but there were some warnings like permission denied
, and the return code is 1.
b03705028@linux7 [~/test] chmod 500 permission/
b03705028@linux7 [~/test] ls --color=no permission/
f1*
b03705028@linux7 [~/test] chmod 400 permission/
b03705028@linux7 [~/test] ls --color=no permission/
ls: 無法存取 'permission/f1': 拒絕不符權限的操作
f1
b03705028@linux7 [~/test] echo $0
bash
The Chinese characters basically talk about permission denied
My unix distribution is Linux 4.17.11-arch1
rm -rf lala; mkdir lala; chmod 400 lala; command ls lala
is successful for me. Thecommand
only makes sure that no alias ofls
is used. Could you please extend your question with the exact commands you type in to show the problem? (i.e., make a minimal working demonstration of what you observe) – stefan Nov 06 '18 at 11:32echo $0
to verify that I'm usingbash
too. May I ask which Unix distribution are you using? I've updated the problem to include the commands I used. – David Chen Nov 06 '18 at 11:35/bin/ls
directly? It's very likely that you have an alias or function in your shell that's making it try to get file stats. The*
at the end off1
makes me think there's the-F
flag – Stephen Harris Nov 06 '18 at 11:42ls
is an alias and uses the-F
flag to classify the filles, seels
(1). This would try to accessf1
in order to classify it and append an asterisk. Usingls --color=no
only appends to the alias. Trycommand ls
instead. I'm using ArchLinux, should not make a difference. – stefan Nov 06 '18 at 11:48command
:) – David Chen Nov 06 '18 at 11:55