Why ls without -l return 1 when permission to directory is r--

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












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










share|improve this question









New contributor




David Chen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Hi David, unfortunately I cannot reproduce your problem. Using bash rm -rf lala; mkdir lala; chmod 400 lala; command ls lala is successful for me. The command 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
    40 mins ago











  • Hi stefan, I use echo $0 to verify that I'm using bash too. May I ask which Unix distribution are you using? I've updated the problem to include the commands I used.
    – David Chen
    37 mins ago











  • What happens if you run /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 of f1 makes me think there's the -F flag
    – Stephen Harris
    31 mins ago











  • @StephenHarris Yeah that's the reason. problem solved. you guys are amazing.
    – David Chen
    26 mins ago










  • Yes, I assume that your ls is an alias and uses the -F flag to classify the filles, see ls(1). This would try to access f1 in order to classify it and append an asterisk. Using ls --color=no only appends to the alias. Try command ls instead. I'm using ArchLinux, should not make a difference.
    – stefan
    25 mins ago














up vote
3
down vote

favorite












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










share|improve this question









New contributor




David Chen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Hi David, unfortunately I cannot reproduce your problem. Using bash rm -rf lala; mkdir lala; chmod 400 lala; command ls lala is successful for me. The command 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
    40 mins ago











  • Hi stefan, I use echo $0 to verify that I'm using bash too. May I ask which Unix distribution are you using? I've updated the problem to include the commands I used.
    – David Chen
    37 mins ago











  • What happens if you run /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 of f1 makes me think there's the -F flag
    – Stephen Harris
    31 mins ago











  • @StephenHarris Yeah that's the reason. problem solved. you guys are amazing.
    – David Chen
    26 mins ago










  • Yes, I assume that your ls is an alias and uses the -F flag to classify the filles, see ls(1). This would try to access f1 in order to classify it and append an asterisk. Using ls --color=no only appends to the alias. Try command ls instead. I'm using ArchLinux, should not make a difference.
    – stefan
    25 mins ago












up vote
3
down vote

favorite









up vote
3
down vote

favorite











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










share|improve this question









New contributor




David Chen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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







permissions directory ls






share|improve this question









New contributor




David Chen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




David Chen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 9 mins ago





















New contributor




David Chen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 1 hour ago









David Chen

1184




1184




New contributor




David Chen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





David Chen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






David Chen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • Hi David, unfortunately I cannot reproduce your problem. Using bash rm -rf lala; mkdir lala; chmod 400 lala; command ls lala is successful for me. The command 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
    40 mins ago











  • Hi stefan, I use echo $0 to verify that I'm using bash too. May I ask which Unix distribution are you using? I've updated the problem to include the commands I used.
    – David Chen
    37 mins ago











  • What happens if you run /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 of f1 makes me think there's the -F flag
    – Stephen Harris
    31 mins ago











  • @StephenHarris Yeah that's the reason. problem solved. you guys are amazing.
    – David Chen
    26 mins ago










  • Yes, I assume that your ls is an alias and uses the -F flag to classify the filles, see ls(1). This would try to access f1 in order to classify it and append an asterisk. Using ls --color=no only appends to the alias. Try command ls instead. I'm using ArchLinux, should not make a difference.
    – stefan
    25 mins ago
















  • Hi David, unfortunately I cannot reproduce your problem. Using bash rm -rf lala; mkdir lala; chmod 400 lala; command ls lala is successful for me. The command 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
    40 mins ago











  • Hi stefan, I use echo $0 to verify that I'm using bash too. May I ask which Unix distribution are you using? I've updated the problem to include the commands I used.
    – David Chen
    37 mins ago











  • What happens if you run /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 of f1 makes me think there's the -F flag
    – Stephen Harris
    31 mins ago











  • @StephenHarris Yeah that's the reason. problem solved. you guys are amazing.
    – David Chen
    26 mins ago










  • Yes, I assume that your ls is an alias and uses the -F flag to classify the filles, see ls(1). This would try to access f1 in order to classify it and append an asterisk. Using ls --color=no only appends to the alias. Try command ls instead. I'm using ArchLinux, should not make a difference.
    – stefan
    25 mins ago















Hi David, unfortunately I cannot reproduce your problem. Using bash rm -rf lala; mkdir lala; chmod 400 lala; command ls lala is successful for me. The command 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
40 mins ago





Hi David, unfortunately I cannot reproduce your problem. Using bash rm -rf lala; mkdir lala; chmod 400 lala; command ls lala is successful for me. The command 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
40 mins ago













Hi stefan, I use echo $0 to verify that I'm using bash too. May I ask which Unix distribution are you using? I've updated the problem to include the commands I used.
– David Chen
37 mins ago





