Checking disk space sounds universal, but each operating system exposes storage through different commands and concepts. Windows usually presents drive letters and volumes. Linux and macOS present mounted filesystems under one directory tree. Containers, network shares, snapshots, quotas, and reserved space add more variation.
The first question should be precise: do you need filesystem capacity, the size of a directory, the largest files, or physical disk information? This guide focuses on capacity: total, used, available, and percentage used.
Command summary
| Environment | Command | Best use |
|---|---|---|
| Windows PowerShell | Get-Volume |
Windows volume metadata, drive letters, filesystem type, health, size, and remaining size. |
| PowerShell filesystem provider | Get-PSDrive -PSProvider FileSystem |
Filesystem drives visible in the current PowerShell session, including Used and Free where supported. |
| Linux | df -h |
Mounted filesystem capacity in human-readable units. |
| macOS | df -h |
Mounted filesystem capacity from Terminal; exact columns and units follow the system's BSD utility. |
| QZX | qzx getDiskInfo --json |
A shared request with structured results for supported Windows, Linux, and macOS environments. |
How to check disk space on Windows
Get-Volume: inspect Windows volumes
Get-Volume
Get-Volume -DriveLetter C
Get-Volume -DriveLetter C |
Select-Object DriveLetter, FileSystem, Size, SizeRemaining
Get-Volume belongs to the Windows Storage module and returns volume objects rather than formatted text alone. That makes it suitable for filtering, sorting, exporting, and calculating percentages.
Get-Volume -DriveLetter C |
Select-Object DriveLetter,
@{Name='SizeGB'; Expression={[math]::Round($_.Size / 1GB, 2)}},
@{Name='FreeGB'; Expression={[math]::Round($_.SizeRemaining / 1GB, 2)}},
@{Name='UsedPercent'; Expression={
[math]::Round((1 - $_.SizeRemaining / $_.Size) * 100, 1)
}}
The example calculates presentation fields without destroying the original byte values. Keep bytes for automation and convert only at the display boundary.
Get-PSDrive: query the PowerShell filesystem provider
Get-PSDrive -PSProvider FileSystem
Get-PSDrive C | Select-Object Name, Root, Used, Free
Get-PSDrive describes drives in the current PowerShell session. Filtering by FileSystem avoids mixing filesystem drives with providers such as the registry, environment, certificates, or aliases. It can also include mapped locations that are meaningful to the session.
Use Get-Volume when Windows volume details matter. Use Get-PSDrive when your automation is already working with PowerShell provider drives. They overlap, but they are not identical inventories.
How to check disk space on Linux
GNU df reports the space available on mounted filesystems:
df -h
df -h /var
df -h --output=source,fstype,size,used,avail,pcent,target
-hselects human-readable powers such as KiB, MiB, and GiB.- Passing a path asks
dffor the filesystem that contains that path. --outputselects explicit columns in GNU coreutils; do not assume that GNU-only option exists on every Unix-like host.
A typical row identifies the filesystem source, total blocks, used space, available space, usage percentage, and mount point. When scripts parse output, set a known locale or use a structured system API where available. Human-oriented spacing and localized headings are brittle contracts.
How to check disk space on macOS
macOS also provides df in Terminal:
df -h
df -h /
df -k /Users
The intent is the same as on Linux, but macOS ships BSD userland rather than GNU coreutils by default. Do not copy GNU-specific options such as --output into a supposedly portable script without detecting support.
For an interactive category view, macOS also exposes storage information in System Settings. The graphical breakdown is useful for a person deciding what to review, while df is the better primitive for terminal automation.
Why df and du do not match
df and du answer different questions:
dfasks the filesystem how much capacity is used and available.duwalks files and directories to estimate their allocated space.
They can disagree because of files that were deleted but remain open by a process, filesystem metadata, snapshots, reserved blocks, hard links, sparse files, compression, permissions, and mount points hidden below a directory. If capacity is low, use df to identify the affected filesystem and then use du or a file-search tool to investigate content.
du -sh /var/log
du -h /var | sort -h | tail
Those examples are diagnostic starting points, not universal cleanup commands. Avoid deleting a large file until you understand its owner, retention policy, open handles, and recovery path.
One QZX request across supported platforms
QZX exposes the read-only getDiskInfo command:
qzx getDiskInfo --json
qzx getDiskInfo C: --json
qzx getDiskInfo /home --json
The catalog documents a path argument. Without one, the command inspects available disks. With a Windows drive or Unix path, it focuses the relevant target. Its structured result includes the common QZX fields success and message, disk data, and summary fields such as total, used, free, and percentage used where available.
{
"success": true,
"message": "Disk information retrieved ...",
"disks": [ ... ],
"summary": {
"total_space": 0,
"used_space": 0,
"free_space": 0,
"percent_used": 0
}
}
This is a shape illustration, not a claim that every filesystem exposes identical semantics. QZX normalizes the request and result contract while preserving platform-specific values. It does not turn drive letters into mount points or erase differences in quotas, snapshots, or reserved space.
Disk-space automation that does not surprise you
- Keep raw bytes. Use rounded GB or GiB values for display, not for threshold calculations.
- Name the unit. Decimal GB and binary GiB are not the same. A bare number is ambiguous.
- Identify the filesystem. Checking
/does not prove that/dataor a container volume has room. - Handle network and removable volumes separately. They can be slow, disconnected, or governed by remote quotas.
- Record both amount and percentage. Ten free gigabytes can be comfortable on a small volume and urgent on a fast-growing service.
- Add trend and context. A threshold tells you the current state; growth rate helps predict when action is needed.
- Do not make cleanup automatic by default. Measurement is read-only. Deletion needs a separate policy, exact targets, backups when appropriate, and validation.
If you need to find candidates after identifying a constrained filesystem, QZX also documents findLargeFiles. Treat discovery and deletion as separate stages so a reporting tool never becomes an unreviewed cleanup job.
Native commands or QZX?
Use a native command when the workflow targets one known platform and its native object model is valuable. Use QZX when a terminal-capable agent or automation benefits from one command name, explicit JSON, a shared success/message contract, and a documented cross-platform vocabulary.
Neither choice removes the need to test on the real systems you support. The broader explanation in our cross-platform automation guide covers paths, permissions, shells, encodings, and output differences beyond storage.
Frequently asked questions
How do I check disk space on Linux?
Run df -h to see mounted filesystems with human-readable capacity, used space, available space, and usage percentage. Use df -h /path for the filesystem containing a path.
How do I check disk space with PowerShell?
Get-Volume returns Windows volume information. Get-PSDrive -PSProvider FileSystem lists filesystem drives in the current PowerShell session, including Used and Free where available.
How do I check disk space on macOS?
In Terminal, df -h reports mounted filesystem capacity in human-readable units. The graphical storage view in System Settings provides an interactive category overview.
What is the difference between df and du?
df reports filesystem-level capacity and availability. du estimates space used by files and directories. Their totals may differ because they measure different things.
How can an AI agent check disk space across operating systems?
It can branch among native commands or call qzx getDiskInfo --json for a supported cross-platform operation with structured disk data and summary fields.
Does low free space always mean the same thing?
No. Reserved blocks, snapshots, quotas, sparse or compressed files, mounted filesystems, deleted-open files, and platform-specific accounting can change the meaning.