shell脚本之文件属性判断

linux

 

#!/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


如果发现下载不了或者地址失效,请联系客服QQ: 2323178881
找资料 » shell脚本之文件属性判断

提供最优质的资源集合

立即查看 了解详情