Linux shell script find 作为 if 判断条件

来源:互联网 发布:高级软件测试认证 编辑:程序博客网 时间:2024/05/20 23:35

学习笔记:
目的:查找当前文件夹下7小时以内的文件,如果有文件打印”successful”,否则打印“fail”

cur_time=$(date "+%Y-%m-%d-%H")#cur_time='12-06'echo $cur_timeif#       ls -lrt --time-style '+%Y-%m-%d-%H' | grep $cur_time        ls -lrt --time-style='+%Y-%m-%d-%H' | grep $cur_time >/dev/nullthen        echo "exist file $?"else        echo "no exist file $?"fiif        find . -cmin -420 -name 'dail*' -exec ls -lrt {} \; | grep -v '^d' >/dev/nullthen        echo "successful"else        echo "fail"fi

这里写图片描述

原创粉丝点击