Skip to content

Instantly share code, notes, and snippets.

@paul-d-ray
Last active June 18, 2025 03:05
Show Gist options
  • Save paul-d-ray/28ff2d408ad161c5bb5b366a6f884549 to your computer and use it in GitHub Desktop.
Save paul-d-ray/28ff2d408ad161c5bb5b366a6f884549 to your computer and use it in GitHub Desktop.
Nushell use Sysinternals DU command

Disk Usage Commands

Sysinternals DU Command

Instead of using Nushell's DU command, use the Sysinternals DU command

Custom function

This function will use the Sysinternals DU comand and transpose the data and format the numbers with a separator and right align.

def du64x [dir: string] {
  ^'C:\Program Files\sysinter\DiskUsage\du64.exe' -nobanner -c $dir |
  from csv |
  transpose Item Value |
  update Value {
    |row|
    if $row.Item in ["CurrentFileSize", "DirectorySize", "DirectorySizeOnDisk"] {
      let size = ($row.Value | into int)

      let formatted = match $size {
        ..<1_000 => $"($size) B",
        ..<1_000_000 => $"(($size / 1_000 | math round -p 2)) KB",
        ..<1_000_000_000 => $"(($size / 1_000_000 | math round -p 2)) MB",
        ..<1_000_000_000_000 => $"(($size / 1_000_000_000 | math round -p 2)) GB",
        _ => $"(($size / 1_000_000_000_000 | math round -p 2)) TB"
      }

      $formatted | fill -a right -w 15 -c ' '
    } else if $row.Item in ["CurrentFileCount", "FileCount", "DirectoryCount"] {
      ($row.Value | into int | into string -g) | fill -a right -w 15 -c ' '
    } else {
      $row.Value
    }
  }
}

Example output

 du64 d:\work\nu
╭───┬─────────────────────┬─────────────────╮
│ # │        Item         │      Value      │
├───┼─────────────────────┼─────────────────┤
│ 0 │ Path                │ d:\work\nu      │
│ 1 │ CurrentFileCount    │              98 │
│ 2 │ CurrentFileSize     │         1.97 GB │
│ 3 │ FileCount           │             451 │
│ 4 │ DirectoryCount      │              12 │
│ 5 │ DirectorySize       │          2.7 GB │
│ 6 │ DirectorySizeOnDisk │         2.71 GB │
╰───┴─────────────────────┴─────────────────╯

Nushell DU command

Nushell's DU command does not show the file count and directory count.

Example Output

du d:/work/nu
╭───┬────────────┬──────────┬──────────╮
│ # │    path    │ apparent │ physical │
├───┼────────────┼──────────┼──────────┤
│ 0 │ d:\work\nu │   2.7 GB │   2.7 GB │
╰───┴────────────┴──────────┴──────────╯
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment