Key points:

The Command Prompt can be used to clear unnecessary files, temporary files, prefetch files, and cache, as well as defragment your hard drive.

The Command Prompt can be a little daunting for beginners, so read the instructions carefully to avoid losing data. You can also use the tool Partition Master Free Edition, which provides an easier alternative to the Command Prompt for defragmenting your hard drive, clearing your PC's cache, and analyzing your disk.

Cleaning your computer can improve performance and free up a lot of storage space. You can use the Command Prompt (CMD) to speed up your computer by following the steps in this article.

Why use CMD to clean up a computer?

While Windows has several built-in system-cleaning tools, like Disk Cleanup, using the Command Prompt is a lesser-known way to clean your computer.

Command Prompt is an in-built command processor that is compatible with Windows 11 and Windows 10/8/7/XP/Vista. While it requires typing commands, it offers advantages in terms of efficiency and performance for advanced users.

If you don't know how to run commands to clean your Windows 11, Windows 10/8/7 PC, follow the given guide to clean your computer that removes unnecessary files, temporary and prefetch files, cache data, fix hard drive errors, defragment the drive, and wipe the disk, etc.

Here are a few ways to clean up Calculator and improve Windows performance using the Command Prompt. If these guides were helpful to you, don't forget to share this article to help more people.

I'm sorry, it seems like you have entered a blank message. Please provide the English content you would like translated, and I'll be glad to assist you.

How do I clean my computer using the Command Prompt?

We'll show you how to use different commands in CMD to clean up various files. First, you need to open Command Prompt with administrator privileges.

To do so, follow these instructions:

    On Windows 10/11, type "cmd" into the search box. Select "Command Prompt," then click "Run as administrator" to open the CMD window.

Run as administrator

1. Run Disk Cleanup through CMD

Disk Cleanup is a built-in utility in Windows designed to scan and analyze your hard drive, helping you free up space on your computer's disk. It can clean up downloaded files, temporary files, the Recycle Bin, and even system files.

Guideline 1: Delete the Core Files

First, let's learn how to use the CMD (Command Prompt).

Begin a disk cleanup and delete essential files. You can initiate the Disk Cleanup tool through Command Prompt using the `cleanmgr` command. Here's how:

Step 1: Open the Command Prompt, type cleanmgr, and press Enter.

Step 2: In the Disk Selection screen, choose the disk you want to clean up and click OK.

Step 3: Check all the files you want to delete in Disk Cleanup, and then click “OK.” Click “Delete Files” to confirm.

Run Disk Cleanup Run Disk Cleanup

Tip 2: Clean up a specific drive

You can run Disk Cleanup on a specific drive by entering the cleanmgr command followed by the letter of the drive you want to clean. This is useful for freeing up space on a particular drive. For example, you could run the following command to clean the C: drive:

This is the command to clean up the disk, indicating to clean up drive C:. When entered in the Command Prompt, it runs the Disk Cleanup tool and deletes temporary files, system files, and other optional files from drive C: to free up disk space.

Disk Cleanup will scan and show you all the files that can be deleted from the C: drive. Check them, then click OK to delete the files.

Guideline 3: Configure disk cleanup settings

The Disk Cleanup command offers several specialized parameters for specific functions. You can customize the Disk Cleanup utility settings.

  1. ✔️Cleanmgr /sageset
  2. This command launches the Disk Cleanup Wizard with advanced settings. Upon executing this command, a dialog box appears that allows users to select the file types and system components to be deleted, thus customizing the disk cleanup process. The "/sageset" parameter saves the user's preferences, enabling quick access to these settings in the future.

This will skip the drive selection and take you straight to the “Disk Cleanup Settings” window, where you can choose what you want Disk Cleanup to automatically clean up when it runs on a schedule.

    In American English, this would be: "✔️Run Disk Cleanup with the 'Sagerun' parameter"

This command will run the disk cleanup process automatically, without any category selection.

  1. ✔️Cleanmgr /lowdisk
  2. This command runs the Disk Cleanup tool and specifies that it should run when disk space is low. When entered in the Command Prompt, this command will automatically search for and delete unnecessary files to free up disk space.

