|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
为什么我使用一个命令的时候,系统告诉我找不到该目录,我要如何限制使用者的权限等问题,这些问题其实都不是很难的。
最后的测评
今天,我看到一个十分风趣的删除一个目次下的海量文件的办法。这个办法来自http://www.quora.com/How-can-someone-rapidly-delete-400-000-files里的ZhenyuLee。
他没有利用find或xargs,他很有创意的使用了rsync的壮大功效,利用rsync–delete将方针文件夹以一个空文件夹来交换。以后,我做了一个实行来对照各类办法。让我受惊的是,Lee的办法要比别的的快的多。上面就是我的测评。
情况:
- CPU:Intel(R)Core(TM)2DuoCPUE8400@3.00GHz
- MEM:4G
- HD:ST3250318AS:250G/7200RPM
Method#OfFilesDeletionTimersync-a–deleteempty/s1/10000006m50.638sfinds2/-typef-delete100000087m38.826sfinds3/-typef|xargs-L100rm100000083m36.851sfinds4/-typef|xargs-L100-P100rm100000078m4.658srm-rfs5100000080m33.434s 利用–delete和–exclude,你能够选择性删除切合前提的文件。另有一点,当你必要保存这个目次做别的用途时,这类办法是再合适不外了。
从头测评
几天前,Keith-Winstein在复兴Quora上的这个帖子时说我之前的测评没法复制,由于操纵的工夫延续的太久。我廓清一下,这些数据过年夜,多是由于我的盘算机在已往的几年里做的事太多,测评中大概存在一些文件体系毛病。但我不断定是这些缘故原由。如今好了,我弄了一天对照新的盘算机,把测评再做一次。此次我利用/usr/bin/time,它能供应更具体的信息。上面就是新的了局。
(每次都是1000000个文件。每一个文件的体积都是0。)
CommandElapsedSystemTime%CPUcs(Vol/Invol)rsync-a–deleteempty/a10.601.3195106/22findb/-typef-delete28.5114.465214849/11findc/-typef|xargs-L100rm41.6920.605437048/15074findd/-typef|xargs-L100-P100rm34.3227.8289929897/21720rm-rff31.2914.804715134/11 原始输入
- #method1~/test$/usr/bin/time-vrsync-a--deleteempty/a/Commandbeingtimed:"rsync-a--deleteempty/a/"Usertime(seconds):1.31Systemtime(seconds):10.60PercentofCPUthisjobgot:95%Elapsed(wallclock)time(h:mm:ssorm:ss):0:12.42Averagesharedtextsize(kbytes):0Averageunshareddatasize(kbytes):0Averagestacksize(kbytes):0Averagetotalsize(kbytes):0Maximumresidentsetsize(kbytes):0Averageresidentsetsize(kbytes):0Major(requiringI/O)pagefaults:0Minor(reclaimingaframe)pagefaults:24378Voluntarycontextswitches:106Involuntarycontextswitches:22Swaps:0Filesysteminputs:0Filesystemoutputs:0Socketmessagessent:0Socketmessagesreceived:0Signalsdelivered:0Pagesize(bytes):4096Exitstatus:0#method2Commandbeingtimed:"findb/-typef-delete"Usertime(seconds):0.41Systemtime(seconds):14.46PercentofCPUthisjobgot:52%Elapsed(wallclock)time(h:mm:ssorm:ss):0:28.51Averagesharedtextsize(kbytes):0Averageunshareddatasize(kbytes):0Averagestacksize(kbytes):0Averagetotalsize(kbytes):0Maximumresidentsetsize(kbytes):0Averageresidentsetsize(kbytes):0Major(requiringI/O)pagefaults:0Minor(reclaimingaframe)pagefaults:11749Voluntarycontextswitches:14849Involuntarycontextswitches:11Swaps:0Filesysteminputs:0Filesystemoutputs:0Socketmessagessent:0Socketmessagesreceived:0Signalsdelivered:0Pagesize(bytes):4096Exitstatus:0#method3findc/-typef|xargs-L100rm~/test$/usr/bin/time-v./delete.shCommandbeingtimed:"./delete.sh"Usertime(seconds):2.06Systemtime(seconds):20.60PercentofCPUthisjobgot:54%Elapsed(wallclock)time(h:mm:ssorm:ss):0:41.69Averagesharedtextsize(kbytes):0Averageunshareddatasize(kbytes):0Averagestacksize(kbytes):0Averagetotalsize(kbytes):0Maximumresidentsetsize(kbytes):0Averageresidentsetsize(kbytes):0Major(requiringI/O)pagefaults:0Minor(reclaimingaframe)pagefaults:1764225Voluntarycontextswitches:37048Involuntarycontextswitches:15074Swaps:0Filesysteminputs:0Filesystemoutputs:0Socketmessagessent:0Socketmessagesreceived:0Signalsdelivered:0Pagesize(bytes):4096Exitstatus:0#method4findd/-typef|xargs-L100-P100rm~/test$/usr/bin/time-v./delete.shCommandbeingtimed:"./delete.sh"Usertime(seconds):2.86Systemtime(seconds):27.82PercentofCPUthisjobgot:89%Elapsed(wallclock)time(h:mm:ssorm:ss):0:34.32Averagesharedtextsize(kbytes):0Averageunshareddatasize(kbytes):0Averagestacksize(kbytes):0Averagetotalsize(kbytes):0Maximumresidentsetsize(kbytes):0Averageresidentsetsize(kbytes):0Major(requiringI/O)pagefaults:0Minor(reclaimingaframe)pagefaults:1764278Voluntarycontextswitches:929897Involuntarycontextswitches:21720Swaps:0Filesysteminputs:0Filesystemoutputs:0Socketmessagessent:0Socketmessagesreceived:0Signalsdelivered:0Pagesize(bytes):4096Exitstatus:0#method5~/test$/usr/bin/time-vrm-rffCommandbeingtimed:"rm-rff"Usertime(seconds):0.20Systemtime(seconds):14.80PercentofCPUthisjobgot:47%Elapsed(wallclock)time(h:mm:ssorm:ss):0:31.29Averagesharedtextsize(kbytes):0Averageunshareddatasize(kbytes):0Averagestacksize(kbytes):0Averagetotalsize(kbytes):0Maximumresidentsetsize(kbytes):0Averageresidentsetsize(kbytes):0Major(requiringI/O)pagefaults:0Minor(reclaimingaframe)pagefaults:176Voluntarycontextswitches:15134Involuntarycontextswitches:11Swaps:0Filesysteminputs:0Filesystemoutputs:0Socketmessagessent:0Socketmessagesreceived:0Signalsdelivered:0Pagesize(bytes):4096Exitstatus:0
复制代码 我真的非常猎奇为何Lee的办法要比别的的快,居然比rm-rf也要快。假如有人晓得,请写鄙人面,十分感激。
英文原文:Afasterwaytodeletemillionsoffilesinadirectory
无论图形界面发展到什么水平这个原理是不会变的,Linux命令有许多强大的功能:从简单的磁盘操作、文件存取、到进行复杂的多媒体图象和流媒体文件的制作。 |
|