shell对文件状态的编程(比如判断文件或目录是否存在)
2014-08-14 13:39
253 查看
摘自linux与unix shell编程指南
17.1 测试文件状态
t e s t一般有两种格式,即:
test condition
或
[ c o n d i t i o n ]
使用方括号时,要注意在条件两边加上空格。
测试文件状态的条件表达式很多,但是最常用的可在表 1 7 - 1中查到。
表17-1 文件状态测试
- d 目录 - s 文件长度大于0、非空
- f 正规文件 - w 可写
- L 符号连接 - u 文件有s u i d位设置
- r 可读 - x 可执行
使用两种方法测试文件s c o r e s . t x t是否可写并用最后退出状态测试是否成功。记住, 0表示
成功,其他为失败。
两种状态均返回0,可知文件s c o r e s . t x t可写,现在测试其是否可执行:
查看文件s c o r e s . t x t权限列表,可知结果正如所料。
下面的例子测试是否存在a p p s b i n目录
17.1 测试文件状态
t e s t一般有两种格式,即:
test condition
或
[ c o n d i t i o n ]
使用方括号时,要注意在条件两边加上空格。
测试文件状态的条件表达式很多,但是最常用的可在表 1 7 - 1中查到。
表17-1 文件状态测试
- d 目录 - s 文件长度大于0、非空
- f 正规文件 - w 可写
- L 符号连接 - u 文件有s u i d位设置
- r 可读 - x 可执行
使用两种方法测试文件s c o r e s . t x t是否可写并用最后退出状态测试是否成功。记住, 0表示
成功,其他为失败。
两种状态均返回0,可知文件s c o r e s . t x t可写,现在测试其是否可执行:
查看文件s c o r e s . t x t权限列表,可知结果正如所料。
下面的例子测试是否存在a p p s b i n目录
相关文章推荐
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell 判断文件、目录是否存在
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权
- shell判断文件,目录是否存在或者具有权限
- [zz] shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限的代码
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限