With a lot of background tasks going on, PC memory needs to be cleaned up from time to time. Windows operating system allows you to clean your PC memory in many different ways. You can use third-party software to flash temporary files on HDD, or you can use windows inbuilt disk cleanup facilities on the command prompt. In this post, we will mainly look at how you can clean computer using cmd (command prompt).  Tip: When you run cmd.exe as an administrator, you will have elevated permission with your commands,, which will be operated from the system32 directory as the currently logged-in user. Heading to the cleaning commands, you have several commands to clean your PC when it comes to cleaning your hard disk or cache memory. To flash remaining unwanted files, you will be able to clean them manually by clearing your temp folder. You can boost the cleaning process by accessing Disk Defragmenter, diskpart, and the Disk Cleanup tool with commands. Later in this post, you will find the list of commands to clear different parts of your PC memory and the steps to execute it.

Why Clean Up Your Computer Using Command Prompt?

It’s obvious that the GUI applications are effortless to use. But using a Windows command processor is fun and really powerful. If you are among those, who do not fancy loading additional tools on their PC memory and stick to the command prompt for its efficiency & performance benefits, then this guide covers it all. Cleaning your PC memory is as important as cleaning up the hardware. While running programs, your computer generates temporary files which become unnecessary after use. Though these files are tiny, the collection of such files can cover many Gigabytes and thus has to be cleared often. Clean hardware helps your PC to run smoothly and extend the PC’s lifespan, whereas software & memory cleanup saves your applications from crashing, and possible conflicts, and provides better memory performance. Cleaning a disk can keep your PC fresh and terminate the possibility of lagging or slowing down. With powerful hardware nowadays, it won’t trouble you but flushing unwanted files from a hard disk is a good idea. 

Commands to clean computer using Command Prompt

The following part of this post contains the list of commands you can use to clean a computer using cmd. Before using these commands, make sure to understand what they do and only perform them if necessary. 

1. Clean unwanted files using Cleanmgr command class

This class of commands allows you to clean unwanted files and free up disk space on a computer’s hard drive. It will first analyze the files on your computer that are no longer of any use, then remove those files. It has sub-commands dedicated to specific functions. 1.1 Cleanmgr Cleanmgr is a disk cleanup command line to clean junk. Follow these steps to use this command.

Cleanmgr is a disk cleanup command line to clean junk.To use it, open the command prompt and type “Cleanmgr.”A small window will appear where you have to select the drive to clean. Click on OK to ask your system to analyze the drive and find out removable junks.Check which files you want to delete and press the OK button to execute.

If you want to automate the disk cleanup task, then there are three command-line switches that Cleanmgr accepts. They are /sageset, /sagerun and /lowdisk. 1.2 Cleanmgr/sageset This command will skip the disk selection step and take you straight to the category selection menu, where you need to check which category of junk files you want to clean. The format of running the sageset command is; for example: 1.3 Cleanmgr/ sagerun This command will automate the disk-cleaning process without selecting the categories you need to use the sagerun command.  The format of running the sagerun command is; for example: 1.4 Cleanmgr/lowdisk This command is used when the disk drive is running in low disk space. When this switch is run, the disk cleanup opens checked with all checkboxes by default. The format of running the lowdisk command is; for example: Tip: these commands work on server 2003, server 2008, Windows XP, Vista, Windows 7, 8, and Windows 10.

2. Clean temporary files using cleanup command

Temporary files are referred to as Temp. These files store info for a transient period during the execution of an application, as well as they can be created for backup purposes. Primarily they are used to store, move data and recover lost data.  It is safe to delete temporary files if and only if they are not being used by any application. Usually, Windows will prevent you from deleting these files during run time can result in application task failure. The temporary files(Temp) created by OS are stored in %system%/windows/temp while temporary files (%Temp%) created by the users are stored in C:\Users\username\AppData\Local\Temp. To view temp files using command prompt use:  And the command to delete temp files (you can manually delete them too from the directory):

3. Clean prefetch files using command prompt

Windows creates all sorts of temporary files on your hard drive. Prefetch files are created by the operating system when an application is used for the first time and later works as a cache. They may cover lots of space based on how the application tends to use the dedicated file. Prefetch is basically to make the app faster, but if you are facing app bugs or lags, you can delete these files. To check the prefetch files on your computer simply check in the prefetch folder, like this (on cmd): And then delete the files from the prefetch folder; Similar content: Tutorial to Remove Virus Using CMD in 4 Steps

4. Clear cache memory in windows

Cache files are helpful for application performance, but, If there’s something wrong with cache files, it can cause data fetching issues, glitches, or even crash. That’s why a common remedy is to clear application cache memory from time to time. You can delete the DNS cache, Windows store cache from your PC without any hesitation. If there’s an issue with deleting these cache files, windows will notify you. To flush the DNS cache, start command prompt as administrator.  You will receive a message that lets you know the DNS cache is successfully flushed. And to clear windows store cache memory, you will need to use the WSReset command in the cmd. Doing so will display a black screen like the image below, and all you need to do is wait until the windows disappear to be sure that windows store memory is successfully flushed.

5. Defragment your hard disk with command prompt

Another part of cleaning computer memory is defragmenting your disks. Defragmenting is the process of reorganizing the data stored in a hard drive. It is a process that reduces the degree of fragmentation by physically organizing the content of mass storage into the smallest number of adjacent regions. Reordering the files will allow your PC to access files faster from the hard disk. Disk fragmentation is a natural occurrence on traditional hard disks, although it is vulnerable to PC performance. Basically, fragments affect the writing and accessing speed of your HDD, resulting in sluggish system performance. To defragment your hard drive using cmd; Note that c: in the defrag c: command is the drive letter that means the drive you want to defrag. Change the drive letter if you want to defrag another drive.

7. Use Diskpart command to erase data from HDD

Diskpart is a command-line disk partitioning utility that is available in Windows 2000 and later editions. Previously Fdisk command was used for this task. You can use the diskpart command line to clean your disk along with specific switches like “clean” & “clean all” to erase data from the hard drive.  To clean hard drives with the diskpart command follow the steps below; Clean command will only clean data on HDD and will be marked as deleted. However, the clean all command will delete every byte of data from the disk, and later you won’t be able to recover that data. 👉🏽  Related article: Best Ryzen 5 5600H Laptops Under 85k INR (November 2021)

8. DISM Windows image cleanup

If you are having trouble with the current operating system, then you can repair the issue with OS. It’s an image cleaning task that will restore the operating system’s health to its ideal state. The command line you will use here is known as DISM (deployment image servicing and management), which is a built-in command line used to manage windows image (.wim) and virtual hard disk (.vhd). It is also used in the windows recovery environment and windows setup process, as well as in updating the operating system. To check if there is any corruption, follow the steps below; Start cmd with admin privilege. Start cmd with admin privilege > Type this command. And to scan the windows image use this command; To fix the windows images, If you find any corrupted files use this command; You can scan your PC for malware/viruses using the command prompt. The scanning process will be performed by Windows defender. Wrapping up: A command prompt is a powerful tool; you can it for many other purposes on your PC. If you have more info regarding PC clean commands, let us know in the comment below. Similar articles: