How to clean Windows PC using Command Prompt

Windows has a number of built-in system cleanup utilities, including the Disk Cleanup tool. However, Command Prompt is a lesser-known way to clean up your computer.

Here are some ways to clean up a slow Windows computer using Command Promt.

Start cleaning up your computer using CMD

Below is a list of commands to launch the disk cleaning utility, clean temporary files, cache, etc. Some of these commands may require you to open Command Prompt with admin rights.

How to defragment hard drive using Command Prompt?

Although fragmentation on traditional hard drives is normal, it can cause performance problems. It affects the read and write speed of the drive, making your system run slow.

How to clean Windows PC using Command Prompt Picture 1

 

Defragmentation reorganizes fragmented data to help your drive operate more efficiently. You do not need to defragment your SSD storage device (this is also not recommended). But if you use a mechanical hard drive, here's how to defragment your hard drive using commands.

  1. Open Command Prompt with admin rights.
  2. In Command Prompt, type the following command and press Enter :
    defrag c:
  3. In the command above, c: is the drive you want to defragment. Change this character if you want to defragment another drive.

You can run the defrag command using optional switches. Refer to the article: Defrag command in Windows to better understand how to use different syntax with the defrag command to perform analysis, add exceptions, change priority, etc.

Clean up your drive quickly with Run

How to clean Windows PC using Command Prompt Picture 2

You can use the Run command to perform a quick disk cleanup without opening the Command Prompt. It's useful if you want to free up a few gigabytes of storage in two steps. This requires you to start the Disk Cleanup tool and specify the drive you want to clean through the Run dialog box.

To run Disk Cleanup:

  1. Press Win + R to open Run.
  2. Enter the following command in the Run dialog box:
    C:windowsSYSTEM32cleanmgr.exe /dDrive
  3. In the above command, replace Drive with the drive letter you want to delete. For example, if you want to perform a quick cleanup of drive E , the full command would be as follows:
    C:windowsSYSTEM32cleanmgr.exe /dE
  4. Click OK or press Enter to execute the command.
  5. Run will quickly launch the Disk Cleanup tool with the drive you specify selected.
  6. Select the files to delete and click OK .

 

How to use Disk Cleanup utility through Command Prompt

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

You can use Command Prompt to launch Disk Cleanup and perform automatic cleanup tasks directly. Here's how to use the tool and what command line switches are supported.

Delete basic files

How to clean Windows PC using Command Prompt Picture 3

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

  1. Open Command Prompt, type cleanmgr and press Enter.
  2. In the Drive Selection window , select the drive you want to clean and click OK .
  3. In the Disk Cleanup window , select all the files you want to delete and click OK.
  4. Click Delete Files to confirm action.

Clean up a specific drive/partition

How to clean Windows PC using Command Prompt Picture 4

 

You can use the cleanmgr command followed by the drive letter to run the Disk Cleanup tool against that drive. This is useful for freeing up space on a specific drive. For example, use the following command to run the Disk Cleanup tool on drive C:

cleanmgr /D C

The Disk Cleanup tool will scan and display all the files you can delete. Make your selection and click OK .

Configure Disk Cleanup tool settings

To customize Disk Cleanup tool settings, the cleanmgr command supports multiple switches, including sageset and sagerun.

  1. sageset:x allows you to configure the settings of the Disk Cleanup tool. When executed, it launches the Disk Cleanup tool and allows you to select specific items you want to delete and assign them an x ​​value. The x value, which can be any value from 1 to 9999, is stored in the registry.
  2. sagerun:x runs the specified task assigned to the value x and automatically deletes all specified files.

Here's how it works:

1. Enter the following command into Command Prompt and press Enter :

cleanmgr /sageset:1

2. In the command above, replace 1 with any number from 1 to 9999 . This guide will use 1 . When executed, it will open the Disk Cleanup tool and display all the junk items that you can delete.

How to clean Windows PC using Command Prompt Picture 5

3. Select or deselect all the items you want to delete. For example, select temporary setup files, Windows Update Cleanup, downloaded program files, Recycle bin (be careful with this file), etc.

How to clean Windows PC using Command Prompt Picture 6

4. After selecting the file types to clean, click OK to save the configuration.

How to clean Windows PC using Command Prompt Picture 7

 

5. Now, use the following command to run the Disk Cleanup tool with your custom configuration:

cleanmgr /sagerun:1 

6. This will launch the Disk Cleanup tool and start cleaning the file types previously specified and assigned to the value 1. In this case, it will delete temporary setup files, Windows Update Cleanup, downloaded program files and Recycle bin files.

Optimized for low amount of space

The lowdisk switch , as the name suggests, is useful if you are running out of storage space on your hard drive. When executed, it will automatically check all file types.

The lowdisk command is followed by the drive letter for the partition to free up space. A complete command will look something like this:

cleanmgr /lowdisk /d

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

To delete all junk files quickly without user prompts, use the following command instead:

cleanmgr /verylowdisk /d

How to delete temporary files using Command Prompt

Windows creates temporary files for use. They rarely take up a large amount of space on your hard drive and are essential for the system to function smoothly. When the task is complete, your system will automatically remove them from the temporary folders.

The Disk Cleanup tool will clean up temporary files older than 7 days. But if you have to clean your temporary folder regularly, you can do it manually or use Command Prompt.

How to clean Windows PC using Command Prompt Picture 8

To view temporary files, enter the following command in Command Prompt:

%SystemRoot%explorer.exe %temp%

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

del %temp%*.* /s /q

Command Prompt will automatically skip any files that are 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 runs on your Windows system. These files contain information used to optimize program execution.

Like other temporary files, prefetch files usually don't take up much space on your hard drive. However, if you need to delete prefetch files regularly, you can use Command Prompt to clean up these files on your system.

To delete prefetched files using Command Prompt:

1. Open Command Prompt with admin rights.

2. In the Command Prompt window, type the following command to view prefetched files:

%SystemRoot%explorer.exe C:Windowsprefetch

3. The command will open the Prefetch folder in File Explorer and display prefetch files that you can delete.

How to clean Windows PC using Command Prompt Picture 9

 

4. To delete prefetched files, use the following command and press Enter :

del C:Windowsprefetch*.*/s/q

5. Command Prompt will display a list of all deleted prefetch files.

Wipe your hard drive with Diskpart

If you want to wipe the entire disk, you can use the diskpart utility. Diskpart is a Windows command line utility that supports more than 38 commands for various functions.

To wipe the drive, you can use diskpart's clean command. Once executed, it deletes all data and converts the drive to unallocated space.

How to clean Windows PC using Command Prompt Picture 10

Use caution when using the diskpart utility. Using incorrect objects can cause you to lose all your data, and you may not be able to recover any of it. Therefore, make a backup of your important system data before using the diskpart tool.

To erase a drive:

  1. Type diskpart in Command Prompt and press Enter.
  2. Next, type list disk to see all installed drives on your system
  3. Select the drive you want to wipe. For example:
    Select disk 0
  4. If the drive status shows offline, type online disk and press Enter .
  5. To wipe the drive, type the following command and press Enter :
    Clean all
  6. Once completed, type exit to close diskpart.
3.5 ★ | 2 Vote

May be interested

  • Windows promptWindows prompt
    the prompt command changes the command prompt cmd.exe file.
  • How to Create a Custom Windows Command PromptHow to Create a Custom Windows Command Prompt
    the windows command prompt (located at c:windowssystem32cmd.exe) is a useful tool to perform various administrative tasks. the prompt is a string of characters (special and non special) that are displayed whenever the command prompt is...
  • How to Open Folders in CMDHow to Open Folders in CMD
    do you need to access something from the command prompt or the windows command prompt? although it looks classic, this program is really easy to use if you know some basic commands. today's tipsmake will show you how to use the 'cd' command to open a folder in windows command prompt. besides, you will also know more great tips to instantly open command prompt in any folder on windows file explorer.
  • How to Execute a Program in Command PromptHow to Execute a Program in Command Prompt
    this article shows you how to open a program on a windows computer using the command prompt application. although you can only open programs that are installed in folders created by windows (such as desktop), you are still allowed to add the program's folder to the command prompt list to open the program with the command prompt.
  • How to Open Command Prompt on WindowsHow to Open Command Prompt on Windows
    today's tipsmake will show you how to open the command prompt program on windows. there are many ways to do it, from as simple as searching the start menu to using the run command. however, you should remember, some computers (such as school computers) cannot run command prompt due to restrictions.
  • How to fix the error of Command Prompt opening automatically on WindowsHow to fix the error of Command Prompt opening automatically on Windows
    it can be extremely annoying when the command prompt constantly interrupts what you're doing on your windows computer by randomly appearing.
  • How to change the folder in Command Prompt on Windows 10How to change the folder in Command Prompt on Windows 10
    one of the first things you need to learn when you become more familiar with the command prompt on windows 10 is how to change the folders in the file system of the operating system. the following article will guide you to implement them.
  • How to open Command Prompt during Windows installationHow to open Command Prompt during Windows installation
    opening command prompt while you install windows will help you use commands in cmd such as checking drive health, converting standard mbr - gpt and many other benefits,
  • How to Add and Delete User Accounts with Command Prompt on WindowsHow to Add and Delete User Accounts with Command Prompt on Windows
    command prompt is basically a version of the 'terminal' application (apple) on windows, a program that allows us to enter system adjustment commands. while most commands users enter into command prompt simply execute the action itself (such as opening a folder), you can also use command prompt to quickly create (or delete) accounts. right on your computer!
  • How to Change Directory in Command PromptHow to Change Directory in Command Prompt
    this article shows you how to change folders in the command prompt program on a windows computer. to change commands in command prompt, you must use an administrator account.