Why ls without -l return 1 when permission to directory is r--
Clash 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
permissions directory ls
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.
 |Â
show 1 more comment
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
permissions directory ls
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 bashrm -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
40 mins ago
Hi stefan, I useecho $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
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 off1
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 yourls
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
25 mins ago
 |Â
show 1 more comment
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
permissions directory ls
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
permissions directory ls
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.
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 bashrm -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
40 mins ago
Hi stefan, I useecho $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
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 off1
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 yourls
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
25 mins ago
 |Â
show 1 more comment
Hi David, unfortunately I cannot reproduce your problem. Using bashrm -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
40 mins ago
Hi stefan, I useecho $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
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 off1
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 yourls
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
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
 |Â
show 1 more comment
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
Thank you for the answer. I just triedls --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 doestype ls
return?
– Kusalananda
35 mins ago
@Kusalanandals 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
 |Â
show 3 more comments
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
Thank you for the answer. I just triedls --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 doestype ls
return?
– Kusalananda
35 mins ago
@Kusalanandals 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
 |Â
show 3 more comments
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
Thank you for the answer. I just triedls --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 doestype ls
return?
– Kusalananda
35 mins ago
@Kusalanandals 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
 |Â
show 3 more comments
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
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
edited 16 mins ago


Kusalananda
113k15217345
113k15217345
answered 1 hour ago
Stephen Kitt
154k23340409
154k23340409
Thank you for the answer. I just triedls --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 doestype ls
return?
– Kusalananda
35 mins ago
@Kusalanandals 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
 |Â
show 3 more comments
Thank you for the answer. I just triedls --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 doestype ls
return?
– Kusalananda
35 mins ago
@Kusalanandals 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
 |Â
show 3 more comments
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.
David Chen is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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. 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
40 mins ago
Hi stefan, I use
echo $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
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 off1
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, 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
25 mins ago