How To Clean Hard Disk Using Command Prompt
Microsoft Windows commonly referred to as windows are one of, if not the most popular operating systems for personal and business computers. No doubt you will be able to work on a massive amount of features on your PC.
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 particularly look at how you canclean computer using cmd (command prompt).
- Type "cmd" onwindows search bar /run the dialog box.
- Right click on Command Prompt.
- Select Run as administrator.
- You will arrive at the command prompt window –

Tip: When you run cmd.exe as an administrator you will have elevated permission with your commands and they will be operated from thesystem32directory else as the currently logged-in user.
Heading to the cleaning commands you have several commands to clean your PC when it comes to clean 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 all 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 about 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, possible conflicts, 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.
What is the Command Prompt?
Cmd is a default command-line interpreter for the operating system such as windows, Linux, ArcaOS, eComStation, etc. Command Prompts is a text-based interface within the operating system. It offers easy access to any directory or file manually. It is used to solve troubleshoot issues and any kind of windows issues. Some command prompts also work as disk cleanup managers.
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 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
Cleanmgris a disk cleanup command line to clean junk. Follow these steps to use this command.
- Cleanmgris 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 onOKto 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 thatCleanmgraccepts. 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;
cleanmgr/ sageset: numeric_id
for example:
c:\Windows\system32> cleanmgr/ sageset: 1
1.3 Cleanmgr/ sagerun
This command will automate the disk-cleaning process without selecting the categories you need to use thesageruncommand.
The format of running the sagerun command is;
cleanmgr/ sagerun: id
for example:
c:\Windows\system32> cleanmgr/ sagerun: 1
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 thelowdiskcommand is;
cleanmgr/lowdisk/d{driver-latter of your disk}
for example:
c:\Windows\system32> cleanmgr/lowdisk/dc {for c drive} c:\Windows\system32> cleanmgr/lowdisk/dd {for d drive}
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 the 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 them else than losing 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 inC:\Users\username\AppData\Local\Temp.
To viewtempfiles using command prompt use:
%SystemRoot%\explorer.exe %temp%\
And the command to deletetempfiles (you can manually delete them too from the directory):
del %temp%\*.*/s/q

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 work as 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):
%SystemRoot%\explorer.exe C:\Windows\prefetch\
And then delete the files from the prefetch folder;
del C:\Windows\prefetch\*.*/s/q

Similar content: Tutorial to Remove Virus Using CMD in 4 Steps
4. Clear cache memory in windows
Cache files are useful 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 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.
- Search for the command prompt on the windows search bar.
- Right-click on the command prompt and selectRun as administrator.
- Next in the command prompt run this command –
ipconfig/flushDNS
You will receive a message that lets you know the DNS cache is successfully flushed.
And toclear windows store cache memory, you will need to use theWSResetcommand in the cmd. Doing so will display a black screen like the image below and all you need to wait until the windows disappear to be sure that windows store memory 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. By reordering the files it can allow your PC to access files faster from the hard disk.
Disk fragmentation is a natural occurrence on traditional hard disks, although, 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;
- Start the command prompt as administrator.
- Use defrag {preferred drive's drive later}: defrag c:
Note that, c: in the defrag c: command is the drive letter i.e 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
Diskpartis a command-line disk partitioning utility that is available in Windows 2000 and later editions. PreviouslyFdiskcommand was used for this task. You can use thediskpartcommand 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;
- Start the command prompt as administrator.
- Typediskpartcommand and press enter.
- Following thediskparttype "list disk" in cmd.
- It will display all connected disks to your computer along with their availability status.
- The typeselect disk n{for example: select disk 0}
- ** if the disk status is offline, type "online disk" and press enter.
- Then type "clean" or "clean all" according to your need.
- On success, you will see the "diskpart succeeded in cleaning the disk" message.
Cleancommand will only clean data on HDD and will be marked as deleted. However, theclean all command will delete every byte of data from the disk, and later you won't be able to recover that data.

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 asDISM(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 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.
DISM /online /Cleanup-Image /checkhealth

And to scan the windows image use this command;
DISM /Online /Cleanup-Image /ScanHealth

To fix the windows images, If you find any corrupted files use this command;
DISM /Online /Cleanup-Image /RestoreHealth /Source:repairSource\install.wim
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:
10 Unique iPhone 11 Tips and Tricks You Must Try
Top 5 Free Noise Cancellation Software You Must Try
Top 10 Best RPG games for android you must try
How to remove virus using cmd [with pictures]
How To Clean Hard Disk Using Command Prompt
Source: https://gamespec.tech/how-to-clean-computer-using-cmd/
Posted by: millerbeftelf1970.blogspot.com
0 Response to "How To Clean Hard Disk Using Command Prompt"
Post a Comment