MiniTool introduces how to clean a computer using CMD in Windows 11/10 to speed up the device in minutes. Follow the step-by-step guide to run 7 commands to clean junk files, delete temp files, defragment a hard drive, delete Prefetch Files, and clean the entire disk.

When Should You Clean Computer Using CMD

If you are an advanced user, Command Prompt is a useful tool for performing tasks such as system repair, disk management, and advanced network configuration.

In terms of hard drive management, disk cleanup is a critical task. It is recommended to run CMD commands to clean a PC when experiencing the following cases:

  • Your disk space is almost full due to accumulated temporary files and junk files.
  • The PC is running slowly due to fragmented files and low system resources.
  • You want a quick cleanup without installing tools.
  • The system crashes are occurring.
Look! How to Clean up Your Computer Digitally and Physically
Look! How to Clean up Your Computer Digitally and Physically

This post reveals the basic information about computer cleanup and shows you how to clean up your computer physically and digitally.

Read More

How to Clean Computer Using CMD Windows 11/10

To clean your computer using CMD, run these commands:

  1. cleanmgr
  2. del %temp%\*.* /s /q
  3. defrag c:
  4. ipconfig /flushdns
  5. del C:\Windows\prefetch\*.*/s/q
  6. DISM /Online /Cleanup-Image /RestoreHealth
  7. Diskpart clean

Before proceeding, you need to open Command Prompt with admin rights.

Step 1: In Windows 10/11, type cmd into the search box.

Step 2: Click Run as administrator from the popup to open the CMD window.

Screenshow showing how to open Command Prompt with admin rights via Search.

Tips:

In addition to this way, you can open Command Prompt in other methods and refer to this related post - How to Open Command Prompt (CMD) in Windows 11? (7 Ways).

Next, perform the cleaning operation via some clean commands in CMD.

Run Cleanmgr to Clean Junk Files

Cleanmgr is an automated disk cleanup tool in the Windows operating system. It can search and analyze your hard drive to find files that are no longer needed and delete them automatically to free up disk space on the hard drive.

By configuring cleanmgr.exe with command-line switches, temp setup files, Internet files, downloaded program files, old chkdsk files, Recycle Bin files, and more can be deleted. You can use the Scheduled Tasks tool to schedule the task to run at a specific time.

Let’s see how to clean your PC using Cleanmgr in Windows 11/10.

Step 1: Open CMD with admin rights.

Step 2: Type Cleanmgr into the CMD window and press Enter.

Step 3: A small window pops up to ask you to choose the drive you want to clean up. Then, click OK.

The running Cleanmgr command with an open pop-up for drive selection.

Step 4: Check the items you want to delete and then this tool will delete them to free up disk space.

Cleanmgr – the command for disk cleanup, offers multiple parameters dedicated to specific functions, and let’s see examples.

1. Cleanmgr /sageset (Skip Drive Selection)

This command for disk cleanup helps to directly skip the selection of the drive and redirects you to the Disk Cleanup Settings window to choose the items you want Disk Cleanup to automatically clean up during its scheduled run times.

The open Disk Cleanup Settings window for item selection via the Cleanmgr /sageset command.

2. Cleanmgr /sagerun (Delete Files Automatically)

This command doesn’t choose the category and helps to automate the disk-cleaning process.

3. Cleanmgr /lowdisk (Optimize for Low Space)

This command is very useful when the hard drive meets low disk space. When running this command, all checkboxes of file categories will be selected by default. The command example is like – cleanmgr /lowdisk/dc. Here c refers to the drive letter.

The command – cleanmgr /verylowdisk/dc helps to delete all junk files quickly without the user prompt.

Tips:

To know more information about this clean manager, you can refer to our previous post - What Is Cleanmgr.exe & Is It Safe & How to Use It.

Run CMD to Delete Temporary Files Windows 11/10

When using the operating system, some temporary files are created for temporary use. They are used to hold data during program operation, manage system memory, or assist in installations.

These files can be found primarily in

  • C:\Users\YourUsername\AppData\Local\Temp
  • C:\Windows\Temp

If applications and Windows fail to delete temporary files after use, these files will accumulate and consume significant disk space over time. It is necessary to delete them manually.

The following are CMD commands to free disk space in Windows 11/10.

To view temporary files, run this command:

%SystemRoot%\explorer.exe %temp%\

