gpt4 book ai didi

linux - 文件权限的测试条件

转载 作者:IT王子 更新时间:2023-10-29 01:07:06 26 4
gpt4 key购买 nike

我正在学习 shell scriptnig,有什么方法可以测试操作,例如检查文件的文件权限..喜欢...我知道一些方式。使用权限通过 find 命令搜索文件,或者在 "ls...| grep 'r--r--r' smthg.. 无论你想要什么权限

我有一些文件,如何检查文件是否具有所需的权限..?\

提前致谢..

最佳答案

你可以这样做:

执行测试:

if [ -x "$file" ]; then
#do_something
fi

写作测试:

if [ -w "$file" ]; then
#do_something
fi

阅读测试:

if [ -r "$file" ]; then
#do_something
fi

关于linux - 文件权限的测试条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3369172/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com