linux bash 文件 路径 目录 是否 存在

Linux

2017-07-11

214

0

技术:linux bash

运行环境:bash + centos7

demo功能:bash查看文件或者目录是否存在

ps: 虽然简单, 但是注意书写的语法,不然报 中括号啥的错误

文件是否存在

targetfile="/www/ROOT.war"

if [ ! -f "$targetfile" ]; then
        echo 文件不存在
        exit 0
fi

目录是否存在

attachment="/attachment"
if [  -d "$attachment" ]; then
  echo 存在
fi

欢迎添加微信,互相学习↑↑↑ -_-

发表评论

全部评论:0条

白老虎

programming is not only to solve problems, ways to think