Use this command when running low on disk space. By default, Disk Cleanup will open with all the check boxes selected.

2. Delete Temporary Files Using CMD

Windows creates temporary files for use while it's running. They don't take up too much space, but they're important for your system to run smoothly. If you need to clear out the Temp folder often, you can do so from the Command Prompt.

Temporary files created by the Windows operating system are stored in the path %system%\windows\temp. User-created temporary files are stored in C:\Users\username\AppData\Local\Temp.

Run this command – %SystemRoot%\explorer.exe %temp%\ to open the "Temp" folder in File Explorer. Then, press Ctrl + A to select all files and delete them. Alternatively, run the command – del %temp%\*.* /s /q to erase these temporary files. CMD will automatically skip files that are currently in use but will remove the rest of the temporary files.

Delete temporary files

How to delete temp files using Command Prompt? In this section, you must have found the detailed guide. Please share this article to let more users know about it.

I'm sorry, it seems like you have entered a blank message. Please provide the English content you would like me to translate, and I'll be glad to assist you.

3. Delete Prefetch Files Using CMD

Prefetch files are temporary files generated by the Windows operating system while applications are running. These files contain information that optimizes program execution, such as how often a software is run, the time it takes to run, and the associated files it uses. This allows the system to load and execute the same application more quickly the next time it is launched.

Like other temporary files, they usually don't take up too much space on your hard drive. But if you do need to clear the prefetch files in Windows 10 or Windows 11, follow these steps:

Step 1: Open the Command Prompt on Windows with administrator privileges.

Step 2: Type %SystemRoot%\explorer.exe C:\Windows\Prefetch in the Command Prompt window and press Enter. This will open the Prefetch folder in File Explorer.

Delete the Prefetch folder: Delete the Prefetch folder

Step 3: You can delete the Prefetch folder directly through Explorer, or you can do it from the Command Prompt.

Type del C:\Windows\Prefetch\*.* /s /q and press Enter to delete these Prefetch files.

"Using CMD to defragment the hard drive"

One effective way to clean your computer using CMD is by defragmenting the disk. While fragmentation on a hard drive naturally occurs, it can lead to performance issues, such as slower access and write speeds or a sluggish system. Here's how you can defragment your hard drive using CMD: 1. **Open Command Prompt as an Administrator:** - Press `Win + X` on your keyboard and choose "Command Prompt (Admin)" from the menu that appears. 2. **Type the following command and press Enter:** ``` defrag C: /f /x /v ``` This command will defragment the C: drive, force the defragmentation process (`/f`), delete temporary files (`/x`), and display detailed information (`/v`). 3. **Wait for the Process to Finish:** Defragmentation may take some time, depending on the size of your hard drive and the level of fragmentation. Be patient and let the process complete. 4. **Check the Results:** Once finished, CMD will display a report showing the defragmentation results. If your disk is already well-optimized, it might say that the volume is already defragmented. 5. **Repeat for Other Drives (Optional):** If you have other drives you want to defragment, replace `C:` in the command with the respective drive letter (e.g., `D:`, `E:`). Remember that modern SSDs don't typically require defragmentation, as they work differently from traditional HDDs. However, if you're using an HDD, regular defragmentation can help maintain its performance.

Step 1: Run Command Prompt as an administrator.

Step 2: Type defrag c: into the CMD window, and press Enter. Replace c: with the letter of the drive you want to defragment.

Defragment C drive

These commands are applicable only to HDDs. If you use an SSD, turn to a reliable SSD Optimizer to boost its performance.

5. Clear the cache in the Windows Command Prompt

Cache files can significantly improve performance, availability, and scalability, enabling faster data delivery and quicker response times. However, if there are errors in the cached files, it can lead to data retrieval issues or even crashes. Regularly clearing cache files can prevent or resolve this problem.

    • Clear the DNS cache by running the following command in the CMD window: **ipconfig/flushDNS** • Clear the Windows Store cache by executing the following command: **wsreset.exe**