To delete the temporary files in the Temp folder, run the command:

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

Tips:
Additionally, you can press Ctrl + A to choose all the files and delete them. 

The running del %temp%\*.* /s /q command to delete temporary files.

How to Delete/Clean Temporary Files in Windows 11? (5 Ways)
How to Delete/Clean Temporary Files in Windows 11? (5 Ways)

How to delete temporary files in Windows 11 to free up some disk space? There are many ways for you to easily remove the temp files.

Read More

Defragment Your Hard Drive via CMD

When talking about “clean computer using CMD”, there is one thing you should think of is the disk defrag. Although fragmentation on the hard drive (only for the traditional hard disk) is a natural occurrence, it may lead to PC performance issues, for example, the access and write speed can be impacted, slowing down the system.

Defrag can reorganize fragmented data in the hard drive so that your PC can access files from the hard drive. You don’t need to defragment your SSDs since this may destroy them or reduce their lifespan. Only defragment your HDDs by following the clean command in CMD – defrag driver letter:.

Step 1: Open Command Prompt as an administrator in Windows 11/10.

Step 2: Type defrag c: into the CMD window and press Enter. Here replace c: with your drive letter

The defrag command to defragment a hard drive.

Delete Prefetch Files Using Command Prompt

When you use a program first, Windows 11/10 will create prefetch files that can work as a cache later. That is, prefetch files are used to store information regarding software activity, including how many times the software has run, when the app was running and associated files used by the software.

These prefetch files are text files with a .pf extension and they are very useful in the quicker loading of programs. But they could take up much disk space. And if you run into app bugs or lags, you can choose to delete these files. Deleting them is harmless and Windows will create prefetch files again the next time you open programs on your computer.

See how to clean PC using CMD by deleting prefetch files:

Step 1: Open CMD with admin permissions in Windows.

Step 2: Type %SystemRoot%\explorer.exe C:\Windows\prefetch\ to the Command Prompt window and press Enter to check the prefetch files. This can open the Prefetch folder in File Explorer.

Step 3: Type del C:\Windows\prefetch\*.*/s/q and press Enter to delete these prefetch files. Alternatively, you can directly delete the Prefetch folder from Windows Explorer.

Screenshot showing how to delete prefetch files via CMD.

Clear DNS Cache and Windows Store Cache

Cache files can dramatically improve performance, availability, and scalability, and they can bring the ability to serve data quickly and faster response times. However, if cache files go wrong, data fetching issues, glitches, or even crashes can happen. A common solution is to clear cache files regularly.

You can choose to clear the DNS cache and Windows store cache. If something goes wrong during the cache-clearing process, the Windows system will tell you.

  • To clear the DNS cache, execute the command – ipconfig/flushDNS in the CMD window.
  • To clear the Windows store cache, execute this command – wsreset.exe.
How to Flush DNS | How to Reset Network Connection
How to Flush DNS | How to Reset Network Connection

Do you know how to flush DNS on a Windows or a Mac computer? In this post, we will show you how to do this job on different operating systems.

Read More

Repair System Image via the DISM Command

Deployment Image Servicing and Management (DISM) is a useful command tool that can help to service and prepare system images. You can use DISM to manage a Windows image (.wim) and virtual hard disk (.vhd). It is used for Windows Recovery Environment (WinRE), Windows PE, and Windows Setup. Via the DISM tool, you can fix many system errors including update errors, boot errors, and more.

  • To check if there is any corruption, run DISM /online /Cleanup-Image /CheckHealth in the CMD window.
  • To scan the Windows image, execute this command – DISM /Online /Cleanup-Image /ScanHealth.
  • To fix Windows images, type DISM /Online /Cleanup-Image /RestoreHealth into the CMD window and press Enter.

The running DISM scan to fix Windows images.

Repair Windows 10 Image with DISM and Other Useful Tips for DISM
Repair Windows 10 Image with DISM and Other Useful Tips for DISM

Are you experiencing some annoying bugs or crashes when using your computer? Right now, you can try to repair Windows 10 image with DISM to fix these issues.

Read More

Clean a Hard Drive Using Diskpart

The process of cleaning a PC using CMD commands involves deleting unwanted files, temp files, and prefetch files, clearing DNS/Windows Store cache, and defragmenting your hard drive.

Additionally, you can use the Diskpart command-line tool to clean the entire hard drive in Windows 11/10, including its disk data.

