linux shell 学习(三)——判断文件和文件夹
来源:互联网 发布:网络机顶盒爱奇艺会员 编辑:程序博客网 时间:2024/05/01 01:42
linux shell 学习(三)——判断文件和文件夹
下面是判断文件和文件夹的相关例子:
主要有如下几个方法:
-d 文件夹是否存在
-e 文件夹或文件是否存在
-f 文件是否存在
-s 文件是否存在且非空
-r 文件是否可读
-w 文件是否可写
-x 文件是否可执行
-O 文件是否存在,且归当前用户所有
-G 文件是否存在,且文件所属组合当前用户所属组相同
file1 -nt file2 文件1是否创建时间比文件2晚
file1 -ot file2 文件1是否比文件2创建时间早
下面是一个简单的例子:
#!/bin/bashif [ -d $HOME ]thenecho 'home is exist'cd $HOMEls -a elseecho 'home is not exist'fiif [ -e ~/xyshell ]thenecho '/xyshell exist'cd ~/xyshellif [ -d ./testing ]thenecho 'there is a testing dir'elsemkdir testingficd testing/if [ -f ./now.txt ]thenecho 'add new date'date >> now.txtelseecho 'add new file and add new date'date > now.txtfifiif [ -d ~/xyshell/testing ] && [ -f ~/xyshell/testing/now.txt ]thenecho 'dictionary exists and file exists'elseecho 'dictionary or file does not exists'fiif [ -d ~/xyshell/testing ] || [ -f ~/xyshell/testing/now.txt ]thenecho 'dictionary or file exists'elseecho 'dictionary and file do not exist'fi
运行效果:
0 0
- linux shell 学习(三)——判断文件和文件夹
- Linux shell判断文件和文件夹是否存在
- Linux shell判断文件和文件夹是否存在
- Linux shell判断文件和文件夹是否存在
- [转] Linux shell判断文件和文件夹是否存在
- 【Linux】Shell学习笔记之三——文件和目录管理(修改、查找)
- Linux shell 对文件或文件夹是否存在的判断
- linux shell 判断文件或文件夹是否真的存在
- linux shell 判断文件或文件夹是否真的存在
- Linux Shell bash判断文件或文件夹是否存在
- linux shell如何判断文件/文件夹是否存在
- Linux之ubuntu学习笔记(三):对文件和文件夹进行简单的操作
- linux shell——遍历文件夹中的文件
- Linux学习5之shell显示当前目录下所有的文件和文件夹
- shell如何判断文件or目录(文件夹)
- linux shell 文件-文件夹列表
- shell if 条件判断 文件 文件夹 链接
- shell判断文件或文件夹是否存在
- 占位
- HibernateTools插件安装
- 邮箱地址的自动匹配
- 贪吃蛇
- DBconnection连接不上
- linux shell 学习(三)——判断文件和文件夹
- TCP中的三次握手
- Java基本数据类型
- centos安装docker
- ecshop 后台菜单栏目【注释】
- Spring笔记总结2
- Unity3D中通过四元数得到欧拉角
- c++简单的单链
- Java字符串、输入和格式化输出