Keeping your computer free from clutter can help improve performance and free up tons of storage space. Windows comes with several built-in system-cleanup utilities, such as the Disk Cleanup tool. However, one lesser-known way to clean your computer is via the Command Prompt.
Here are a few ways to clean up a slow Windows computer using Command Prompt.
Why Clean Up Your Computer Using 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 handy for most people, some may prefer the Command Prompt to perform several tasks for its efficiency and performance benefits.
If you are new to Microsoft’s popular command processor, check out our beginner’s guide to the Windows Command Prompt.
The Disk Cleanup tool and the Storage Sense feature in Windows 10 make it fairly easy to clean up your computer. If any unwanted files remain, you can remove them manually by, for example, clearing your temp folder. You can speed up this process with the help of commands to access the Disk Defragmenter, diskpart, and the Disk Cleanup tool.
Commands to Clean Your Computer Using CMD
Below is the 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.
- Select Run as administrator.
How to Defragment Hard Disk With Command Prompt?
While disk fragmentation on traditional hard disks is a natural occurrence, it can cause performance issues. It affects the access and write speed of your disk, making your system slow.
Defragmentation rearranges fragmented data to help your disks work more efficiently. You don’t need to defragment your SSD drives, but if you use a mechanical 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 that you want to defrag. Change the drive letter if you want to defrag another drive.
You can run the defrag command with optional switches. This Microsoft Documentation offers more insight into using different syntax with the defrag command to perform analysis, add exceptions, change priority, and more.
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 some automated cleanup tasks directly. Here is how to use the tool and command-line switches supported.
Basic File Deletion
You can use the cleanmgr command to launch the Disk Cleanup tool using Command Prompt. To use it:
- Open Command Prompt, type cleanmgr, and hit Enter.
- In the Drive Selection window, select the drive you want to clean up and click OK.
- Next, in the Disk Cleanup window, select all the files you want to delete and click OK.
- Finally, click on Delete Files to confirm the action.
Skipping Drive Selection
cleanmgr /sageset
Executing this command skips the drive selection step and shows the Disk Cleanup settings window. From here, you can select the files to delete.
Delete Files Automatically
If you would rather let the Disk Cleanup utility decide what files to delete, use the cleanmgr /sagerun variant. Upon execution, it will scan your drives and delete junk files from your system.
cleanmgr /sagerun
Optimize for Low Space
The lowdisk switch, as the name suggests, is useful if you are running low on storage space on your hard disk. When executed, it automatically checks all the files categories by default.
When using this form of the command, enter the drive letter for the partition to free up space. The command will look something like this:
cleanmgr /lowdisk /d
When executed, Disk Cleanup will open with all junk files categories selected from the D: drive.
To delete all junk files quickly, without the user prompt, use the following command instead:
cleanmgr /verylowdisk /d
How to Clear Temporary Files Using Command Prompt?
Windows creates temporary files for momentary use. Temp files rarely occupy a large space on your hard drive and are essential for the smooth functioning of your system. When the task is complete, your system should automatically discard them from the temporary folders.
The Disk Cleanup tool cleans temporary files that are older than seven days. But if you have to clean the temp folder frequently, you can do it manually or using the Command Prompt.
To view temporary files, enter the following command in Command Prompt:
%SystemRoot%\explorer.exe %temp%\
You can delete these files manually (Ctrl + A > Delete) from the File Explorer or use the following command to delete temp files:
del %temp%\*.* /s /q
Command Prompt will automatically skip any file that is currently in use, but it will delete the rest.
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 with support for 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, we recommended you create a backup of your important 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 individual category files and wipe clean disks.