Linux下如何快速删除海量文件
日常运维中,某些服务器几十万的文件需要删除,该如果快速删除?
rm
[sys@sys-test-lv-101 ~]$ cd test
[sys@sys-test-lv-101 test]$ for i in $(seq 1 500000).log;do echo "this is test">>${i}.log;done
[sys@sys-test-lv-101 test]$ time rm -f *.log
-bash: /bin/rm: Argument list too long
find + delete
[sys@sys-test-lv-101 ~]$ cd test
[sys@sys-test-lv-101 test]$ for i in $(seq 1 500000).log;do echo "this is test">>${i}.log;done
[sys@sys-test-lv-101 ~]$ time find test/ -type f -delete
real 0m25.030s
user 0m0.515s
sys 0m13.969s
rsync + delete
[sys@sys-test-lv-101 ~]$ cd test/
[sys@sys-test-lv-101 test]$ for i in $(seq 1 500000).log;do echo "this is test">>${i}.log;done
[sys@sys-test-lv-101 ~]$ time rsync --delete-before -a empty/ test/
real 0m15.497s
user 0m1.175
从测试结果可以看出rsync效率最高