Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Man i do think this is a big step for windows , it's 2016 and still complex to pull a du -sh or df on windows. Things we take for granted on *nixes. Much love.


According to http://stackoverflow.com/a/868290/259130

    function directory-summary($dir=".") { 
      get-childitem $dir | 
        % { $f = $_ ; 
            get-childitem -r $_.FullName | 
               measure-object -property length -sum | 
                 select @{Name="Name";Expression={$f}},Sum}
    }
I could get a shorter non exact version if I was on windows.


that's almost as easy as just typing "du -sh"


Add that function (or whatever combo of attributes you want to see on a regular basis) to your PowerShell profile, as well as this line:

New-Alias -Name "du" -Value "Directory-Summary"


For 'du':

    > Get-ChildItem C:\windows | Measure-Object -property length -sum


    Count    : 28
    Average  :
    Sum      : 6407920
    Maximum  :
    Minimum  :
    Property : length
For 'df':

    > get-WmiObject win32_logicaldisk

    DeviceID     : C:
    DriveType    : 3
    ProviderName :
    FreeSpace    : 21796540416
    Size         : 31685865472
    VolumeName   :

    DeviceID     : D:
    DriveType    : 5
    ProviderName :
    FreeSpace    :
    Size         :
    VolumeName   :

    DeviceID     : Z:
    DriveType    : 4
    ProviderName : \\veertu\share
    FreeSpace    : 44674220032
    Size         : 399999991808
    VolumeName   : VeertuFS


And you just built du with a single line of PowerShell. Also, you demonstrated the full syntax. The short form would be (leveraging aliases, positional parameters and unambiguous short parameter names):

For du:

    ls C:\Windows\ | measure length -sum
For df:

    gwmi win32_logicaldisk


Microsoft provides a du implementation in sysinternals stuff, but you have to install it and I think even accept a licence in a graphical window the first time you launch it...

They have neglected the CLI for years and powershell while I guess it has its uses for scripting is light years behind *nix stuff as an interactive shell.


>but you have to install it and I think even accept a licence in a graphical window

You can -accepteula from the command line and the "installation" is downloading and extracting a zip file. If there's an internet connection, you could even run it straight off of Micrsoft's servers via SMB.


Or you can just download du.exe from SysInternals to get a du-like tool.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: