Shell determines if file/directory is emptyCategory: Linux 2010-05-29 17:06 3512 People read review (0) Favorite report Shell file
At the beginning of the shell, a lot of the internet is not looking for the West looking for.
#判断文件目录是否为空
The first type:
emptydir.sh
-----------------------------------------------------------
#!/bin/sh
Directory=$1
If ["' ls-a $DIRECTORY '" = ""]; Then
echo "$DIRECTORY is indeed empty"
Else
echo "$DIRECTORY is not empty"
Fi
-----------------------------------------------------------
The second type:
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
-----------------------------------------------------------