How to Clean Computer Using Command Prompt - Tutorial

Sherly updated on Apr 19, 2024 | Home >Computer Instruction

Key Notes:

💡Command Prompt can clear unwanted files, temporary files, prefetch files, cache, and defragment your hard drive.

💡The Command Prompt is a bit difficult for beginners; please read the following guides carefully to avoid data loss. You can also turn to EaseUS Partition Master Free Edition. This tool can defrag your hard drive, clean your PC cache, and analyze your disk as an easier-to-use alternative to Command Prompt.

Free Download 

Windows 11/10/8/7100% Secure

Cleaning up your PC helps improve performance and free up lots of storage space. However, how to use CMD to speed up your PCs? You can follow this article to learn exactly how to clean up PC using CMD.

Why Use CMD to Clean up PC?

Windows has several built-in system cleaning utilities, just like the Disk Cleanup tool. However, the Command Prompt is a lesser-known way to clean up your computer.

Command Prompt is a built-in command processor compatible with Windows 11 and Windows 10/8/7/XP/Vista. Although it requires entering the command line, it has efficiency and performance advantages for Advanced users.

If you don't know how to run commands to clean Windows 11, Windows 10/8/7 PCs, follow the given guide to clean your computer, which can remove unnecessary files, temporary and prefetched files, cached data, and damage to the hard drive Defragment drives, wipe disks, etc.

Here are a few ways to clean up your calculator and speed up Windows performance using Command Prompt. If these Guides are useful to you, don't forget to share this article to help more people.


How to Clean Computer Using Command Prompt?

We will show you how to use different commands in CMD to clean different files. First, you need to open the command prompt with administrator rights.

To do this, follow the instructions:

  • In Windows 10/11, type cmd in the search box.
  • Select Command Prompt and click RunRun as administrator to open the CMD window.

run as administrator

1. Run Disk Cleanup via CMD

Disk Cleanup is a built-in Windows utility that searches and analyzes your hard drive and helps you free up space on your computer's hard drive. It can clean downloads, temporary files, Recycle Bin, and even system files. 

Guide 1. Delete Basic Files

First, let's learn how to use CMD

to start Disk Cleanup and delete essential files. You can start the disk cleaning tool through the command prompt using the cleanmgr command. Here are the steps:

Step 1: Open a command prompt, type cleanmgr, and press Enter.

Step 2: In the Drive Selection interface, select the drive you want to clean and click OK.

Step 3: In Disk Cleanup, select all the files you want to delete and click OK. Click Delete Files to confirm the action.

run disk cleanup

Guide 2. Clean Specific Drive

You can run the disk cleanup tool against a drive by typing the cleanmgr command followed by the drive letter. This can be useful to free up space on a specific drive. For example, you can run the following command to clean up the C drive:

cleanmgr /D C

The Disk Cleanup will scan and display all files on your C drive that you can delete. Select them and click OK to remove these files.

Guide 3. Configure the Disk Cleanup Settings

The disk cleanup command provides several parameters dedicated to specific functions. You can customize Disk Cleanup tool settings.

  1. ✔️Cleanmgr /sageset

This skips drive selection and redirects you to the Disk Cleanup Settings window to select the items you want Disk Cleanup to clean automatically during its scheduled run time.

  1. ✔️Cleanmgr /sagerun

This command will automate the disk cleanup process without selecting a category.

  1. ✔️Cleanmgr /lowdisk

You can use this command when the disk drive is low on space. Disk Cleanup will open with all checkboxes selected by default.

2. Run CMD to Remove Temporary Files

Windows creates temporary files for temporary use. They do not take up much disk space and play an important role in the smooth operation of the system. If you must clean your temporary folders frequently, you can do this using Command Prompt.

The storage path for temporary files created by the Windows operating system is %system%/windows/temp. Temporary files created by users are stored in C:\Users\username\AppData\Local\Temp.

Run this command – %SystemRoot%\explorer.exe %temp%\ to open the Temp folder in File Explorer. Then, press Ctrl + A to select all files and delete them. Or run the command – del %temp%\*.* /s /q to delete these temporary files. CMD can automatically skip any files currently in use but delete the remaining temporary files.

delete temp files

How to remove temp files using Command Prompt? In this part, you are sure to have found the step-by-step guide on it. Please share this article and let more users know about it.


3. Delete Prefetch Files Using CMD

Prefetch files are temporary files created when an application runs on Windows. These files contain information used to optimize program execution, such as the number of times the software was run, the run time, and associated files used by the software.

Like other temporary files, prefetch files usually don't take up much space on your hard drive. If you must clean up Windows 10 or Windows 11 prefetch files, please follow the steps below:

Step 1: Open Command Prompt in Windows with administrator rights.

Step 2: Enter %SystemRoot%\explorer.exe C:\Windows\prefetch\ in the command prompt window and press Enter. This will open the Prefetch folder in File Explorer.

delete prefetch folder

Step 3: You can delete the Prefetch folder directly from Windows Explorer. Alternatively, you can also delete it in the CMD window.

Enter del C:\Windows\prefetch\*.*/s/q and press Enter to delete these prefetch files.

4. Defrag Hard Drive Using CMD

An effective way to clean up your computer using CMD is to defragment the disk. While fragmentation on a hard drive occurs naturally, it can cause PC performance issues, such as slower access and write speeds, or slow down the system. Here, we'll show you how to defrag the hard drive using CMD:

Step 1: Launch the Command Prompt as administrator.

Step 2: Type defrag c: in the CMD window and press Enter. Here, replace c: with the target drive letter.

defrag c

The commands only work for HDDS. If you are using an SSD, turn to a reliable SSD optimizer to boost its performance.

