The Talent500 Blog
How to Clean Your Windows PC Using Command Prompt 1

How to Clean Your Windows PC Using Command Prompt

If your Windows PC runs low on storage space, clean out the junk using these fast Command Prompt utilities.

Keeping your computer free from clutter can help improve performance and free up tons of storage space. Windows comes with several built-in system cleanup utilities, such as the Disk Cleanup tool. However, one lesser-known way to clean your computer is via the Command Prompt.

Here are a few ways to clean up a slow Windows computer using Command Prompt. 

The Disk Cleanup tool in Windows 10 makes it fairly easy to clean up your computer. If any unwanted files remain, you can remove them manually.  For example, clearing your temp folder. You can speed up this process with the help of commands to access the Disk Cleanup tool.

How to Use the Disk Cleanup Utility via Command Prompt

How to Clean Your Windows PC Using Command Prompt 2

Disk Cleanup is a built-in Windows utility to help you free up space on your computer’s hard drive. It can clean up downloads, temporary internet files, recycle bins, and even system files.

You can use the Command Prompt to launch Disk Cleanup and perform automated cleanup tasks directly. Here is how to use the tool and supported command-line switches.

Basic File Deletion

You can use the cleanmgr command to launch the Disk Cleanup tool using Command Prompt. To use it:

Open Command Prompt with admin privileges by typing cmd in the search box, right-click on the command prompt and click on the run as administrator. Type cleanmgr, and hit Enter.

How to Clean Your Windows PC Using Command Prompt 3

How to Clean Your Windows PC Using Command Prompt 4

In the Drive Selection window, select the drive you want to clean up and click OK.

How to Clean Your Windows PC Using Command Prompt 5

Next, in the Disk Cleanup window, select all the files you want to delete and click OK.  If you run cleanmgr with admin privileges, you will find more options to clean in the disk clean-up section.

How to Clean Your Windows PC Using Command Prompt 6

Finally, click on Delete Files to confirm the action.

Cleanmgr /sageset

How to Clean Your Windows PC Using Command Prompt 7

Executing this command skips the drive selection step and shows the Disk Cleanup settings window. From here, you can select the files to delete.

Delete Files Automatically

If you would rather let the Disk Cleanup utility decide what files to delete, use the command cleanmgr /sagerun. Upon execution, it will scan your drives and delete junk files from your system.

How to Clean Your Windows PC Using Command Prompt 8


The low disk switch is useful if you are running low on storage space on your hard disk. When executed, it automatically checks all the file categories by default.

How to Clean Your Windows PC Using Command Prompt 9

When executed, Disk Cleanup will open with all junk file categories selected from the D: drive.

To delete all junk files quickly, without the user prompt, use the following command instead: where d is the letter of the drive which is low on storage.

How to Clean Your Windows PC Using Command Prompt 10

The Disk Cleanup tool cleans temporary files that are older than seven days. But if you have to clean the temp folder frequently, you can do it manually or use the Command Prompt.

You can delete the temp file  manually (Ctrl + A > Delete) from File Explorer or use the following command to delete temp files:

How to Clean Your Windows PC Using Command Prompt 11

Command Prompt will automatically skip any file that is currently in use, but it will delete the rest.

How to Delete Prefetch Files Using Command Prompt

Prefetch files are temporary files created when an application is run on your Windows system. These files contain information that is used to optimize the execution of programs.
Similar to other temporary files, prefetch files often don’t take up much space on your hard drive. However, if you need to delete prefetch files frequently, you can use the Command Prompt to clean up these files on your system.

To delete prefetch files using Command Prompt:

Open Command Prompt as administrator

How to Clean Your Windows PC Using Command Prompt 12

To delete the prefetch files, use the following command and hit enter:

How to Clean Your Windows PC Using Command Prompt 13

Keep Your Computer Clean From Junk Files Using Command Prompt

You can use the Command Prompt to perform various advanced actions, including removing junk files from your computer. While you can use the GUI-based Disk Cleanup tool, Command Prompt makes it easy to clean up individual category files and wipe clean disks.

You can also add these commands in a .bat file and run them all by just clicking the .bat file using admin privileges

How to create a .bat file and add the command

Open Notepad, by typing Notepad in the search box 

How to Clean Your Windows PC Using Command Prompt 14

This will open a blank text file 

In this blank text file, enter all the commands one by one on separate lines

How to Clean Your Windows PC Using Command Prompt 15

Click on file, save as to save the file.  Type any name of your choice and then put the extension as .bat.  here just as a demo, I have added only 2 commands.  You can add many more.  The commands will execute one by one.

How to Clean Your Windows PC Using Command Prompt 16

This will create test.bat on your desktop. Now whenever you want to execute the commands, you can just double-click on the .bat file and the commands will run one by one.  (make sure you right-click on the file and select run as administrator ) to get the best out of the disk cleanup commands)

1+
Avatar

Priyam Vaidya

A certified cloud architect (Azure and AWS) with over 15 years of experience in IT. Currently working as Sr Cloud Infrastructure Engineer. Love to explore and train others on new technology

Add comment