How to Clean Computer Using CMD in Windows: 7 Commands to Free Up Space

Mr Kumar
Reviewed By :
Mr Kumar
Prakhar Shivhare Written by Prakhar Shivhare
Updated on
Nov 27, 2026

A sluggish PC does not always need a factory reset or expensive cleaning software. A few built-in Command Prompt commands can help remove temporary files, clear specific caches, and recover storage space.

However, not every CMD clear command described as a cleaning trick actually frees up disk space. Some are meant for troubleshooting, while others can delete important data if used incorrectly. Here’s how to clean computer using CMD, what each command does, and when to use it.

What Can You Clean Using Command Prompt?

Command Prompt commands give you access to several built-in Windows tools that can remove unnecessary files and clear specific types of cached data. Each command handles a different task, so there is not one command that cleans every part of your PC.

Here are some things you can manage and clear in CMD:

  • Temporary Files: Files created by Windows and applications during everyday use.
  • Disk Cleanup Files: Disk cleanup commands can manage temporary setup files, thumbnails, selected system files, and Recycle Bin contents.
  • Microsoft Store Cache: Temporary data that may cause Store-related issues.
  • DNS Cache: Saved website address records used during network lookups.
  • Windows Component Store: Outdated Windows components left behind after updates.

Some commands free up disk space, while others are mainly useful for troubleshooting. Let’s look at how to use each one.

How to Clean Computer Using CMD?

Now let’s see how to clear in CMD using 7 commands. First, open Command Prompt by searching for cmd in the Start menu. Select Run as administrator for commands that require elevated permissions. 

1. Run Disk Cleanup Using cleanmgr

Windows’ built-in Disk Cleanup utility identifies unnecessary files you can remove. Let’s take a look at the commands to clean up PCs.

  • Enter:

cleanmgr

  • Select the drive you want to clean, choose the file categories to remove, and click OK > Delete Files.
  • To open Disk Cleanup for a specific drive, use:

cleanmgr /d C:

For additional cleanup options, select Clean up system files. Review the categories carefully, especially Previous Windows installations, before deleting them.

2. Configure Disk Cleanup Using cleanmgr /sageset

If you want to save your preferred cleanup categories, run:

cleanmgr /sageset:1

Run cleanmgr /sageset:1

Select the file categories you want Disk Cleanup to handle and click OK. Windows saves these choices under Profile number 1. You can use a different number if you want to create another cleanup profile.

3. Run Your Saved Cleanup Profile Using cleanmgr /sagerun

After configuring your cleanup profile, run:

cleanmgr /sagerun:1

Windows applies the saved cleanup settings. Keep in mind that this CMD command to clean PCs processes all enumerated drives, not just the C: drive.

4. Delete Temporary Files Using del

Temporary files can accumulate in your user Temp folder. Close open applications first, then run:

del /q /f /s %temp%\*

Run del /q /f /s %temp%\*

Here’s what the switches mean:

  • /q: Deletes files without asking for confirmation.
  • /f: Forces deletion of read-only files.
  • /s: Includes files in subfolders.
  • %temp%: Points to your user Temp folder.

Some files may remain because they are currently in use; that is normal. Also, del bypasses the Recycle Bin, so double-check the path before running the command.

5. Clear Microsoft Store Cache Using wsreset.exe

If your Microsoft Store is loading slowly, behaving unexpectedly, or having cache-related issues, run the following command to reset its cache:

wsreset.exe

Press Enter and wait. A blank Command Prompt window may appear before closing automatically. Microsoft Store should then reopen.

This command resets the Microsoft Store cache. It does not clear every application cache or remove unnecessary files across your PC.

6. Clear DNS Cache Using ipconfig /flushdns

Windows stores DNS records to speed up website lookups. If outdated records cause connection problems or DNS errors, run:

ipconfig /flushdns

Run ipconfig /flushdns

Press Enter. Windows will confirm when the DNS resolver cache has been cleared. This command is useful for network troubleshooting, but it does not free up disk space.

7. Clean Windows Components Using DISM

Windows stores system components and update files in the WinSxS folder. DISM can remove superseded components that are no longer needed.

Open Command Prompt as administrator and run:

DISM /Online /Cleanup-Image /StartComponentCleanup

Run DISM /Online /Cleanup-Image /StartComponentCleanup

Wait for the operation to finish. Also, avoid adding /ResetBase unless you understand its consequences. It prevents you from uninstalling existing Windows updates.

CMD Commands That Are Not Meant for Routine Cleaning

Some Windows commands are useful for system maintenance but are not designed to remove unnecessary files.

  • sfc /scannow: Scans and repairs protected Windows system files. Use it to troubleshoot system errors, not to free up storage.
  • chkdsk: This checks a drive for file system errors and can repair certain problems. It is useful when you are investigating storage errors.
  • defrag: The defrag utility helps optimize traditional hard drives by reorganizing fragmented data. It does not delete junk files or directly clear storage.
  • diskpart clean: Be particularly careful with this diskpart command. It removes partition information from the selected disk. Selecting the wrong disk can make its data inaccessible. Do not use it as one of the routine CMD cleaning commands.

