需求
有的开发代码写不好,导致单目录下缓存文件近900W个,要求删除这900W个文件,怎搞?
分析
如果是使用rm -rf 肯定不好,会卡死,提示参数过长,看来是把文件名当成参数了。顶多就80W个,已经很不错了。明显满足不了要求
可以用rsync同步清空,rsync统计文件名不会全部写在内存中了,超过一定数据会放在磁盘里,所以适合删除文件数比较多的情况
操作
[root@vm6Temp.old]$ ls -1f |wc -l 8767765 [root@vm6 tools]# cd /disk1/tools [root@vm6 tools]# time rsync --delete-before -d --progress --stats empty/ Temp.old/ ... Number of files: 1 Number of files transferred: 0 Total file size: 0 bytes Total transferred file size: 0 bytes Literal data: 0 bytes Matched data: 0 bytes File list size: 15 File list generation time: 0.001 seconds File list transfer time: 0.000 seconds Total bytes sent: 22 Total bytes received: 12 sent 22 bytes received 12 bytes 0.00 bytes/sec total size is 0 speedup is 0.00 rsync warning: some files vanished before they could be transferred (code 24) at main.c(1039) [sender=3.0.6] real 753m37.972s(约12.5小时)

最低0.47元/天 解锁文章
1890

被折叠的 条评论
为什么被折叠?