Hi stefan, I use echo $0 to verify that I'm using bash too. May I ask which Unix distribution are you using? I've updated the problem to include the commands I used.
– David Chen
37 mins ago













What happens if you run /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 of f1 makes me think there's the -F flag
– Stephen Harris
31 mins ago





What happens if you run /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 of f1 makes me think there's the -F flag
– Stephen Harris
31 mins ago













@StephenHarris Yeah that's the reason. problem solved. you guys are amazing.
– David Chen
26 mins ago




@StephenHarris Yeah that's the reason. problem solved. you guys are amazing.
– David Chen
26 mins ago












Yes, I assume that your ls is an alias and uses the -F flag to classify the filles, see ls(1). This would try to access f1 in order to classify it and append an asterisk. Using ls --color=no only appends to the alias. Try command ls instead. I'm using ArchLinux, should not make a difference.
– stefan
25 mins ago




Yes, I assume that your ls is an alias and uses the -F flag to classify the filles, see ls(1). This would try to access f1 in order to classify it and append an asterisk. Using ls --color=no only appends to the alias. Try command ls instead. I'm using ArchLinux, should not make a difference.
– stefan
25 mins ago










1 Answer
1






active

oldest

votes

















up vote
4
down vote



accepted










I suspect ls in your case is an alias to something like ls --color=auto; in that case, ls tries to find information about the files contained inside the directory to determine which colour to use.



ls --color=no


should list the directory without complaining.



If it still complains, then you may be using another option, like -F or --classify, that needs to access file metadata (-F/--classify looks at the file type, for example).



To be sure that you run ls without going through an alias, use either of



command ls


or



ls


To remove an alias for ls, use



unalias ls





share|improve this answer






















  • Thank you for the answer. I just tried ls --color=no, but the result is exactly the same. I also checked /etc/bash.bashrc and ~/.bashrc, and there are no such aliases. Am I missing something?
    – David Chen
    1 hour ago











  • @DavidChen What does type ls return?
    – Kusalananda
    35 mins ago










  • @Kusalananda ls is alias of「ls --color -F」 I guess -F here is the reason why I still get return code as 1 even using --clor=no?
    – David Chen
    28 mins ago










  • @DavidChen Yes, that option needs to access the filetype of each file.
    – Kusalananda
    27 mins ago










  • @Kusalananda I know this is kind of unrelated to the original question, but where can the alias be defined other than /etc/bash.bashrc and ~/.bashrc?
    – David Chen
    20 mins ago










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






David Chen is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480083%2fwhy-ls-without-l-return-1-when-permission-to-directory-is-r%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote



accepted










I suspect ls in your case is an alias to something like ls --color=auto; in that case, ls tries to find information about the files contained inside the directory to determine which colour to use.



ls --color=no


should list the directory without complaining.



If it still complains, then you may be using another option, like -F or --classify, that needs to access file metadata (-F/--classify looks at the file type, for example).



To be sure that you run ls without going through an alias, use either of



command ls


or



ls


To remove an alias for ls, use



unalias ls





share|improve this answer






















  • Thank you for the answer. I just tried ls --color=no, but the result is exactly the same. I also checked /etc/bash.bashrc and ~/.bashrc, and there are no such aliases. Am I missing something?
    – David Chen
    1 hour ago











  • @DavidChen What does type ls return?
    – Kusalananda
    35 mins ago










  • @Kusalananda ls is alias of「ls --color -F」 I guess -F here is the reason why I still get return code as 1 even using --clor=no?
    – David Chen
    28 mins ago










  • @DavidChen Yes, that option needs to access the filetype of each file.
    – Kusalananda
    27 mins ago










  • @Kusalananda I know this is kind of unrelated to the original question, but where can the alias be defined other than /etc/bash.bashrc and ~/.bashrc?
    – David Chen
    20 mins ago














up vote
4
down vote



accepted










I suspect ls in your case is an alias to something like ls --color=auto; in that case, ls tries to find information about the files contained inside the directory to determine which colour to use.



ls --color=no


should list the directory without complaining.



If it still complains, then you may be using another option, like -F or --classify, that needs to access file metadata (-F/--classify looks at the file type, for example).



To be sure that you run ls without going through an alias, use either of



command ls


or



ls


To remove an alias for ls, use



unalias ls





share|improve this answer






















  • Thank you for the answer. I just tried ls --color=no, but the result is exactly the same. I also checked /etc/bash.bashrc and ~/.bashrc, and there are no such aliases. Am I missing something?
    – David Chen
    1 hour ago











  • @DavidChen What does type ls return?
    – Kusalananda
    35 mins ago










  • @Kusalananda ls is alias of「ls --color -F」 I guess -F here is the reason why I still get return code as 1 even using --clor=no?
    – David Chen
    28 mins ago










  • @DavidChen Yes, that option needs to access the filetype of each file.
    – Kusalananda
    27 mins ago










  • @Kusalananda I know this is kind of unrelated to the original question, but where can the alias be defined other than /etc/bash.bashrc and ~/.bashrc?
    – David Chen
    20 mins ago












