linux该怎么判断文件是否存在?我们一起来了解一下吧。
1、access函数
access函数按照实际用户ID和实际组进行访问权限测试,使用F_OK测试文件是否存在。
2、oepndir函数
opendir函数用来打开文件目录,成功返回指针,出错返回NULL。实现如下:
linux系统如何去实现检查文件夹是否存在不存在则创建?
linux shell脚本检查文件夹是否存在不存在则创建
date_str=`date %Y%m%d`dir=/root/crontab/logfunction run_mkcurrent_dir(){my_dir="$dir/$date_str" if [ ! -d "$my_dir" ]; then echo "创建文件夹" mkdir $my_direlse echo "文件夹已存在"fi}run_mkcurrent_dir;