Linux下如何快速删除海量文件

zhangwentaohh 2020-05-25

日常运维中,某些服务器几十万的文件需要删除,该如果快速删除?

rm

[ ~]$ cd test
[ test]$ for i in $(seq 1 500000).log;do echo "this is test">>${i}.log;done
[ test]$ time rm -f *.log
-bash: /bin/rm: Argument list too long

find + delete

[ ~]$ cd test
[ test]$ for i in $(seq 1 500000).log;do echo "this is test">>${i}.log;done
[ ~]$ time find test/ -type f -delete

real    0m25.030s
user    0m0.515s
sys 0m13.969s

rsync + delete

[ ~]$ cd test/
[ test]$ for i in $(seq 1 500000).log;do echo "this is test">>${i}.log;done
[ ~]$ time rsync --delete-before -a empty/ test/

real    0m15.497s
user    0m1.175

从测试结果可以看出rsync效率最高

相关推荐