0
点赞
收藏
分享

微信扫一扫

shell脚本之文件属性判断

快乐小鱼儿_9911 2022-06-06 阅读 48
#!/bin/bash
file="./var.sh"

if [ -r $file ]
then
echo "can read"
else
echo "can not read"
fi

if [ -w $file ]
then
echo "can write"
else
echo "can not write"
fi

if [ -x $file ]
then
echo "can exec"
else
echo "can not exec"
fi

if [ -f $file ]
then
echo "common file"
else
echo "special file"
fi

if [ -d $file ]
then
echo "is dir"
else
echo "is not dir"
fi

if [ -e $file ]
then
echo "file exist"
else
echo "file not exist"
fi

if [ -s $file ]
then
echo "file is not empty"
else
echo "file not exist"
fi

输出结果:

can read
can write
can not exec
common file
is not dir
file exist
file is not empty

 


举报

相关推荐

0 条评论