du Command for Windows: How to Check Folder Sizes
In this article
The du command is a Unix/Linux tool for estimating disk usage, and it does not exist natively in Windows. To get the same result on Windows, you can use PowerShell's Get-ChildItem with Measure-Object, install the Windows Sysinternals du utility, or use the built-in dir command with the /s switch for a quick total. The simplest built-in method is a one-line PowerShell command that sums file lengths in a folder.
What You'll Need
- A Windows 10 or Windows 11 PC (the steps also work on Windows 8.1 and 7 with PowerShell 5.1).
- Access to PowerShell or Command Prompt. No administrator rights are required for reading folder sizes, but you may need them for system folders.
- Optional: the Sysinternals
duutility from Microsoft's official download page if you want a trueducommand.
Step-by-Step
- Open PowerShell. Press
Win + Xand choose Windows PowerShell or Terminal. On Windows 11, Terminal opens PowerShell by default. You can also search for PowerShell in the Start menu. - Navigate to the folder you want to measure. Use
cdfollowed by the path, for example:cd C:\Users\YourName\Documents. If the path contains spaces, wrap it in quotes:cd "C:\Users\Your Name\Documents". - Run the folder-size command. Type the following and press Enter:
This lists every file in the current folder and all subfolders, then sums their sizes in bytes. The output shows Count (number of files) and Sum (total bytes).Get-ChildItem -Recurse -File | Measure-Object -Property Length -Sum - Convert bytes to a readable unit. Divide the Sum value by 1,048,576 for megabytes or by 1,073,741,824 for gigabytes. For a quicker readable output, use:
- Measure a folder without changing directory. Use the
-Pathparameter:Get-ChildItem -Path "C:\Users\YourName\Downloads" -Recurse -File | Measure-Object -Property Length -Sum - See per-subfolder sizes. To list the size of each immediate subfolder, run:
This prints a table of folder names and their sizes in megabytes.Get-ChildItem -Directory | ForEach-Object { $size = (Get-ChildItem $_.FullName -Recurse -File | Measure-Object -Property Length -Sum).Sum; [PSCustomObject]@{Folder=$_.Name; SizeMB=[math]::Round($size/1MB,2)} } - Optional: use the Sysinternals du tool. Download du from Microsoft's Sysinternals page (official Microsoft source). Extract
du.exeto a folder in your PATH, or run it from its folder. Then in Command Prompt or PowerShell, run:
Thedu -sh C:\Users\YourName\Documents-sflag gives a summary, and-hmakes the output human-readable. Rundu -?to see all options. - Optional: use Command Prompt's dir. In Command Prompt, run:
The last line shows the total number of files and total bytes. This is less flexible than PowerShell but requires no extra tools.dir /s /a "C:\Users\YourName\Documents"
Common Mistakes
- Forgetting
-File. Without it,Get-ChildItem -Recurseincludes folders, andMeasure-Object -Property Lengthmay error or return zero because folders do not have a Length property. - Running from the wrong directory. If you do not
cdinto the target folder and do not use-Path, you will measure whatever folder PowerShell opened in, often your user profile. - Expecting
duto work out of the box. Typingduin a fresh Windows install returns "not recognized." You must install Sysinternals du or use PowerShell. - Ignoring hidden and system files. By default,
Get-ChildItemskips hidden items. Add-Forceto include them:Get-ChildItem -Recurse -File -Force | Measure-Object -Property Length -Sum. - Using
dir /son huge drives without patience. It can take a long time and may hit access-denied errors on protected folders; run it on a specific folder rather than the whole drive.
Tips
- Use
-ErrorAction SilentlyContinueto skip folders you cannot access without stopping the whole command:Get-ChildItem -Recurse -File -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum. - For a quick visual overview, Windows Settings > System > Storage shows per-category usage, and File Explorer's folder Properties dialog shows a folder's size on disk, though it can be slow on large trees.
- PowerShell 7 (installed separately) handles very large folder trees faster than Windows PowerShell 5.1 in many cases.
- If you only need the total for one folder,
dir /sin Command Prompt is the fastest no-install option.
Troubleshooting
- "du is not recognized": You have not installed Sysinternals du or it is not in your PATH. Either add its folder to PATH or call it with the full path, e.g.
C:\Tools\du.exe -sh C:\Folder. - Command returns zero or a blank Sum: Check that you included
-Fileand that the path exists. If the folder is empty, the sum is null; that is expected. - Access denied errors: Run PowerShell as administrator for protected folders, or add
-ErrorAction SilentlyContinueto skip them. Note that skipped files are not counted. - Very slow results on large drives: Measure one subfolder at a time, or use the Sysinternals du tool, which is optimized for this task.
- Output in bytes is hard to read: Use the
Select-Objectexpression shown in step 4 to convert to MB, or pipe toFormat-Listfor a clearer layout.
Frequently Asked Questions
Is there a built-in du command in Windows?
No. Windows does not ship a command called du. The closest built-in options are PowerShell's Get-ChildItem with Measure-Object and Command Prompt's dir /s.
Can I use du in Command Prompt after installing Sysinternals?
Yes. Once du.exe is in a folder listed in your PATH, you can run du -sh C:\Folder from either Command Prompt or PowerShell.
How do I get folder sizes in GB instead of bytes?
Divide the Sum by 1GB in PowerShell: [math]::Round($_.Sum/1GB,2). The example in step 4 shows the full command.
Why does PowerShell skip some files?
By default it hides hidden and system files, and it may skip files you lack permission to read. Add -Force to include hidden items and run as administrator for protected locations.
Does du work on Windows Subsystem for Linux?
Yes. If you have WSL installed, you can run Linux du inside the WSL environment, but it measures files as seen from Linux, which may differ slightly from Windows reporting.
What is the fastest way to check a single folder's size?
For a quick total, open Command Prompt and run dir /s "C:\Folder". For scripted or repeated use, the PowerShell one-liner is more flexible.