首先建立50万个文件

➜ test for i in $(seq 1 500000);do echo text >>$i.txt;done

1. rm

➜ test time rm -f *

zsh: sure you want to delete all the files in /home/hungerr/test [yn]? y

zsh: argument list too long: rm

rm -f * 3.63s user 0.29s system 98% cpu 3.985 total

由于文件数量过多,rm不起作用。

2. find

➜ test time find ./ -type f -exec rm {} \;

find ./ -type f -exec rm {} \; 49.86s user 1032.13s system 41% cpu 43:19.17 total

大概43分钟,我的电脑。。。。。。边看视频边删的。

3. find with delete

➜ test time find ./ -type f -delete

find ./ -type f -delete 0.43s user 11.21s system 2% cpu 9:13.38 total

用时9分钟。

4. rsync

首先建立空文件夹blanktest

➜ ~ time rsync -a --delete blanktest/ test/

rsync -a --delete blanktest/ test/ 0.59s user 7.86s system 51% cpu 16.418 total

16s,很好很强大。

5. Python

import os

import timeit

def main():

for pathname,dirnames,filenames in os.walk('/home/username/test'):

for filename in filenames:

file=os.path.join(pathname,filename)

os.remove(file)

if __name__=='__main__':

t=timeit.Timer('main()','from __main__ import main')

print t.timeit(1)  

1

2

➜ ~ python test.py

529.309022903

大概用时9分钟。

6. Perl

➜ test time perl -e 'for(<*>){((stat)[9]<(unlink))}'

perl -e 'for(<*>){((stat)[9]<(unlink))}' 1.28s user 7.23s system 50% cpu 16.784 total

16s,这个应该最快了。

统计一下:

命令 耗费时间

rm 文件数量太多,不可用

find with -exec 50万文件耗时43分钟

find with -delete 9分钟

Perl 16s

Python 9分钟

rsync with -delete 16s

CentOS下下删除大量文件的更多相关文章

  1. Mac系统下下删除加锁文件方法|使用终端命令强制清除废纸篓中的文件

    链接地址1:http://jingyan.baidu.com/article/fdffd1f8e39403f3e98ca195.html 在Mac OS X下,无法删除的文件无外乎三种情况:1,文件( ...

  2. Centos 自动删除日志文件的Shell代码

    #!/bin/bash # #判断文件夹内文件的大小,如果大于一定的数值,那么删除 # echo '判断文件夹内文件的大小,如果大于一定的数值,并且文件名称包含数字(年月日)的删除,那么删除' pat ...

  3. centos定时删除log文件

    #!bin/bash #获取年 time=$(date "+%Y") #查找并删除7天前的文件 find /opt/applog/travelsky -type f -mtime ...

  4. CentOS Maven 删除 *.lastUpdated文件

    find . -name "*.lastUpdated" -exec rm -rf {} \;

  5. centos彻底删除文件夹、文件命令(centos 新建、删除、移动、复制等命令)

    centos彻底删除文件夹.文件命令(centos 新建.删除.移动.复制等命令: 1.新建文件夹 mkdir 文件名 新建一个名为test的文件夹在home下 view source1 mkdir ...

  6. 转发:centos彻底删除文件夹、文件命令(centos 新建、删除、移动、复制等命令)

    http://blog.csdn.net/lpdx111/article/details/16877725 centos彻底删除文件夹.文件命令(centos 新建.删除.移动.复制等命令: 1.新建 ...

  7. 转:centos彻底删除文件夹、文件命令

    转自:http://www.cnblogs.com/kluan/p/4458296.html centos彻底删除文件夹.文件命令(centos 新建.删除.移动.复制等命令: 1.新建文件夹 mkd ...

  8. centos彻底删除文件夹创建文件

    centos彻底删除文件夹.文件命令(centos 新建.删除.移动.复制等命令: 1.新建文件夹 mkdir 文件名 新建一个名为test的文件夹在home下 view source1 mkdir ...

  9. centos彻底删除文件夹、文件命令

    [1]新建文件夹 格式:mkdir 文件名 view source1 mkdir /home/test     新建一个名为test的文件夹在home下 [2]新建文本 vi /home/test.s ...

随机推荐

  1. STL之map

    参见http://www.cplusplus.com/reference/map/map/ template < class Key,                               ...

  2. 软件工程随堂作业--随机产生30到四则运算(c语言)

    #include "stdio.h" #include "math.h" #include "stdlib.h" #include" ...

  3. 小组开发项目针对性的NABC分析

    单独就我们团队开发项目——重力解锁的功能特点而言,我们解决了智能手机屏幕解锁的乏味和繁琐的特点,显得更有趣味性和独特性,更符合现代人追随时尚的潮流:我们根据个人的不同喜好和便利性来设定一些动作,利用重 ...

  4. android 安装应用程序apk安装不了

    今天用测试机的时候遇到这个问题 解决办法: 在设置里面找到应用程序管理安全设置,,[允许未知来源程序安装] -------------大致以上思路,具体按钮名称我就不重新去找了------------ ...

  5. 单点登录(iwantmoon.com出品)

    早年便听到单点登录,一直因为感觉很简单,就没有动手去弄,正好现在公司有要求,那么OK,直接做了一个单机版的单点登录. 原理,可以参考SSO. Now,我们来看看我的实现吧.看下图 我们平时所做的登录, ...

  6. HDU 5693 D Game 区间dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5693 题解: 一种朴实的想法是枚举选择可以删除的两个或三个数(其他的大于三的数都能凑成2和3的和), ...

  7. 剑指offer--13题

    #include "stdafx.h" #include <iostream> using namespace std; void FirstNoRepeatCh(co ...

  8. WCF基本概念

    WCF是基于Windows平台下开发和部署服务的SDK.服务是一组公开的功能集合. 面向服务(Service Orientatio,SO)是一组原则的抽象, 面向服务的应用程序(SOA)将众多服务聚集 ...

  9. [noip2005提高]过河 dp

    由于L的范围到了109,用普通dp做肯定是不成了: 可以观察到M的数量很小,dp在转移的过程中有大量的无用转移: 可以想到压缩范围,问题是如何压缩,观察若S=9,T=10时,能到达的点,9,10,18 ...

  10. The Brain vs Deep Learning Part I: Computational Complexity — Or Why the Singularity Is Nowhere Near

    The Brain vs Deep Learning Part I: Computational Complexity — Or Why the Singularity Is Nowhere Near ...