unix – 如何区分“No such file or directory”和“Permission Denied”之间的区别

我宁愿不解析STDERR,但我想不出另外一种方法来区分两者之间的差异:
$ls /net/foo.example.com/bar/test
/net/foo.example.com/bar/test: Permission denied
$ls /sdfsdf
/sdfsdf: No such file or directory

无论我尝试什么命令,他们似乎都返回相同的错误代码,所以这是一个死胡同:

$ls /net/foo.example.com/bar/test
/net/foo.example.com/bar/test: Permission denied
$echo $?
2
$ls /sdfsdf
/sdfsdf: No such file or directory
$echo $?
2

我在perl中尝试过各种文件测试,但它们都返回相同的代码.

改为测试文件.
test -e /etc/shadow && echo The file is there

test -f /etc/shadow && echo The file is a file

test -d /etc/shadow && echo Oops,that file is a directory

test -r /etc/shadow && echo I can read the file

test -w /etc/shadow && echo I can write the file

有关其他可能性,请参见测试手册页.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...