linux shell

关注公众号 jb51net

关闭
首页 > 脚本专栏 > linux shell > linux shell文件系统属性

linux shell之通过标识测试文件系统属性的方法示例

作者:chenyu_insist

今天小编就为大家分享一篇关于linux shell之通过标识测试文件系统属性的方法示例,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧

1 通过标识测试文件系统属性

2 代码测试

#/bin/bash
fpath="/home/chenyu/Desktop/linux/dabian/shell/1.txt"
#fdir="/home/chenyu/Desktop/linux/dabian/shell/back"
fdir="./back"
fexe="./file.sh"
#判断是否为文件
if [ -e $path ];
then
 echo "file "${fpath}" exist";
else
 echo "file "${fpath}" dose not exist"
fi
#判断是否为目录
if [ -d $fdir ];
then
 echo "dictionary "${fdir}" exist";
else
 echo "dictionary "${fdir}" dose not exist"
fi
#判断是否为可执行文件
if [ -x $fexe ];
then
 echo ${fexe}" can exec"
else
 echo ${fexe}" can not exec"
fi

3 运行结果

file /home/chenyu/Desktop/linux/dabian/shell/1.txt exist
dictionary ./back exist
./file.sh can exec

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对脚本之家的支持。如果你想了解更多相关内容请查看下面相关链接

您可能感兴趣的文章:
阅读全文