shell 判断文件/目录是否为空
2010-05-29 17:06
302 查看
刚开始写shell,很多都不会在网上东找找西找找.
#判断文件目录是否为空
第一种:
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
-----------------------------------------------------------
#判断文件目录是否为空
第一种:
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
-----------------------------------------------------------
相关文章推荐
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell 判断文件、目录是否存在
- shell判断文件,目录是否存在或者具有权限
- Shell脚本中判断文件,目录是否存在或者具有权限
- 在Shell里面判断字符串是否为空 ,文件存在,目录存在
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权
- shell 判断文件、目录是否存在
- shell 判断文件、目录是否存在
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断文件,目录是否存在或者具有权限
- shell判断目录或者文件是否存在