当前位置:网站首页>shell判断文件是否存在,判断文件大小是否为0
shell判断文件是否存在,判断文件大小是否为0
2022-07-20 12:38:00 【SYBY】
使用-f,-d,-e分别判断:普通文件是否存在,目录是否存在,某东西是否存在,不限定为文件
if [ ! -d "$filedir" ];then
echo "`date`, ${filedir} does not exist. "
exit 128
fi
使用-s判断文件大小是否为0,以下代码表示如果$filename所表示的文件大小为0,则执行echo语句,并退出脚本。
if [ ! -s "$filename" ];then
echo "`date`, The ${filename} size is zero, failed. "
exit 128
fi
128为常用退出码,代表信号产生。
其他常见退出码,可以参考
题外话
shell脚本中的本,使用${参数名},可以避免变量与其他字段粘合连读的情况。
边栏推荐
- How to improve the clarity of LED display?
- Real interview question 2
- Yes, another testing partner with a monthly salary of more than 10000!
- What is the difference between dall-e2 and imgen? Reddit hot post inventory effect difference
- Surface strongest editor sublime | regular expression skills
- Lesson 2 WiFi experiment of hi3861 -api-4
- IDR of R language epidisplay package The display function obtains the summary statistical information of Poisson regression Poisson model (initial event density ratio IDR value, adjusted event density
- [redis] summary of common knowledge points
- 模块学习(四)——超声波测距
- 新建第一个HBuilder项目
猜你喜欢
同步原语:锁
新建第一个HBuilder项目
VPS、独服和云服务器哪种最适合您的业务?
Lesson 2 WiFi experiment of hi3861 -api-2
redis排行榜
《流浪(Stray)》工人外套与安全帽获得方法 工人安全帽怎么获得
redis实现周边景点由近到远排序
史上最全的mysql数据类型汇总-(上)
After Huawei, no one can stop apple. It is expected that iphone14 will be popular with hundreds of millions of domestic users
开源demo| ARCall 小程序开源示例发布
随机推荐
包揽数理化国际奥赛全部第一,全员金牌,网友:中国队太秀了
Module learning (IV) - Ultrasonic Ranging
面試真題2
【线性DP】数字三角形
RENIX_IPv6自动配置——网络测试仪实操
多线程与高并发(二)—— Synchronized 加锁解锁流程
第2讲 Hi3861的WiFi实验-API-3
Ovirt: API interface +keystone interface +neutron interface example
Solve the failure of updating entity data model after visual studio 2019 update and upgrade
how to deal with " no such file error or diretory" error for a new programmer in QT creator
C语言练习项目:三子棋
PG优化篇--执行计划
harbor安装
玫瑰通行证发放中!
R language Kolmogorov Smirnov test compares whether the two samples come from the same distribution: ks The test function performs Kolmogorov Smirnov test to compare whether the two samples are from t
uva11100
九章云极DataCanvas YLearn因果学习开源项目:从预测到决策
kubernetes创建一个dashboard只读权限的用户(具有exec权限)
VIM encrypted file "recommended collection"
shell脚本编程-获取系统信息