Things to Consider Before Running CMD Commands to Clean PC

Commands like Disk Cleanup and others can remove files quickly, but not every cleanup operation is risk-free. Keep these points in mind:

  • Check Commands Carefully: A small change in a file path or switch can alter what gets deleted. And avoid copying commands from unverified sources.
  • Close Running Applications: This reduces the chances of temporary files being in use during cleanup.
  • Avoid Deleting System Folders Manually: Do not remove random files from C: \Windows, WinSxS, or other system directories.
  • Don’t Clear Prefetch Routinely: Windows uses Prefetch data to help applications load. Deleting it regularly is not a reliable way to speed up your PC.
  • Understand Each Cache Command: There is no universal way to clear cache through CMD that is safe and clears every browser, application, and system cache.
  • Back Up Important Files: Commands such as del bypass the Recycle Bin. So, keep a separate copy of important documents before deleting files.

If you are unsure about a command or the files it will remove, use Windows’ Disk Cleanup or Storage settings instead. These tools allow you to review cleanup categories before confirming deletion.

Conclusion

Command Prompt can help remove temporary files, run Disk Cleanup, clear specific caches, and maintain Windows components. Start with cleanmgr and use other commands only when needed. Avoid destructive disk operations unless you understand exactly what they do. Knowing the purpose of each command is more useful than running a long list of cleanup commands blindly.

Read Next: What is LockApp.exe in Windows and How to Fix or Disable It?

Frequently Asked Questions

How do I use Command Prompt for cleaning PCs?

Run cleanmgr to open Disk Cleanup. You can also use del /q /f /s “%TEMP%\*” to remove files from your user Temp folder or DISM to clean superseded Windows components.

What is the command to clear the cache in CMD?

There isn’t one universal command. Use ipconfig /flushdns for DNS cache and wsreset.exe for Microsoft Store cache. Other application caches require app-specific cleanup.

How to clear the Command Prompt screen?

Type cls and press Enter. It clears the visible CMD window but does not delete files or free up storage.

Is it safe to delete temporary files using CMD?

Generally, yes, if you target your user Temp folder. Don’t forget to close applications before trying to delete them. Some files may remain in use, and deleted files won’t go to the Recycle Bin.

Can CMD make my computer run faster?

CMD can remove unnecessary files and certain Windows components, and it may boost your PC speed. However, it won’t fix every cause of a slow PC.

Sources:




Related Posts
Operating System Nov 28, 2026
How to Crop an Image on Mac: Preview, Photos, and Third-Party Tools

A photo can be perfectly good and still need a trim. A stranger at the edge, too much empty space,…

Operating System Nov 28, 2026
How to Format a USB Drive on Windows and Mac

Formatting a USB flash drive can help prepare it for a new device, remove unwanted files, or resolve certain file…

Where is the Applications Folder on Mac and How to Access It
Operating System Nov 26, 2026
Where is the Applications Folder on Mac and How to Access It

Need to find an installed app, move it into place, or check whether it is available on your Mac? You…

How to Change Cursor Color in Windows 11?
Operating System Nov 16, 2026
How to Change Cursor Color in Windows 11?

The default white mouse pointer can be difficult to spot against bright windows, documents, and light-colored backgrounds. That’s when people…

What is LockApp.exe in Windows and How to Fix or Disable It?
Operating System Nov 02, 2026
What is LockApp.exe in Windows and How to Fix or Disable It?

LockApp.exe may look suspicious when you spot it in Task Manager, especially if you haven’t opened it yourself. This Windows…

How to Run Windows on Mac: 4 Methods That Actually Work
Operating System Oct 29, 2026
How to Run Windows on Mac: 4 Methods That Actually Work

Buying a Mac does not mean you have to give up Windows. You might need a Windows-only work application, open…

How to Fix DISM Error 87 in Windows?
Operating System Oct 23, 2026
How to Fix DISM Error 87 in Windows?

DISM Error 87 usually appears when Windows cannot understand a DISM command or one of its parameters. You may see…

How to Restart Explorer.exe in Windows?
Operating System Oct 23, 2026
How to Restart Explorer.exe in Windows?

A frozen taskbar, missing desktop icons, or an unresponsive File Explorer can make Windows feel stuck even when your computer…

How to Reopen Closed Tabs on Mac [Easy Ways to Restore Tabs]
Operating System Oct 23, 2026
How to Reopen Closed Tabs on Mac [Easy Ways to Restore Tabs]

Accidentally closing the wrong tab can be super annoying, especially when you were in the middle of something important. You…