How to clean hard disk using cmd?

A computer’s hard disk drive (HDD) stores all of your personal data and installed programs. Over time, it can become cluttered with unnecessary temporary files, caches, downloads, and other junk data that accumulates from normal use. Cleaning your hard disk helps free up storage space and keeps your computer running smoothly.

Why should you clean your hard disk?

Here are some key reasons to periodically clean your hard disk:

  • Frees up storage space – Removing unnecessary files clears up room for more useful data.
  • Improves performance – Decluttering gets rid of data fragments and consolidates free space into larger contiguous blocks for faster read/write times.
  • Increases security – Deleting temporary internet files helps protect personal data and browsing history from being accessed.
  • Fixes issues – Cleaning can resolve problems caused by disk errors, corrupted files, or programs not uninstalling properly.

How to use the Disk Cleanup utility

Windows includes a built-in Disk Cleanup utility that searches for unnecessary files that can safely be deleted. Here’s how to use it:

  1. Open Disk Cleanup by searching for it or going to Start > All Programs > Accessories > System Tools > Disk Cleanup.
  2. Select the drive you want to clean up (usually C:) and click OK.
  3. Disk Cleanup will scan the drive and show you how much space can be recovered. Check the file types you want to delete.
  4. Click Clean up system files to repeat the scan including system files. Check any additional item types to remove.
  5. Click OK to permanently delete the selected file types. Confirm any warnings if prompted.

Disk Cleanup removes temporary files, empties the recycling bin, clears system file history and other recovered storage space. However, it only scratches the surface of deeper disk cleaning.

Use the command prompt for advanced disk cleaning

The Windows command prompt provides access to powerful built-in tools for thoroughly cleaning a hard disk. Here are some of the most useful commands:


The DEL (delete) command deletes one or more files and folders specified after it. For example:

DEL D:\Temp\*.tmp

This deletes all files with a .tmp extension in the Temp folder on drive D:. You can use wildcards like * and ? in the filename/path. Be careful, as deleted files are permanently gone.


CLEANMGR executes the Disk Cleanup utility from the command prompt. Use the /VERYLOWDISK switch to clean up as much as possible when low on disk space:



DISKPART is a powerful disk partitioning tool. The CLEAN command inside DISKPART will completely wipe and reformat the specified drive. Caution – this erases ALL data on the drive!



SFC (System File Checker) scans Windows system files and replaces corrupted or missing ones using cached versions. This repairs problems that might prevent Windows from working properly:



CHKDSK checks the file system and disk surface for logical and physical errors. Use the /F switch to fix any found errors:


This will schedule a disk check to run on restart. Add /R to check and repair bad sectors.


DEFRAG rearranges and consolidates fragmented files and free space for optimal file storage. Defragmenting will boost hard disk performance:


Best practices for disk cleaning

Follow these tips for keeping your hard disk efficiently cleaned:

  • Clean temporary files and caches weekly using Disk Cleanup to recover storage space.
  • Delete unneeded downloads, documents, and media that pile up over time.
  • Run an in-depth cleaning monthly using DISKPART and CHKDSK to fix errors.
  • Perform regular defragmentation to optimize file arrangement.
  • Uninstall unused programs to purge all associated files.
  • Monitor disk usage to know when more aggressive cleaning is needed.
  • Back up important data first before cleaning to avoid accidental data loss.

Guidelines for safe disk cleaning

Here are some guidelines to follow to avoid potential issues when cleaning your hard disk:

Do Don’t
Scan what will be deleted before cleaning Clean without understanding what will be removed
Have backups before wiping or reformatting drives Erase data with no backup – recovery could be impossible
Close other programs before running disk utilities Clean while files are still open or running
Schedule deep cleans when you won’t need your computer Interrupt your workflow to clean – schedule it instead
Use the Safely Remove Hardware tool before disconnecting external drives Unplug an external drive without ejecting it first


Keeping your hard disk clutter-free optimizes computer performance, resolves issues caused by disk errors, and maximizes available storage capacity. The Windows Disk Cleanup utility provides an easy way to recover space by removing unneeded files. For more advanced disk cleaning, the command prompt gives access to powerful utilities like DISKPART, CHKDSK, and DEFRAG.

Regularly schedule both high-level and deep disk cleaning sessions. Always backup your data first and understand what will be deleted before running cleaning tools. Follow best practices, like frequent defragmentation, monitoring disk usage, and safe drive removal to keep your hard disk running efficiently.