if判断目录 linux,shell 判断文件/目录是否为空
#判断文件目录是否为空第一种:emptydir.sh-----------------------------------------------------------#!/bin/shDIRECTORY=$1if [ "`ls -A $DIRECTORY`" = "" ]; thenecho "$DIRECTORY is indeed empty"elseecho "$DIRECTORY is
#判断文件目录是否为空
第一种:
emptydir.sh
-----------------------------------------------------------
#!/bin/sh
DIRECTORY=$1
if [ "`ls -A $DIRECTORY`" = "" ]; then
echo "$DIRECTORY is indeed empty"
else
echo "$DIRECTORY is not empty"
fi
-----------------------------------------------------------
第二种:
count.sh
-----------------------------------------------------------
#!/bin/sh
count=`ls $*|wc -w`
if [ "$count" > "0" ];
then
echo "file size $count"
else
echo "empty!"
fi
-----------------------------------------------------------
#目录是否存在
ifmkdir.sh
-----------------------------------------------------------
#!/bin/sh
dir="test"
if [ ! -d $dir ]; then
echo "$dir not exists"
mkdir "$dir"
else
echo "$dir exists!"
fi
-----------------------------------------------------------
更多推荐
所有评论(0)