删除50万个文件,各种方法的速度对比:
先创建50万个文件:
for i in $(seq 1 500000); do echo testing >> $i.txt; done
各种删除当前目录文件方法,先进入该目录(比如PHP的sessions目录),然后执行以下命令:
time rm -f * 删除失败,返回 /bin/rm: Argument list too long
time find ./ -type f -exec rm {} ;
time find ./ -type f -delete
time rsync -a --delete EmptyDir/ BigDir/
time perl -e 'for(<*>){((stat)[9]<(unlink))}'
结果:
perl用了1分钟
rsync用了3分钟
find with -delete用了5分钟
find with -exec用了14分钟
直接用rm结果是删除失败.
如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!
赞0
添加新评论0 条评论