Keeping your computer clutter-free can help improve performance and free up a lot of storage space. Windows comes with several built-in system cleaning utilities, such as the Disk Cleanup tool. However, there is a lesser known way to clean your computer with CMD.
Join the channel Telegram of the AnonyViet 👉 Link 👈 |
Here are some ways to clean Windows using Command Prompt.
Why clean up PC with Command Prompt?
Command Prompt is a built-in command processor available on most versions of Windows since Windows 3.1. Although the graphical user interface is still suitable for most people, some people still prefer to use Command Prompt to perform some tasks for its benefits and performance.
If you are new to Command Prompt, then check out my Command Prompt articles here.
The Disk Cleanup tool and the Storage Sense feature in Windows 10 make cleaning up your computer even easier. If there are still any unwanted files, you can delete them manually, such as deleting your temp folder. You can speed up this process with the help of commands to access Disk Defragmenter, diskpart and Disk Cleanup tool.
Commands to clean junk files with CMD
Below is a list of commands to launch utilities that clean up disks, delete temporary files, cache and more.
Some of these commands may require you to open Command Prompt as an administrator. Here’s how to do it.
- Import cmd into the Windows search bar.
- Right click on Command Prompt.
- Select Run as administrator.
How to defragment a hard drive with CMD
While drive fragmentation on traditional hard disks is common, it can cause performance issues. It affects the speed of accessing and writing data of the drive, making your system slower.
Defrag rearranges fragmented data to make your drive more efficient. You don’t need to defragment your SSD, but if you use a mechanical HDD, here’s how to defragment it with commands.
Step 1: Open Command Prompt with Admin rights
Step 2: In the Command Prompt, type the following command and press enter:
defrag c:
Step 3: In the above command, c: is the drive that you want to defragment. Change the drive letter if you want to defrag another drive.
You can run the defrag command with different options. This Microsoft document provides more detailed information on using different options with defrag command to perform analysis, add exceptions, change priority and much more.
How to use Disk Cleanup with CMD
Disk Cleanup is a built-in Windows utility to help you free up space on your computer’s hard drive. It can clean downloaded files, temporary internet files, recycle bin and even system files.
You can use Command Prompt to launch Disk Cleanup and directly perform some automatic cleaning tasks. Here’s how to use the tool and supported commands.
Delete Basic File
You can use the cleanmgr command to launch the Disk Cleanup tool using the Command Prompt:
Step 1: Open Command Prompt, type cleanmgr and press Enter.
Step 2: In the window Drive Selectionselect the drive you want to clean and tap OK.
Step 3: Next, in the window Disk Cleanupselect all the files you want to delete and press OK.
Step 4: Finally, press Delete Files to confirm the action.
Skip Drive Selection
cleanmgr /sageset
Executing this command will skip the drive selection step and display the Disk Cleanup installation window. From here, you can select files to delete.
Automatically delete files
If you want to let the Disk Cleanup utility decide which files to delete, use the cleanmgr /sagerun command. Once executed, it will scan your drive and remove Junk Files from the system.
cleanmgr /sagerun
Optimized for low capacity drives
Option lowdisk, as the name suggests, is useful if the drive is running low on storage space. When executed, it automatically checks all File categories by default.
When using this command, enter the drive letter to free up space. The command will look something like this:
cleanmgr /lowdisk /d
When executed, Disk Cleanup will select all Junk File categories from drive D.
To delete all junk files quickly without user confirmation, use the following command:
cleanmgr /verylowdisk /d
How to delete Temporary Files with CMD
Windows creates temporary files for temporary use. Temporary files rarely take up large space on your hard drive and are essential for the system to function smoothly. When the task is complete, your system will automatically delete them from the temporary folders.
The Disk Cleanup tool cleans up temporary files older than seven days. But if you have to clean the temp folder often, you can do it manually or using Command Prompt.
To view temporary files, enter the following command into the Command Prompt:
%SystemRoot%\explorer.exe %temp%\
You can delete these files manually (Ctrl + A > Delete) from File Explorer or use the following command to delete temporary files:
del %temp%\*.* /s /q
The Command Prompt will automatically ignore any files that are currently in use, but it will delete the remaining files.
Clean up hard drive with Diskpart
If you want to wipe the entire drive, you can use the diskpart utility. Diskpart is a Windows command line utility with more than 38 commands for different functions.
To wipe the drive, you can use diskpart’s clean command. When executed, it erases all data and converts the disk to unallocated space.
Use caution when using the diskpart utility. Using the incorrect command may cause you to lose all data and you may not be able to recover any data. Therefore, I recommend that you create a backup of your system data before using the diskpart tool.
To clean up the drive:
Step 1: Import diskpart in Command Prompt and press enter.
Step 2: Next, type list disk to view all installed disks on your system.
Step 3: Select the disk you want to wipe. Eg:
Select disk 0
Step 4: If the disk status is offline, enter online disk and press enter.
Step 5: To wipe your disk, type the following command and press enter:
Clean all
Step 6: Once done, type exit to close diskpart.
You can use the Command Prompt to perform various advanced actions, including deleting Junk Files from your computer. While you can use the GUI-based Disk Cleanup tool, the Command Prompt makes it easy to clean individual directory files and wipe drives.