• <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
            <2007年9月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            30123456

            常用鏈接

            留言簿(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

            由于文件數(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,很好很強大。

            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,這個應(yīng)該最快了。


             

            統(tǒng)計一下:

             命令耗費時間
            rm 文件數(shù)量太多,不可用
            find with -exec50萬文件耗時43分鐘
            find with -delete9分鐘
            Perl16s
            Python9分鐘
            rsync with -delete16s
            posted on 2021-07-11 15:07 聶文龍 閱讀(189) 評論(0)  編輯 收藏 引用 所屬分類: Linux
            久久午夜免费视频| 国内精品久久久久久久影视麻豆| 久久久久se色偷偷亚洲精品av| 亚洲AV乱码久久精品蜜桃| 青青国产成人久久91网| 日韩精品久久久久久久电影| 精品久久久噜噜噜久久久| 久久久91人妻无码精品蜜桃HD| 99精品国产综合久久久久五月天 | 麻豆亚洲AV永久无码精品久久| 久久最近最新中文字幕大全| 亚洲性久久久影院| 久久se精品一区二区| 久久综合亚洲色一区二区三区| 99久久99久久精品国产片| 五月丁香综合激情六月久久| 久久免费香蕉视频| 欧美亚洲国产精品久久蜜芽| 亚洲伊人久久精品影院| 无码乱码观看精品久久| 精品久久久久久无码中文野结衣 | 狠狠色丁香婷综合久久| 亚洲午夜无码久久久久| 久久亚洲精品国产精品婷婷| 久久久久久A亚洲欧洲AV冫| 久久国产免费观看精品| 久久99精品久久只有精品| 亚洲色婷婷综合久久| 91麻豆国产精品91久久久| 怡红院日本一道日本久久| 欧洲人妻丰满av无码久久不卡| 思思久久精品在热线热| 中文字幕精品无码久久久久久3D日动漫 | 国产精品久久久久久久久鸭| 久久久免费精品re6| 久久久久人妻一区二区三区vr| 精品国产乱码久久久久久人妻| 亚洲国产日韩欧美久久| 久久人人爽人人爽人人爽| 综合久久给合久久狠狠狠97色 | 久久午夜夜伦鲁鲁片免费无码影视|