Optimize a Drive from the CLI with defrag
Run fragmentation consolidation on HDDs or the trim pass on SSDs, with progress output.
01Command
$ defrag C: /O /U /V02What it does
The modern /O switch is media-aware: it defragments and consolidates free space on spinning disks but issues the trim pass on SSDs, so one command is correct for both. /U prints progress and /V prints verbose statistics at the end. Windows already schedules this weekly, but a manual run helps right after large file churn or before imaging a drive.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- defrag - Windows CommandsEvidence: Documents defrag, including /O to perform the proper optimization (trim on SSDs), /U for progress and /V for verbose output.
Last verified: 2026-09-17 · Category: System & Settings
06Related solutions
Save a cleanup profile once, then run it unattended on any schedule.
Read-only command that prints free, total and available bytes for any volume.
One command that shows OS version, install date, boot time, memory, network adapters and installed hotfixes.