黑松山资源网 Design By www.paidiu.com
本文主要介绍了linux shell 中判断文件、目录是否存在的方法,分享给大家
-e filename 如果 filename存在,则为真
-d filename 如果 filename为目录,则为真
-f filename 如果 filename为常规文件,则为真
-L filename 如果 filename为符号链接,则为真
-r filename 如果 filename可读,则为真
-w filename 如果 filename可写,则为真
-x filename 如果 filename可执行,则为真
-s filename 如果文件长度不为0,则为真
-h filename 如果文件是软链接,则为真
常用例子
如果存在某文件,则删除
if [ -f trials ]; then rm ${result_path}trials; fi
如果没有文件夹,则创建
if [ ! -d $result_name ];then mkdir -p $result_name fi
shell命令判断文件或文件夹是否存在,先直接看实例:
#!/bin/sh #判断文件存在,判断是否为文件夹等 testPath="/Volumes/MacBookProHD/Mr.Wen/08 shell命令" testFile="/Volumes/MacBookProHD/Mr.Wen/08 shell命令/fileWen" #判断文件夹是否存在 -d if [[ ! -d "$testPath" ]]; then echo "文件夹不存在" else echo "文件夹存在" fi #判断文件夹是否存在,并且具有可执行权限 if [[ ! -x "$testFile" ]]; then echo "文件不存在并且没有可执行权限" else echo "文件存在并有可执行权限" fi #判断文件是否存在 if [[ ! -f "$testFile" ]]; then echo "文件不存在" else echo "文件存在" fi
在shell命令脚本编写当中,会遇到各种对文件的判断,除了以上常用的判断,还有其他的可以使用,如下:
shell 判断文件内容是否改变
判断文件内容是否改变:
1)md5值判断
2)diff 判断
#添加日志时间戳 function fn_showlog() { local curtime; curtime=`date +"%Y%m%d-%H:%M:%S"` echo "$curtime ------ $1"; } #判断文件内容是否一致 function diff_file(){ for file in `ls $1` do if [ ! -f "$2$file" ];then fn_showlog "存在新增文件:$2$file" return 0 else diff $file $2$file if [ $"文件内容发生变化:$file" return 0 fi fi done return 1 } diff_file "python*Ip" "/home/admin/tools/" if [ $"内容发生改变......" else fn_showlog "内容未发生改变,退出脚本!" exit 0 fi
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2024年10月10日
2024年10月10日
- 泰迪罗宾.1984-天外人(2004环球复黑王)【宝丽金】【WAV+CUE】
- 《网络夜色风 2CD》[WAV/分轨][1GB]
- 《发烧金曲金装影视 绝对超值不容错过 2CD》[WAV/分轨][600MB]
- 《林俊杰 最具影响力的创作歌手 JJ林俊杰 2CD》[WAV+CUE][940MB]
- 《CATO 黄油猫》评测:和物理老师说再见……吗?
- 《Ara:不为人知的历史》:抗衡《文明》?4X游戏挑战者
- 《艾诺提亚:失落之歌》:令人失望的意大利特色试验品
- 《蛋仔派对》斯派克皮肤图鉴
- 黑神话悟空九种美酒在哪获得 黑神话悟空九种酒位置一览
- 黑神话悟空全丹药配怎么获取 黑神话悟空全丹药配方获取方式介绍
- 梁汉文2014-听后感[天凯唱片][WAV+CUE]
- 徐小明1984-剑胆琴心(LP版)[文志][WAV+CUE]
- 韩红-精选(庆功版)[WAV整轨]
- 《暗喻幻想:ReFantazio》获IGN法国满分评价:完美的新标杆之作
- 《暗喻幻想》开分后 开发者小姐姐感动到热泪盈眶