`

在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---------------

分享到:
评论
1 楼 wjason 2008-07-04  
center的评论:

第二个,至少要 `find . -type d` 吧

这样好像也行
for nulldir in $(find . -type d | du | awk '{if ($1 == 4) print $2}');do rm -rf $nulldir; done

相关推荐

Global site tag (gtag.js) - Google Analytics