web服务器上有个目录,它的结构是这样的,首先有256个一级子目录和一个特殊目录,另外这256个一级子目录下还有256个二级子目录(特殊目录除外)。在这些二级子目录下有很多小文件,而且是每时每刻都会生成很多个。 虽然文件不大,但是时间长了,逐渐发现该分区的下inode快被占用满了。 所以请写一个小脚本,实现每天删除两天前的小文件,注意忽略那个特殊的一级子目录default。
目录: /data/web/abc/
二/三级子目录: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de default df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff (三级子目录下没有default目录)
参考脚本:
{{{密码回复可见}}}
目录: /data/web/abc/
二/三级子目录: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de default df e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff (三级子目录下没有default目录)
参考脚本:
{{{密码回复可见}}}
0
本帖最后由 Hello_Lemon 于 2013-10-30 14:53 编辑
find /data/web/abc/ -mtime +2 -path "/data/web/abc/default" -prune -o -print|xargs rm -rf
find /data/web/abc/ -mtime +2 -path "/data/web/abc/default" -prune -o -print|xargs rm -rf
0
忽略一级和二级目录中的default子目录,只删除文件
find /data/web/abc/ -path "/data/web/abc/default" -prune -o -path "/data/web/abc/*/default" -prune -o -mtime +2 -type f -print -exec rm -rf {} \;
find /data/web/abc/ -path "/data/web/abc/default" -prune -o -path "/data/web/abc/*/default" -prune -o -mtime +2 -type f -print | xargs rm -rf
find /data/web/abc/ -path "/data/web/abc/default" -prune -o -path "/data/web/abc/*/default" -prune -o -mtime +2 -type f -print -exec rm -rf {} \;
find /data/web/abc/ -path "/data/web/abc/default" -prune -o -path "/data/web/abc/*/default" -prune -o -mtime +2 -type f -print | xargs rm -rf
0
#!/bin/bash
## This script is for delete mini files to release inode space.
## Writed by Louis on 2014/08/29 22:55
dir=/newdata/web/abc
for d1 in `ls $dir`; do
if echo $d1|grep -q 'default' ; then
continue
else
find $dir/$d1 -mmin +1|xargs rm -rf
fi
done
#!/bin/bash
## This script is for delete mini files to release inode space.
## Writed by Louis on 2014/08/29 22:55
dir=/newdata/web/abc
for d1 in `ls $dir`; do
if echo $d1|grep -q 'default' ; then
continue
else
find $dir/$d1 -mmin +1|xargs rm -rf
fi
done
0
更正:
#!/bin/bash
## This script is for delete mini files to release inode space.
## Writed by Louis on 2014/08/29 22:55
dir=/newdata/web/abc
for d1 in `ls $dir`; do
if echo $d1|grep -q 'default' ; then
continue
else
find $dir/$d1 -mtime +2|xargs rm -rf
fi
done
#!/bin/bash
## This script is for delete mini files to release inode space.
## Writed by Louis on 2014/08/29 22:55
dir=/newdata/web/abc
for d1 in `ls $dir`; do
if echo $d1|grep -q 'default' ; then
continue
else
find $dir/$d1 -mtime +2|xargs rm -rf
fi
done
0
find /data/web/abc -path /data/web/abc/default -prune -o -type f -mtime +2 -print | xargs -i rm -f {}
0
#!/bin/bash
for i in `ls /data/web/abc/|grep -v default`
do
for j in `ls $i`
do
find $i/$j -type f -mtime +2|xargs rm -rf
done
done
for i in `ls /data/web/abc/|grep -v default`
do
for j in `ls $i`
do
find $i/$j -type f -mtime +2|xargs rm -rf
done
done
0
本帖最后由 qq20847697 于 2015-3-18 16:48 编辑
find /data/web/abc -path "/data/web/abc/default" -prune -o -type f -mtime +2 -print | xargs rm -rf
find /data/web/abc -path "/data/web/abc/default" -prune -o -type f -mtime +2 -print | xargs rm -rf
0
for i in `ls /data`
do
if [ $i -eq default]
continue
for j in `ls $i`
do
if [ $j -eq default]
continue
for k in `ls $j`
do
if awk '{print $7}' 1.txt<`ls -l $k`==`date -d "-2 days" +%d` || `date -d "-2 days" +%d`
then
rm -rf $k
fi
done
rm -rf $j
done
rm -rf $i
done
for i in `ls /data`
do
if [ $i -eq default]
continue
for j in `ls $i`
do
if [ $j -eq default]
continue
for k in `ls $j`
do
if awk '{print $7}' 1.txt<`ls -l $k`==`date -d "-2 days" +%d` || `date -d "-2 days" +%d`
then
rm -rf $k
fi
done
rm -rf $j
done
rm -rf $i
done
0
本帖最后由 zql254 于 2016-1-5 22:15 编辑
for i in `ls |grep -v default`; do
for n in `ls $i|grep -v default`; do
find ./$i/$n -type f -mtime +2|xargs rm -f
done
done
for i in `ls |grep -v default`; do
for n in `ls $i|grep -v default`; do
find ./$i/$n -type f -mtime +2|xargs rm -f
done
done
0
for i in `ls |grep -v default`; do
for n in `ls $i|grep -v default`; do
find ./$i/$n -type f -mtime +2|xargs rm -f
done
done
for n in `ls $i|grep -v default`; do
find ./$i/$n -type f -mtime +2|xargs rm -f
done
done
0
#!/bin/sh
filedir='/data/web/abc'
for i in `ls $filedir`
do
if [ echo$i |grep default ];then
continue
else
find $filedir/$i -mtime +2 | xargs rm -rf
fi
done
filedir='/data/web/abc'
for i in `ls $filedir`
do
if [ echo$i |grep default ];then
continue
else
find $filedir/$i -mtime +2 | xargs rm -rf
fi
done
0
#!/bin/bash
for i in `ls /data/web/abc/ |grep -v default`
do
for j in `ls $i`
do
find $i/$j -type f -mtime +2 |xargs rm -rf
done
done
for i in `ls /data/web/abc/ |grep -v default`
do
for j in `ls $i`
do
find $i/$j -type f -mtime +2 |xargs rm -rf
done
done
0
#!/bin/bash
cd /data/web/abc/
for i in `find . -type d -mtime +2`
do
if [ $i -eq default ];then
continue
else
rm -rf $i
fi
done
cd /data/web/abc/
for i in `find . -type d -mtime +2`
do
if [ $i -eq default ];then
continue
else
rm -rf $i
fi
done
0
本帖最后由 duyanbin 于 2016-4-9 23:06 编辑
#!/bin/bash
DIR=/data/web/
if [ -d $DIR ] ; then
find $DIR -type f -a \( ! -regex "./.*/default/.*" -a ! -regex "./default/.*" \) -a -mtime +2 -print0 | xargs rm -f
else
echo "$DIR not exsit"
fi
#!/bin/bash
DIR=/data/web/
if [ -d $DIR ] ; then
find $DIR -type f -a \( ! -regex "./.*/default/.*" -a ! -regex "./default/.*" \) -a -mtime +2 -print0 | xargs rm -f
else
echo "$DIR not exsit"
fi
0
本帖最后由 luckytodd 于 2016-6-5 00:28 编辑
find /data/web/abc/ -type d -mtim +2 |grep -v "default"|xargs rm -rf
find /data/web/abc/ -type d -mtim +2 |grep -v "default"|xargs rm -rf
0
- find /data/web/abc/ -mtime +2 -path -mindeps 2 "/data/web/abc/default" -prune -o -print|xargs rm -rf
编辑回复