5. Clear the Cache in the Windows Command Prompt

Caching files can significantly improve performance, availability, and scalability and can result in the ability to serve data quickly and faster response times. However, if there are errors in the cached files, data retrieval issues or even crashes may occur. You can prevent or resolve this problem by clearing cache files regularly.

  • To clear the DNS cache, execute the lines in the CMD window: ipconfig/flushDNS
  • To clear the Windows storage cache, execute this command: wsreset.exe

EaseUS Partition Master is also a reliable free PC cache cleaner; you can install it on your PC as an alternative to Command Prompt if you are unfamiliar with the command lines.

Free Download 

Windows 11/10/8/7100% Secure

6. Wipe the Whole Disk

If you want to erase the entire disk, you can launch diskpart by using CMD. Diskpart is a command-line disk utility compatible with Windows 2000 and later Windows versions. Its predecessor was fdisk. Diskpart commands can manage your disks and partitions by creating, deleting, and erasing entire disks.

Before wiping the whole disk using CMD, remember to back up the important data.

Here is how to use Command Prompt to clean your hard drive and wipe the whole disk:

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

Step 2: Type list disk and press Enter; this will display all the hard drives installed on your computer.

Step 3: Enter select disk n. n represents the disk number.

Note: If you see the disk status showing offline, type online disk and press Enter.

Step 4: To wipe the hard drive, type clean all or clean and press Enter.

type clean or clean all

During this process, you may meet the "there are no fixed disks to show in Diskpart" error; click the link to learn the fixes.

Command Prompt allows you to use different commands to clean different junk files on your computer. However, not all users can easily use this tool. There are different files to clean. CMD requires familiarity with all the above commands, which is too difficult for beginners. Hence, we recommend that beginners use EaseUS Partition Master to clean their PCs.

An Easier Option to Clean Windows PC

In order to avoid data loss caused by entering wrong commands and simplify the computer cleaning process, we recommend you use EaseUS Partition Master, which is a disk and computer space optimization manager for Windows 11/10/18/8.1/7/XP computers.

Free Download 

Windows 11/10/8/7100% Secure

It can replace CMD to clean disks and computers in the following aspects:

  1. ✔️Wipe Disk: Make the disk as new as you bought.
  2. ✔️Extend Volume When Low Disk Space: Extend the target drive when a low disk space error occurs, such as extending the C drive from the D drive or any unallocated space on the disk.
  3. ✔️Clear Cache: Its "Clean Genius" feature can search and delete all the cache on the Windows PC.
  4. ✔️Analyze Disk Space: EaseUS Partition Master can analyze your disk, locate the large files taking up your disk, and one-click remove the large files.

Here, I'll show you how to analyze disk space and clean a computer:

Step 1. Launch EaseUS Partition Master and turn to Discovery. Find and Download Space Analyzer below Frequently Used Tools.

download space analyzer

Step 2. In the Space Analyzer pop-up window, select the target disk to be analyzed and click Analyze in the upper right corner.

click analyze

Step 3. Wait a while, and you will see the detailed data. You can click on Folder/File to view different data types and click on the small folder icon to see more information inside the file.

view the detailed data

Then, click the folder icon to delete the large files that are taking up disk space.

Free Download 

Windows 11/10/8/7100% Secure

Editor's Thought

If you run CMD to clean your computer, you will need to have a clear understanding of many commands and be familiar with Command Prompt. However, EaseUS Partition Master allows you to completely clean all junk files on Windows without entering complicated commands.

Don't miss this tool if you want to make computer cleaning easier and simpler.

Run Commands for Cleaning PC FAQs

We hope you can have a smooth computer by following the above solutions. If you have further questions, please continue reading.

1. How to start Disk Cleanup by using the command line?

To start the Disk Cleanup and specify the hard disk to be cleaned by using the command lines, follow these steps:

  • Click Start, and then click Run.
  • In the Open box, type the following command, and then press Enter: c:\windows\SYSTEM32\cleanmgr.exe /dDrive​​​​​​
  • Note: In this command, the placeholder Drive means the drive letter of the hard disk to be cleaned.

2. How do I clean up my computer using cmd?

To use CMD to speed up the computer: Open Command Prompt with admin privileges via typing cmd in the Windows search box, right-click the Command Prompt, and select the RunRun as administrator option. Type cleanmgr, and hit Enter. In the Drive Selection window, select the drive you want to clean and click OK.

3. How can I speed up my computer using cmd?

To speed up your computer using CMD, follow the instructions:

  • To open Command Prompt, press Win + R, input cmd, and then hit Enter. 
  • After typing powercfg -list, hit Enter. The list of three power scheme codes for high performance, power saving, and balanced modes should be visible to you. The one that is enabled will have a * next to it.
  • The high-performance power scheme's code should be copied. 
  • Next, type the subsequent command: powercfg -setactive CODE, with CODE being the copied value. 
  • Lastly, to view the most recent power schemes, use powercfg -list. Next to the high-performance one, you ought to have *.

4. What is the clean command in cmd?

Clean is the command line to erase the whole disk and make the the disk as new as before.Cleaning or erasing a storage device removes all data and partitions from the drive.

Was This Page Helpful?


Updated by Sherly

Sherly joined EaseUS in 2022 and she has always loved writing articles and enjoys the fun they bring. She receives professional training here, focusing on product performance and other relative knowledge. She has written over 200 articles to help people overcome computing issues.

Read full bio

Totalav antivirus software

EaseUS Data Recovery Services

Request a free evaluation >>

EaseUS data recovery experts have uneaqualed expertise to repair disks/systems and salvage data from all devices like RAID, HDD, SSD, USB, etc.