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 lalais successful for me. Thecommandonly makes sure that no alias oflsis 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 $0to verify that I'm usingbashtoo. 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/lsdirectly? 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 off1makes me think there's the-Fflag – Stephen Harris Nov 06 '18 at 11:42lsis an alias and uses the-Fflag to classify the filles, seels(1). This would try to accessf1in order to classify it and append an asterisk. Usingls --color=noonly appends to the alias. Trycommand lsinstead. I'm using ArchLinux, should not make a difference. – stefan Nov 06 '18 at 11:48command:) – David Chen Nov 06 '18 at 11:55