Aside from being a reliable disk partition manager, AOMEI Partition Assistant also works as a decent free PC cache cleaner. You can install it on your computer as an alternative if you're not familiar with the Command Prompt.

6. Erase the entire disk

To delete a disk entirely, you can launch Diskpart from the CMD. Diskpart is a command-line disk utility that is compatible with Windows 2000 and later, and it's the successor to fdisk. By using the Diskpart commands, you can manage disks and partitions by creating, deleting, and erasing entire disks.

Before using CMD to wipe the entire disk, make sure to back up important data.

Here's how to clean your hard drive and wipe the entire disk using Command Prompt:

Step 1: Type diskpart in the CMD window and hit Enter to proceed.

Step 2: Type list disk and press Enter. This will display all the hard drives installed on your computer.

Step 3: Type select disk n, where n is the number of the disk.

Note If the disk status is Offline, type online disk, and then press Enter.

Step 4: Type clean all or just clean, and press Enter to erase the hard drive.

Clean up or clean up all

Along the way, you may encounter the “No fixed disks to show in disk management” error; click the link to learn the fix.

While the Command Prompt allows you to use different commands to clean up various junk files on your computer, not all users are comfortable using this tool. There are various files to clean, and the CMD needs to be familiar with all the above commands, which can be challenging for beginners. Therefore, we recommend that novices use tools like Disk Master to clean their PCs.

A Simpler Way to Clean Up Your Windows PC

To avoid data loss due to incorrect commands and simplify the disk cleanup process, we recommend using the Partition Master tool. It is a disk and computer space optimization manager for Windows 11/10/8.1/7/XP computers.

It can replace CMD for disk and computer cleaning in the following ways:

    • ✔️ Wipe Disk: Restores the disk to its original state when it was newly purchased. • ✔️ Extend Volume on Low Disk Space: It allows you to extend the target drive, such as the C drive, when facing low disk space issues, like expanding from unallocated space on Drive D or any other disk. • ✔️ Clean Cache: Its "Clean Genius" feature searches and deletes all caches on your Windows PC. • ✔️ Analyze Disk Space: The Partition Master tool can analyze your disk, locate large files occupying significant disk space, and delete them with a single click.

Here, I will show you how to analyze disk space and clean up your computer:

Step 1: Launch AOMEI Partition Assistant and then navigate to the "Discovery" tab. Under "Common Tools", find and download "Space Analyzer".

Download Space Analyzer

Step 2: In the Space Analyzer window, select the target disk that you wish to analyze, and then click the “Analyze” button located on the top-right corner.

Click “Analyze Disk Space.”

Step 3: Wait for a moment, and you will see the detailed data. You can click on Folders/files to view different types of data, then click the small folder icon to view more information inside the file.

View detailed data

Then, click the folder icon to delete large files that are taking up disk space.

Editor's Note

While using CMD to clean your computer requires knowledge of many commands and familiarity with the Command Prompt, the Partition Master tool allows you to completely wipe all junk files from Windows without having to input complex commands.

If you want to make computer cleaning easier, you can't miss this tool.

FAQs on Running Commands to Clean Your PC

With these solutions, we hope that your computer is now running more smoothly. If you have further issues, feel free to continue reading.

How do I start the Disk Cleanup utility from the command line?

To start Disk Cleanup from the command line and specify the drive to clean, follow these steps:

    1. Click Start, and then click Run. 2. In the Open box, type the following command, and then press Enter: c:\windows\SYSTEM32\cleanmgr.exe /d Drive 3. Note In this command, the placeholder Drive represents the letter of the hard disk drive that you want to clean up.

