How to Clean Your Windows PC Using Command Prompt

How to Clean Your Windows PC Using Command Prompt

Utilize these quick Command Prompt programs to clear away the clutter if your Windows computer is running out of storage space.

Maintaining a clutter-free PC may enhance speed and liberate a ton of storage space. Windows has a number of built-in system-cleaning tools, including the Disk Cleanup program. However, using the Command Prompt is a less well-known method of cleaning your computer.

Here are a few tips for utilizing Command Prompt to speed up a slow Windows machine.

Why Use Command Prompt to Clean Up Your Computer?

A built-in command processor called Command Prompt has been a part of Windows since Windows 3.1. While the graphical user interface is convenient for the majority of users, others may like the Command Prompt for a variety of activities due to its speed and performance advantages.

Check out our beginner’s tutorial to the Windows Command Prompt if you’re unfamiliar with Microsoft’s well-known command processor.

Cleaning up your PC is a reasonably simple process thanks to Windows 10’s Disk Cleanup tool and Storage Sense function. If any undesirable files are still present, you may manually get rid of them by, for instance, deleting your temporary folder. Disk Defragmenter, diskpart, and the Disk Cleanup tool access commands can assist you speed up this procedure.

CMD Commands for Computer Cleaning

The list of instructions to run the disk cleanup tool, clear temporary files, the memory cache, and more is provided below.

You might need to launch Command Prompt as administrator for some of these tasks. This is the procedure.

In the Windows search box, type cmd.
Right-click the Command Prompt icon.
Go to Run and choose Administrator.

How to Use Command Prompt to Defragment a Hard Drive?

Disk fragmentation on conventional hard drives happens naturally, however it can impact performance. It slows down your system by affecting the access and write speeds of your disk.

Command Prompt

Defragmentation reorganizes fragmented data to improve the performance of your drives. Although it is not necessary or advised to defragment SSD storage devices, here is how to use a command to do so if you use a mechanical drive.

  1. As an administrator, launch the Command Prompt.
  2. Enter the following command into the Command Prompt:
defrag c:

3. The disk you wish to defragment is indicated by the command above as c:. If you wish to defragment a different drive, change the drive letter.

The defrag command has optional switches. More information on utilizing various syntax with the defrag command to do analysis, add exceptions, adjust priority, and other tasks is provided in this Microsoft Documentation.

Using the Run Box to Perform Quick Disk Cleaning

Command Prompt

Without even opening the Command Prompt, you may quickly clear up your drive with the Run command. Useful if you need to quickly clear up a few megabytes of storage. Start the Disk Cleanup program, and then use the Run dialog to choose the disk you wish to clean.

Using Run, launch Disk Cleanup:

  • Open Run by pressing Win + R.
  • In the Run dialog box, enter the following command:
C:\windows\SYSTEM32\cleanmgr.exe /dDrive
  • Replace Drive with the disk drive letter you wish to clean in the aforementioned command. For instance, the whole command might be as follows if you wanted to quickly clear out the E drive:
C:\windows\SYSTEM32\cleanmgr.exe /dE
  • To run the command, hit Enter or click OK.
  • Run will instantly open the Disk Cleanup application with the disk you specify already selected.
  • Click OK after selecting the files to remove.

How to Use the Command Prompt to Use the Disk Cleanup Utility

Disk Cleanup Utility

A built-in Windows tool called Disk Cleanup can assist you in making space on your computer’s hard disk. Downloads, transient internet files, recycle bin contents, and even system files may all be cleaned away.

You may start Disk Cleanup and carry out several automatic cleanup activities straight from the Command Prompt. Here is how to use the tool and supporting command-line switches.

Simple File Removal

The Disk Cleanup program may be started in Command Prompt by using the cleanmgr command. To apply it:

  1. Enter cleanmgr at the Command Prompt after opening it.
  2. Choose the drive you wish to clean up in the Drive Selection box, then click OK.
  3. Select all the files you wish to remove and then click OK in the Disk Cleanup box.
  4. To confirm the action, click Delete Files at the end.

Not choosing a drive.

