Shell determines if file/directory is empty

Source: Internet
Author: User
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

-----------------------------------------------------------

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.