if [ -a “/mnt/myfile” ],if [ ! -a “/mnt/myfile” ] 例子:文件判断 文件夹不存在则创建 1 2 3 4 5 if[ ! -d"/data/"];then mkdir/data else echo"文件夹已经存在" fi 文件存在则删除 1 2 3 4 5 if[ ! -f"/data/filename"];then echo"文件不存在" else rm-f/data/filename...
import os path ='/home/data/logs' ifnot os.path.exists(path): os.mkdir(path)
importospath='/home/data/logs'ifnotos.path.exists(path):os.mkdir(path) 1. 2. 3. 4.
echo "$dir not exists" mkdir "$dir" else echo "$dir exists!" fi ---
$ mkdir -p dir or: if [[ ! -e $dir ]]; then mkdir $dir elif [[ ! -d $dir ]]; then echo "$dir already exists but is not a directory" 1>&2 fi which will create the directory if it doesn't exist, but warn you if the name of the directory you're trying to ...
if [ "`ls -A $DIRECTORY`" = "" ]; then echo "$DIRECTORY is indeed empty"else echo "$DIRECTORY is not empty"fi 分类: 2010-05-29 17:06 3512⼈阅读 (0) 收藏 刚开始写shell,很多都不会在⽹上东找找西找找.#判断⽂件⽬录是否为空 第⼀种:emptydir.sh --- #!/bin/sh DIRECTO...
判断表达式中直接用-d判断即可,参考代码如下:myFolder=/home/test if[-d$myFolder];then echo"Folderexists!"else echo"Folderdoesn'texist!"fi Shell基本上是一个命令解释器,类似于DOS下的command。它接收用户命令(如ls等),然后调用相应的应用程序。较为通用的shell有标准的Bourne shell (sh)和...
1. shell判断文件,目录是否存在或者具有权限 2. #!/bin/sh 3.4. myPath="/var/log/httpd/"5. myFile="/var /log/httpd/access.log"6.7. # 这里的-x 参数判断$myPath是否存在并且是否具有可执行权限 8. if [ ! -x "$myPath"]; then 9. mkdir "$myPath"10. fi 11.12. # ...