unix – 如何区分“No such file or directory”和“Permission
发布时间:2020-12-15 18:27:38 所属栏目:安全 来源:网络整理
导读:我宁愿不解析STDERR,但我想不出另外一种方法来区分两者之间的差异: $ls /net/foo.example.com/bar/test/net/foo.example.com/bar/test: Permission denied$ls /sdfsdf/sdfsdf: No such file or directory 无论我尝试什么命令,他们似乎都返回相同的错误代码,
我宁愿不解析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 有关其他可能性,请参见测试手册页. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |