Keeping your computer free from clutter can help improve performance and free up storage space. Windows has several built-in system cleanup utilities, including the Disk Cleanup tool. However, the Command Prompt is a lesser-known method to clean your computer.
Here are a few ways to clean up a slow Windows computer using Command Prompt.
Why Clean Up Your Computer Using the Command Prompt?
Command Prompt is a built-in command processor available on almost all Windows versions since Windows 3.1. While the graphical user interface is convenient for most people, some prefer Command Prompt for tasks due to its efficiency and performance benefits.
If you are new to Microsoft’s command processor, check out our beginner’s guide to the Windows Command Prompt.
The Disk Cleanup tool and Storage Sense feature in Windows 11 make it fairly easy to clean up your computer. If any unwanted files remain, you can remove them manually by, for example, clearing the temp folder. You can speed up this process with the help of commands to access the Disk Defragmenter, diskpart, and the Disk Cleanup tool.
Start Cleaning Your Computer Using CMD
Below is a list of commands to launch the disk cleanup utility, clean temporary files, memory cache, and more.
Some of these commands may require you to open Command Prompt as administrator. Here’s how to do it:
- Type
cmd
in the Windows search bar. - Right-click on Command Prompt and select Run as administrator.
How to Defragment Hard Disk With the Command Prompt?
While disk fragmentation on traditional hard disks is natural, it can cause performance issues. It affects your disk’s read and write speed, slowing down your system.
Defragmentation rearranges fragmented data to help your disks work more efficiently. You don’t need to defragment your SSD storage devices (nor is it recommended). But if you use a mechanical hard drive, here’s how to defragment the hard disk with a command:
- Open the Command Prompt as administrator.
- In the Command Prompt, type the following command and hit enter:
defrag c:
In the above command, c:
is the drive you want to defrag. Change the drive letter if you want to defrag another drive.
You can run the defrag command with optional switches. Check Microsoft’s documentation on using the defrag command for more insight into using different syntax with the defrag command to perform analysis, add exceptions, change priority, and more.
Quick Disk Cleanup Using the Run Box
You can use a Run command to perform a quick disk cleanup without opening the Command Prompt. It is useful if you want to free up a few gigabytes of storage in two steps. This requires you to start the Disk Cleanup tool and specify the disk you want to clean via the Run dialog.
To run Disk Cleanup:
- Press
Win + R
to open Run. - Type the following command in the Run dialog:
C:\windows\SYSTEM32\cleanmgr.exe /dDrive
In the above command, replace Drive
with the disk drive letter you want to clean. For example, if you want to perform a quick cleanup for the E drive, then the full command will look like this:
C:\windows\SYSTEM32\cleanmgr.exe /dE
- Click OK or press Enter to execute the command.
- Run will quickly launch the Disk Cleanup tool with your specified drive selected.
- Select the files to delete and click OK.
How to Use the Disk Cleanup Utility via Command Prompt
Disk Cleanup is a built-in Windows utility to help you free up space on your computer’s hard drive. It can clean up downloads, temporary internet files, recycle bin, and even system files.
You can use the Command Prompt to launch Disk Cleanup and perform automated cleanup tasks directly. Here is how to use the tool and supported command-line switches.
Basic File Deletion
You can use the cleanmgr
command to launch the Disk Cleanup tool using Command Prompt.
- Open Command Prompt, type
cleanmgr
, and hit Enter. - In the Drive Selection window, select the drive you want to clean up and click OK.
- In the Disk Cleanup window, select all the files you want to delete and click OK.
- Click on Delete Files to confirm the action.
Cleaning a Hard Disk Using Diskpart
If you want to wipe clean an entire disk, you can use the diskpart utility. Diskpart is a Windows command-line utility supporting over 38 commands for different functions.
To wipe clean a disk, you can use diskpart’s clean command. Upon execution, it deletes all the data and converts the disk into unallocated space.
Exercise caution when using the diskpart utility. Using incorrect objects can cost you all of your data, and you may not be able to recover any of it at all. Therefore, create a backup of your critical system data before using the diskpart tool.
To clean a disk:
- Type
diskpart
In the Command Prompt and hit enter. - Next, type
list disk
to view all the installed disks on your system. - Select the disk you want to wipe clean. For example:
Select disk 0
- If the disk status shows offline, type
online disk
and hit enter. - To wipe clean your disk, type the following command and hit enter:
Clean all
- Once completed, type
exit
to close diskpart.
Keep Your Computer Clean From Junk Files Using Command Prompt
You can use the Command Prompt to perform various advanced actions, including removing junk files from your computer. While you can use the GUI-based Disk Cleanup tool, Command Prompt makes it easy to clean up specific types of files and wipe clean disks.