成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Linux技巧:一次刪除一百萬個文件的最快方法

系統 Linux
昨天,我看到一個非常有趣的刪除一個目錄下的海量文件的方法。他沒有使用find 或 xargs,他很有創意的利用了rsync的強大功能,使用rsync –delete將目標文件夾以一個空文件夾來替換。之后,我做了一個實驗來比較各種方法。讓我吃驚的是,Lee的方法要比其它的快的多。來看看本文的測評。

最初的測評

昨天,我看到一個非常有趣的刪除一個目錄下的海量文件的方法。這個方法來自http://www.quora.com/How-can-someone-rapidly-delete-400-000-files里的Zhenyu Lee。

他沒有使用find 或 xargs,他很有創意的利用了rsync的強大功能,使用rsync –delete將目標文件夾以一個空文件夾來替換。之后,我做了一個實驗來比較各種方法。讓我吃驚的是,Lee的方法要比其它的快的多。下面就是我的測評。

環境:

  • CPU: Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz
  • MEM: 4G
  • HD: ST3250318AS: 250G/7200RPM

使用 –delete 和 –exclude,你可以選擇性刪除符合條件的文件。還有一點,當你需要保留這個目錄做其它用處時,這種方法是再適合不過了。

重新測評

幾天前,Keith-Winstein在回復Quora上的這個帖子時說我之前的測評無法復制,因為操作的時間持續的太久。我澄清一下,這些數據過大,可能是因為我的計算機在過去的幾年里做的事太多,測評中可能存在一些文件系統錯誤。但我不確定是這些原因。現在好了,我弄了一天比較新的計算機,把測評再做一次。這次我使用/usr/bin/time,它能提供更詳細的信息。下面就是新的結果。

(每次都是1000000個文件。每個文件的體積都是0。)

原始輸出

# method 1
~/test $ /usr/bin/time -v  rsync -a --delete empty/ a/
        Command being timed: "rsync -a --delete empty/ a/"
        User time (seconds): 1.31
        System time (seconds): 10.60
        Percent of CPU this job got: 95%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:12.42
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 0
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 24378
        Voluntary context switches: 106
        Involuntary context switches: 22
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

# method 2
        Command being timed: "find b/ -type f -delete"
        User time (seconds): 0.41
        System time (seconds): 14.46
        Percent of CPU this job got: 52%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:28.51
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 0
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 11749
        Voluntary context switches: 14849
        Involuntary context switches: 11
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0
# method 3
find c/ -type f | xargs -L 100 rm
~/test $ /usr/bin/time -v ./delete.sh
        Command being timed: "./delete.sh"
        User time (seconds): 2.06
        System time (seconds): 20.60
        Percent of CPU this job got: 54%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:41.69
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 0
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 1764225
        Voluntary context switches: 37048
        Involuntary context switches: 15074
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

# method 4
find d/ -type f | xargs -L 100 -P 100 rm
~/test $ /usr/bin/time -v ./delete.sh
        Command being timed: "./delete.sh"
        User time (seconds): 2.86
        System time (seconds): 27.82
        Percent of CPU this job got: 89%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:34.32
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 0
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 1764278
        Voluntary context switches: 929897
        Involuntary context switches: 21720
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

# method 5
~/test $ /usr/bin/time -v rm -rf f
        Command being timed: "rm -rf f"
        User time (seconds): 0.20
        System time (seconds): 14.80
        Percent of CPU this job got: 47%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:31.29
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 0
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 176
        Voluntary context switches: 15134
        Involuntary context switches: 11
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

 

 

我真的十分好奇為什么Lee的方法要比其它的快,竟然比rm -rf也要快。如果有人知道,請寫在下面,非常感謝。

[英文原文: A faster way to delete millions of files in a directory ]

責任編輯:黃丹 來源: oschina
相關推薦

2014-05-22 14:36:34

2010-05-21 08:21:32

Google電視Android TV

2014-03-06 09:35:40

Git提交

2011-06-28 10:41:50

DBA

2023-10-26 11:07:48

Golang開發

2018-10-31 15:30:11

Linux命令重命名

2020-10-18 12:53:29

黑科技網站軟件

2019-10-11 10:22:36

Linux命令

2021-04-05 14:44:20

JavaScript循環代碼

2021-12-27 10:08:16

Python編程語言

2020-10-24 13:50:59

Python編程語言

2024-11-27 09:32:58

2014-08-01 14:06:45

2018-02-28 13:20:40

Python解壓zip

2013-06-05 11:41:53

2010-09-13 10:43:22

SQL Server

2019-08-26 09:50:09

2012-11-02 09:44:07

戴爾服務器數據中心

2017-07-17 09:54:43

代碼C語言功能

2013-12-24 13:59:03

點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 日韩av在线播 | 成人午夜网站 | 久久国产日韩 | 精品视频一区二区 | 日韩美女一区二区三区在线观看 | 青娱乐自拍 | 成人精品视频99在线观看免费 | 国产精品久久久久久久午夜 | 精品久久久久久久久久久久久久 | 日韩理论电影在线观看 | 97精品国产一区二区三区 | 亚洲精品视频一区 | 亚洲精品视频免费 | 亚洲精品久 | 成人一级黄色毛片 | 国产高清视频在线播放 | 久久er精品 | 国产精品18hdxxxⅹ在线 | 久久久精品黄色 | 欧美日韩久久 | 欧美日韩国产中文 | 色综合桃花网 | 国产美女自拍视频 | 日韩在线免费视频 | 国产精品中文字幕在线观看 | 精品国产区| 欧美日韩成人影院 | 日韩欧美三级 | 欧美在线视频观看 | 亚洲免费久久久 | 五月婷婷丁香 | 蜜桃av人人夜夜澡人人爽 | 欧美性影院 | av大片| 久久精品一级 | 成人午夜在线 | 欧美一级久久 | 激情五月综合 | 神马影院一区二区三区 | 狠狠插天天干 | 免费国产一区 |