加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

Windows PowerShell中的Windows?

发布时间:2020-12-13 21:08:12 所属栏目:Windows 来源:网络整理
导读:如何使用PowerShell进行 du-ish分析?我想定期检查磁盘上目录的大
如何使用PowerShell进行 du-ish分析?我想定期检查磁盘上目录的大小。

以下给出了当前目录中每个文件的大小:

foreach ($o in gci)
{
   Write-output $o.Length
}

但我真正想要的是目录中所有文件的聚合大小,包括子目录。此外,我也希望能够根据大小进行排序。

博客中的“探索美丽语言”有一个实现:

“An implementation of ‘du -s *’ in Powershell”

function directory-summary($dir=".") { 
  get-childitem $dir | 
    % { $f = $_ ; 
        get-childitem -r $_.FullName | 
           measure-object -property length -sum | 
             select @{Name="Name";Expression={$f}},Sum}
}

(代码由博主:Luis Diego Fallas)

输出:

PS C:Python25> directory-summary

Name                  Sum
----                  ---
DLLs              4794012
Doc               4160038
include            382592
Lib              13752327
libs               948600
tcl               3248808
Tools              547784
LICENSE.txt         13817
NEWS.txt            88573
python.exe          24064
pythonw.exe         24576
README.txt          56691
w9xpopen.exe         4608

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读