遍历文件夹里的文件格式

本文介绍了一个用于统计指定目录下txt、xml、map及其他类型文件数量的Shell脚本,并将统计结果记录到日志文件中,最后通过邮件发送统计结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/bin/sh

. $HOME/.profile

 

DIRECTORY=/data/tran_data/20170526

LOGDIR=/data/tran_data/20170526/log

LOG=$LOGDIR/countdir.log

begin1=`date +"%m/%d/%Y %T"`

 

txt_count=0  

xml_count=0  

map_count=0  

other_count=0 

 

mail_user=""

 

DIRECTORY=$1  

if [ "`ls -A $DIRECTORY`" = "" ]; then  

  echo "$DIRECTORY is empty"  

else  

  echo "$DIRECTORY is not empty"  

fi  

  

    for file in ` ls $DIRECTORY `  

    do  

        if [ -f $DIRECTORY"/"$file ]  

        then  

        fileType=${file##*.}  

                        if [ "$fileType" = "txt" ];  

                         then  

                          txt_count=$(($txt_count+1))  

                        elif  [ "$fileType" = "xml" ];  

                         then  

                          xml_count=$(($xml_count+1))  

                        elif  [ "$fileType" = "map" ];  

                         then  

                          map_count=$(($map_count+1))  

                        else  

                          other_count=$(($other_count+1))  

                        fi  

                fi  

    done  

echo "'txt file count:'$txt_count" >>$LOG  

echo "'xml file count:'$xml_count" >>$LOG 

echo "'map file count:'$map_count" >>$LOG 

echo "'other file count:'$other_count" >>$LOG 

 

end1=`date +"%T"`

echo "Begin=[ ${begin1} ] - End=[ ${end1} ]">>$LOG 

mailx -s "COUNTDIR, Begin=[ ${begin1} ] - End=[ ${end1} ]" ${mail_users} < /data/tran_data/20170526/$LOG 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值