cleanmgr /sageset

By using this command, the disk selection phase is skipped, and the Disk Cleanup settings box is displayed instead. You may choose which files to remove from here.

Delete Files Automatically

Use the cleanmgr /sagerun variation if you’d prefer allow the Disk Cleanup tool determine which files to remove. Upon execution, it will check your disks for trash files and remove them from your computer.

cleanmgr /sagerun

Improve for Small Space

As its name indicates, the lowdisk option comes in handy if your hard drive is getting low on storage capacity. When it is performed, it by default checks every file category.

When executing this form of the command, specify the drive letter for the partition to free up space. The command will have the following format:

cleanmgr /lowdisk /d

When launched, Disk Cleanup will open with all D: disk trash file categories already chosen.

Instead, use the following command to immediately remove all garbage files without the user being prompted:

cleanmgr /verylowdisk /d

How to Clear Temporary Files Using Command Prompt?

For short-term use, Windows generates temporary files. The efficient operation of your system depends on the presence of temporary files, which seldom take up much space on your hard disk. Your system ought to automatically remove them from the temporary directories after the process is finished.

Temporary files that are older than seven days are delete by using the Disk Cleanup program. However, if you regularly need to clean the temp folder, you may do it manually or with the help of the Command Prompt.

Clear Temporary Files

Enter the following command in Command Prompt to access temporary files:

%SystemRoot%\explorer.exe %temp%\

You may manually delete these files using the File Explorer by pressing Ctrl + A > Erase, or you can use the following command to delete temporary files:

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

Any file that is presently being used will be immediately skipped by Command Prompt, but the remaining files will be deleted.

Using the Command Prompt, how to Remove Prefetch Files

Prefetch files are temporary files that are generated when a Windows application is started. These files include data that helps applications run as efficiently as possible.

Prefetch files often don’t use up much space on your hard disk, similar to other temporary files. However, you may utilize the Command Prompt to clear up these files from your system if you regularly need to erase prefetch files.

Using Command Prompt, erase prefetch files as follows:

  • As an administrator, launch Command Prompt.
Remove Prefetch Files
  • To examine the prefetch files, enter the following command in the Command Prompt window:
%SystemRoot%\explorer.exe C:\Windows\prefetch\

It will display the prefetch files that you may remove and access the prefetch folder in File Explorer.

Remove Prefetch Files
  • Use the following command and press Enter to remove the prefetch files.
del C:\Windows\prefetch\*.*/s/q
  • All of the prefetch files that have been destroyed will be listed in Command Prompt.

Diskpart: Cleaning a Hard Disk

You may make use of the diskpart tool to completely erase a disk. Diskpart is a Windows command-line tool that supports over 38 distinct commands for various tasks.

The clean command in diskpart may be for complete erase of a disk. Upon execution, it purges the disk of all data and turns it into empty space.


When using the diskpart tool, use care. You risk losing all of your data if you use the wrong items, and you might not be able to retrieve any of it. So, before using the diskpart program, we advise you to make a backup of your crucial system data.

Clearing a disk

  • In the Command Prompt, type diskpart and press Enter.
  • To examine all the installed disks on your system, type list disk next.
  • Choose the disk that needs to clean. For instance
Select disk 0
  • Type online disk and press enter if the disk state is offline.
  • Simply execute the following command to wipe your drive clean.
Clean all

When finished, type quit to shut off diskpart.

Using Command Prompt, keep your computer free of unnecessary files

You may remove unnecessary files from your computer using the Command Prompt, among other complex tasks. Although the GUI-based Disk Cleanup program is available, cleaning up certain category files and wiping clean drives is simple with Command Prompt.

Frequently Asked Questions

1.How can I use Command Prompt to fix Windows 10?

Search for the Command Prompt under “Start,” choose it, and execute it as administrator. 2. After that, use the command “sfc /scannow”. If SFC is unable to resolve the issue, it is likely that the tool is unable to access the essential files from the Windows image, which may have developed a problem. I expect that you got the answer.

Leave a Reply

Your email address will not be published. Required fields are marked *