• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 298  文章 - 377  trackbacks - 0
            <2021年7月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            常用鏈接

            留言簿(34)

            隨筆分類

            隨筆檔案

            文章檔案

            相冊

            收藏夾

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            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]? 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

            1
            2
            3
            4
            5
            6
            7
            8
            9
            10
            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 -exec50萬文件耗時43分鐘
            find with -delete9分鐘
            Perl16s
            Python9分鐘
            rsync with -delete16s
            posted on 2021-07-11 15:07 聶文龍 閱讀(195) 評論(0)  編輯 收藏 引用 所屬分類: Linux
            996久久国产精品线观看| 久久久久亚洲AV综合波多野结衣| 久久国产欧美日韩精品| 囯产极品美女高潮无套久久久| 国产精品99久久精品| 久久精品国产亚洲av影院| 久久综合丝袜日本网| 久久婷婷五月综合色奶水99啪| 无码国内精品久久人妻| 精品久久香蕉国产线看观看亚洲 | 久久激情五月丁香伊人| 久久久精品国产Sm最大网站| 中文字幕久久波多野结衣av| 久久久久亚洲AV成人网| 久久99精品久久久久子伦| 国产成人精品综合久久久| 亚洲综合伊人久久综合| 久久久久亚洲AV成人网人人软件 | 中文字幕亚洲综合久久| 99久久久国产精品免费无卡顿| 国产精品免费久久| 99久久婷婷国产综合亚洲| 久久久精品国产| 久久人人爽人爽人人爽av| 香蕉久久夜色精品国产小说| 国产精品一区二区久久国产| 亚洲狠狠婷婷综合久久久久| 亚洲国产成人久久综合区| 久久久人妻精品无码一区 | 中文国产成人精品久久不卡| 中文精品久久久久国产网址 | 精品综合久久久久久88小说 | 国产精品内射久久久久欢欢| 久久人人爽人人爽人人片AV东京热 | 精品熟女少妇AV免费久久 | 亚洲精品乱码久久久久久蜜桃不卡 | 国产精品成人99久久久久91gav| 好属妞这里只有精品久久| 麻豆AV一区二区三区久久| 亚洲中文字幕久久精品无码喷水| 久久精品一本到99热免费|