国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Linux > 正文

Linux下刪除大量文件

2024-06-28 13:28:15
字體:
供稿:網(wǎng)友
linux下刪除大量文件

主要參考了http://www.slashroot.in/which-is-the-fastest-method-to-delete-files-in-linux

首先建立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]? yzsh: argument list too long: rmrm -f *  3.63s user 0.29s system 98% cpu 3.985 total

由于文件數(shù)量過多,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,很好很強(qiáng)大。

5. Python
import osimport timeitdef 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)  
?  ~  python test.py529.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,這個應(yīng)該最快了。


統(tǒng)計一下:

命令耗費(fèi)時間
rm文件數(shù)量太多,不可用
find with -exec50萬文件耗時43分鐘
find with -delete9分鐘
Perl16s
Python9分鐘
rsync with -delete16s

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 肇东市| 阿图什市| 新野县| 临颍县| 蓝山县| 广西| 佳木斯市| 油尖旺区| 永兴县| 甘洛县| 大埔县| 兰坪| 桦甸市| 托里县| 四川省| 密山市| 巴林左旗| 乌拉特中旗| 上林县| 厦门市| 酉阳| 房产| 方城县| 绿春县| 民乐县| 奉化市| 团风县| 岚皋县| 德惠市| 车致| 福鼎市| 陈巴尔虎旗| 东阳市| 北辰区| 阿巴嘎旗| 平谷区| 浦东新区| 襄城县| 卓资县| 乌兰县| 南丹县|