Skip to content

How to Use Command Prompt to Clean Your Windows 11 PC

May 30, 20253 minute read

If you enjoy using the Command Prompt to maintain your Windows 11 PC, you can easily execute commands to clean your system. This allows you to remove junk files, temporary files, prefetch files, and even defragment your hard drive.

Windows 11 includes a built-in disk cleanup tool designed to clear system junk, temporary files, and other unnecessary items that consume resources and take up storage space. While accessing these tools is straightforward, Command Prompt enthusiasts may prefer to utilize these hidden features through CMD for a more streamlined experience.

Utilizing CMD for maintenance tasks is perfect for users who prefer a command-line interface for a cleaner, faster Windows 11 experience. Here is how to do it.

How to Use Command Prompt to Run Disk Cleanup Utility

1. First, open the Command Prompt as administrator.

Open CMD as administrator

2. Next type the command cleanmgr and press Enter button.

Disk cleanup via CMD

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

4. If you wish to skip the drive selection pop-up, execute the command: cleanmgr /sageset

Command to clean junk files
[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

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

How to Clear Temporary Files Using the Command Prompt?

1. Open Command Prompt as administrator.

2. Execute the given command: %SystemRoot%\explorer.exe %temp%\

Command to clean temporary files in Windows 11

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

4. Or execute the command del %temp%*.* /s /q to delete all temporary files.

How to Delete the Prefetch Files Using the Command Prompt

1. Open Command Prompt as administrator.

2. Execute the command %SystemRoot%\explorer.exe C:\Windows\prefetch\

Command to clean prefetch files in Windows 11

3. Once done, execute this command to delete the Prefetch files: del C:\Windows\prefetch*.*/s/q

How to Defrag the Hard Disk via Command Prompt

Important: Do not defrag SSD. Execute the command if your PC has HDD.

1. Open Command Prompt as administrator.

2. Type the command defrag c: and press Enter. [Change the drive letter if you want to defrag any other drive.]

3. The Disk Defragment tool will scan the selected drive and defrag the drive.

Conclusion:

In summary, cleaning your Windows 11 PC via Command Prompt is an efficient way to remove junk files, temporary files, and prefetch data. By executing specific commands, you can optimize system performance and free up storage space. This method is ideal for users who prefer a command-line interface for maintenance tasks.

JP, your go-to how-to expert and IT specialist with two decades of experience. He shares his knowledge through blogging filled with practical tips and guidance to help you enhance your computer and smartphone skills.

Previous Article --- Next Article

No Comments

Comments (0)

Leave a Reply

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

Related Posts
Recent Articles
Tutorials
Back To Top