Note:
Before running Diskpart clean in Command Prompt, it is recommended to create a backup for important files. This is because the clean command can completely and permanently delete the drive data, making file recovery impossible, especially for the clean all command.
How to Clean C Drive in Windows 11/10 Without Losing Data
How to Clean C Drive in Windows 11/10 Without Losing Data

How to clean C drive in Windows 11/10 if it is full of unnecessary files and programs? Multiple methods can be found in this post to help you out.

Read More

Back up Critical Data Before Cleanup Command Diskpart

To back up your significant files on the hard drive or USB flash drive, you can choose to use the Windows built-in backup tool – Backup and Restore (Windows 7). Just go to open Control Panel, view all the items by Large icons, and click Backup and Restore (Windows 7) to open this tool. Then, click Set up backup and start a file backup by following the instructions on the screen.

Windows 11/10 Backups Not Working? Top Solutions Here to Fix!
Windows 11/10 Backups Not Working? Top Solutions Here to Fix!

Windows 10 Backup not working? Two cases are introduced here: Backup and Restore (Windows 7) not working, Windows 10 File History not working.

Read More

If you don’t want to use this tool but look for a professional and free backup software for file backup, MiniTool ShadowMaker is a good option. This software supports file, folder, disk, partition and system backup & recovery, file sync, and disk cloning. Importantly, it works although the PC fails to boot. Just click the following button to get its Trial Edition to free use for 30 days.

MiniTool ShadowMaker TrialClick to Download100%Clean & Safe

Step 1: Double-click on the .exe file and install MiniTool ShadowMaker on your PC by following the on-screen wizards.

Step 2: Open this software and click Keep Trial to continue.

Step 3: To back up your files, you can go to the Backup page or Sync tab, choose the items you want to back up, and the storage path like an external hard drive or USB flash drive.

Step 4: Click Back Up Now or Sync Now to execute the backup task.

The Backup tab in MiniTool ShadowMaker with selected backup source and target for file backup.

Clean a Hard Drive via Diskpart

Next, it is time to use the clean command in CMD – Diskpart. See how to clean computer using CMD:

Step 1: In the CMD window, type diskpart and press Enter.

Step 2: Type list disk and press Enter.

Step 3: Execute the command – select disk n. N means the disk number. If you see the disk status shows offline, type online disk and hit Enter.

Step 4: To wipe your hard drive, run clean or clean all.

Diskpart clean all command in Command Prompt for disk cleanup.

Tips:

If you want to know the difference between the command – clean and clean all, you can find details from our previous post - Diskpart Clean vs Clean All: Choose a Way to Wipe Disks.

[Solved] How to Get Rid of System Junk Files from Windows 10?
[Solved] How to Get Rid of System Junk Files from Windows 10?

Is it safe to delete system junk files? How to get rid of system junk files to release some space for new data? You can read this article to get the answers.

Read More

Click to Tweet

Bottom Line

That’s all the information about how to clean computer using CMD including deleting unwanted files, temp files, & prefetch files, defragging your hard drive, cleaning cache, erasing a disk, and running DISM. If you need, just speed up your Windows 11/10 computer using these CMD commands when low disk space occurs or the PC runs slowly.

For issues with MiniTool ShadowMaker, contact us at [email protected].

Clean Computer Using CMD FAQ

Is it safe to use Cleanmgr?
Yes, it is safe to use cleanmgr.exe (Windows Disk Cleanup) to delete temporary files and other junk files. This can help free up disk space without damaging the operating system.
How to free up 500GB of storage on a PC?
To free up 500GB of storage on your PC:
1. Run Disk Cleanup to remove temporary files, Windows updates, and other junk files.
2. Empty Recycle Bin.
3. Uninstall unnecessary applications and games.
4. Use MiniTool Partition Wizard to identify which files are taking up the disk space and move large files to an external hard drive.
5. Clear the Downloads folder.
How to 100% wipe your PC?
To wipe your PC completely:
1. Use the Reset this PC feature.
2. Run the Diskpart clean all command.
3. Uses MiniTool Partition Wizard to wipe a hard drive.
How often should I clean my PC using CMD?
For most users, it is enough to clean the PC using CMD every 1-3 months. If you have limited storage space or download many files, it is recommended to run Cleanmgr monthly.
  • linkedin
  • reddit