How to Clean your Windows PC using CMD

Photo of author
Written By Larious

Larious is the Executive Editor of LowkeyTech. He is a tech enthusiast and a content writer. 

 

 

 

 

Last Updated on November 17, 2024 by Larious

Keeping your computer free from clutter is one way to improve performance and stability. Just cleaning up the junk files can free up tons of disk space.

Windows 10 & 11 also offer several built-in system junk cleaning utilities to free up storage space. Although it’s pretty easy to access those tools, wouldn’t it be easier to access the hidden tools via CMD?

This article will share some of the best methods to clean Windows PC via Command Prompt.

1. Defragment Hard Disk via CMD

In this method, we will defrag our hard disk via CMD. This method will clean all junk files stored on selected drives. Let’s check out.

1. First, click the Windows Start button and type in CMD. Next, right-click on the Command Promot and select Run as Administrator.

open CMDopen CMD

2. On the Command Prompt, enter the command:

defrag c:

defrag c:defrag c:

Important: The above command will defrag the C: Drive of your PC. Change the drive letter if you want to defrag any other drive.

3. Now, the Disk Defragment tool will scan the selected drive and remove the junk & temp files.

remove the junk & temp filesremove the junk & temp files

2. Run Disk Cleanup Utility via CMD

In this method, we will run Windows’ built-in Disk Cleanup utility to free up storage space. Follow the simple steps below.

1. Click on the Windows Start button and type in CMD. Next, right-click on the Command Promot and select Run as Administrator.

Run Disk Cleanup Utility via CMDRun Disk Cleanup Utility via CMD

2. Now, on the Command Prompt, type in cleanmgr and hit the Enter button.

cleanmgrcleanmgr

3. This will launch the Disk Cleanup utility. Select the drive you want to clean and click the Ok button.

Disk Cleanup utilityDisk Cleanup utility

4. If you wish to skip the drive selection pop-up, enter the command:

cleanmgr /sageset

cleanmgr /sagesetcleanmgr /sageset

You need to select the files to delete after executing the above command

5. If you wish to delete files automatically, then execute the command:

cleanmgr /sagerun

cleanmgr /sageruncleanmgr /sagerun

The above command will automatically scan your drives and delete junk files from your PC.

3. Clear Temporary Files Using the Command Prompt

You can also use the Command Prompt utility to clear the temporary files. Here’s how you can clear the temporary files using the Command Prompt utility on Windows.

1. Click on Windows 11 Search and type Command Prompt. Right-click on the Command Prompt and select Run as administrator.

Run as administratorRun as administrator

2. When the Command Prompt opens, execute the given command:

%SystemRoot%\explorer.exe %temp%\

execute the given commandexecute the given command

3. You can use the CTRL + A function to select all files. Once selected, you can delete it. Or else, execute the command to delete all temporary files.

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

delete all temporary filesdelete all temporary files

4. Delete the Prefetch Files Using the Command Prompt

Prefetch files are temporary files you can delete to free up storage space. Here’s how to do so using the Command Prompt.

1. Open Command Prompt with admin rights (Right click > Run as administrator).

Run Command Prompt As an AdministratorRun Command Prompt As an Administrator

2. When the Command Prompt opens, execute this command:

%SystemRoot%\explorer.exe C:\Windows\prefetch\

execute this commandexecute this command

3. Once done, execute this command to delete the Prefetch files:

del C:\Windows\prefetch\*.*/s/q

delete the Prefetch filesdelete the Prefetch files

This guide explains how to clean your Windows 10/11 PC via Command Prompt. I hope this article helped you! Please share it with your friends. If you have any doubts, let us know in the comment box below.

Previous

How to Turn Windows Efficiency Mode Off

How to Turn On or Off Professional Mode on Facebook

Next