在Unix/Linux伟大哲学的指导下,linux的文件处理确实挺强悍。

写了一个删除不含有我们修改标记以及空文件夹的脚本。确实很好用,代码行也很少。赞一个。

1. del file

#!/bin/sh
# -------- I contain myself so i will not be deleted ----

# ------------ del file start ---------------------
#for file in $(grep -R -L -i FOMA08-1st *)
for file in $(grep -R -L -i F8_1ST *)
do
    echo $file
    rm -f $file
done
# ------------ del file end ---------------------

 

2 del folder

#!/bin/sh
# ------------ I contain FOMA08-1st and F8_1ST ---------------------
# ----------------- del dir without file start---------------


path=$(pwd)
echo "$path"
oldNum="1"
newNum="0"
while [ "$oldNum" -ne "$newNum" ]
do
    oldNum="`find | wc -l`"

    for dir in $(find)
    do
        if [ -d $dir ]
        then
            if [ "`ls -al $dir | wc -l`" -gt "3" ]
            then
                echo
                #echo "     file exist"
            else
                echo "$dir"
                echo "     del it, because it does not contain any file"
                rm -rf $dir
            fi
        fi
    done

    newNum="`find | wc -l`"
done
# ----------------- del dir without file end---------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值