**How can I use the Command Prompt to clean my computer?** In the Windows operating system, you can utilize the Command Prompt (CMD) to perform some basic cleanup tasks. Here are some common commands: 1. **Cleaning temporary files:** - Open Command Prompt: Press `Win + X` and then select `Command Prompt (Admin)`. - Type the following command and press Enter: ``` cleanmgr /sageset:64 ``` - This will open the "Disk Cleanup" dialog, where you can choose file types to delete. Select the options you want to clean and click OK. - To clean automatically, type: ``` cleanmgr /sagerun:64 ``` 2. **Cleaning log files:** - In Command Prompt, enter: ``` del /f /s /q %windir%\logs\*.* ``` - This will delete all files in the Windows log folder. Exercise caution as this might remove important information. 3. **Cleaning a specific folder:** - For instance, to clean the Downloads folder, type: ``` rd /s /q %USERPROFILE%\Downloads ``` - Note that this will delete everything within the folder, so ensure you don't need the files. 4. **Defragmenting the disk (for HDDs, not SSDs):** - Type: ``` defrag C: /h /u /x ``` - This will defragment the C: drive. Replace "C:" with the letter of the drive you want to defragment. Use these commands carefully, as they can permanently delete data. It's recommended to back up important files before running any cleanup commands.

To speed up your computer using CMD, type "cmd" in the Windows search bar, right-click on "Command Prompt," and select "Run as administrator." Enter cleanmgr and hit Enter. In the "Drive Selection" window, choose the drive you want to clean and then click OK.

3. How to Speed Up Your Computer Using the Command Prompt? You can use the Command Prompt (CMD) to execute commands that can enhance your computer's performance. Here are some basic steps: 1. **Open Command Prompt**: - Press `Win + R` to open the "Run" dialog box. - Type `cmd` or `cmd.exe`, then hit `Enter`. 2. **Clean Temporary Files**: - In the command prompt, type `cleanmgr /sageset:1` and press `Enter`. This will open the Disk Cleanup settings window. - Select the file types you want to clean up and click "OK". - Next, type `cleanmgr /sagerun:1` and press `Enter` to run Disk Cleanup. 3. **Disable Unnecessary Startup Programs**: - Enter `msconfig` and press `Enter` to open the "System Configuration" window. - Go to the "Startup" tab and uncheck unnecessary startup items. - Click "Apply" and "OK", then restart your computer. 4. **Update Drivers**: - In the command prompt, type `devmgmt.msc` and press `Enter` to open Device Manager. - Update outdated drivers. 5. **Defragment the Hard Drive** (not applicable for SSDs): - Type `defrag C: /optimize` (replace `C:` with the drive letter you want to optimize), then press `Enter`. 6. **Flush DNS Cache**: - Type `ipconfig /flushdns` and press `Enter`. 7. **Disable Visual Effects**: - Type `regedit` and press `Enter` to open Registry Editor. - Navigate to `HKEY_CURRENT_USER\Control Panel\Desktop`. - Create or modify the `WindowArrangementActive` value to `0`. - Exit the Registry Editor and restart your computer. Please note that modifying the registry can impact system stability, so it's recommended to back up important data beforehand. If unsure, consult a professional for assistance.

To speed up your computer using CMD, follow these steps:

    1. To open the Command Prompt, press Win + R, type "cmd," and then hit Enter. 2. Type `powercfg -list` and press Enter. You should see three power plans: High Performance, Power Saver, and Balanced. An asterisk (*) indicates the active plan. 3. Copy the code for the High Performance power plan. 4. Next, input the following command: `powercfg -setactive CODE`, replacing "CODE" with the value you copied. 5. Finally, use `powercfg -list` again to view the current power plan. The High Performance plan should now have an asterisk next to it, indicating it's active.

**4. What is the 'clean' command in CMD?** In CMD (Command Prompt), there isn't a specific 'clean' command. However, the concept of 'clean' is used in certain development environments or build tools. For instance, in a Git repository, you can use the `git clean` command to remove untracked files. In integrated development environments like Visual Studio, a "clean" operation is typically used to delete generated intermediate and output files, preparing the project for a fresh build. The specific command you would use depends on the tool and context you are working with.

Clean is a command-line utility used to sanitize an entire disk and restore it to its initial state. Sanitizing or erasing a storage device removes all data and partitions from the hard drive.