up vote
4
down vote



accepted







up vote
4
down vote



accepted






I suspect ls in your case is an alias to something like ls --color=auto; in that case, ls tries to find information about the files contained inside the directory to determine which colour to use.



ls --color=no


should list the directory without complaining.



If it still complains, then you may be using another option, like -F or --classify, that needs to access file metadata (-F/--classify looks at the file type, for example).



To be sure that you run ls without going through an alias, use either of



command ls


or



ls


To remove an alias for ls, use



unalias ls





share|improve this answer














I suspect ls in your case is an alias to something like ls --color=auto; in that case, ls tries to find information about the files contained inside the directory to determine which colour to use.



ls --color=no


should list the directory without complaining.



If it still complains, then you may be using another option, like -F or --classify, that needs to access file metadata (-F/--classify looks at the file type, for example).



To be sure that you run ls without going through an alias, use either of



command ls


or



ls


To remove an alias for ls, use



unalias ls






share|improve this answer














share|improve this answer



share|improve this answer








edited 16 mins ago









Kusalananda

113k15217345




113k15217345










answered 1 hour ago









Stephen Kitt

154k23340409




154k23340409











  • Thank you for the answer. I just tried ls --color=no, but the result is exactly the same. I also checked /etc/bash.bashrc and ~/.bashrc, and there are no such aliases. Am I missing something?
    – David Chen
    1 hour ago











  • @DavidChen What does type ls return?
    – Kusalananda
    35 mins ago










  • @Kusalananda ls is alias of「ls --color -F」 I guess -F here is the reason why I still get return code as 1 even using --clor=no?
    – David Chen
    28 mins ago










  • @DavidChen Yes, that option needs to access the filetype of each file.
    – Kusalananda
    27 mins ago










  • @Kusalananda I know this is kind of unrelated to the original question, but where can the alias be defined other than /etc/bash.bashrc and ~/.bashrc?
    – David Chen
    20 mins ago
















  • Thank you for the answer. I just tried ls --color=no, but the result is exactly the same. I also checked /etc/bash.bashrc and ~/.bashrc, and there are no such aliases. Am I missing something?
    – David Chen
    1 hour ago











  • @DavidChen What does type ls return?
    – Kusalananda
    35 mins ago










  • @Kusalananda ls is alias of「ls --color -F」 I guess -F here is the reason why I still get return code as 1 even using --clor=no?
    – David Chen
    28 mins ago










  • @DavidChen Yes, that option needs to access the filetype of each file.
    – Kusalananda
    27 mins ago










  • @Kusalananda I know this is kind of unrelated to the original question, but where can the alias be defined other than /etc/bash.bashrc and ~/.bashrc?
    – David Chen
    20 mins ago















Thank you for the answer. I just tried ls --color=no, but the result is exactly the same. I also checked /etc/bash.bashrc and ~/.bashrc, and there are no such aliases. Am I missing something?
– David Chen
1 hour ago





Thank you for the answer. I just tried ls --color=no, but the result is exactly the same. I also checked /etc/bash.bashrc and ~/.bashrc, and there are no such aliases. Am I missing something?
– David Chen
1 hour ago













@DavidChen What does type ls return?
– Kusalananda
35 mins ago




@DavidChen What does type ls return?
– Kusalananda
35 mins ago












@Kusalananda ls is alias of「ls --color -F」 I guess -F here is the reason why I still get return code as 1 even using --clor=no?
– David Chen
28 mins ago




@Kusalananda ls is alias of「ls --color -F」 I guess -F here is the reason why I still get return code as 1 even using --clor=no?
– David Chen
28 mins ago












@DavidChen Yes, that option needs to access the filetype of each file.
– Kusalananda
27 mins ago




@DavidChen Yes, that option needs to access the filetype of each file.
– Kusalananda
27 mins ago












@Kusalananda I know this is kind of unrelated to the original question, but where can the alias be defined other than /etc/bash.bashrc and ~/.bashrc?
– David Chen
20 mins ago




@Kusalananda I know this is kind of unrelated to the original question, but where can the alias be defined other than /etc/bash.bashrc and ~/.bashrc?
– David Chen
20 mins ago










David Chen is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















David Chen is a new contributor. Be nice, and check out our Code of Conduct.












David Chen is a new contributor. Be nice, and check out our Code of Conduct.











David Chen is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480083%2fwhy-ls-without-l-return-1-when-permission-to-directory-is-r%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

List of Gilmore Girls characters

Confectionery