Cleansing Your Hard Drive With Cmd: A Comprehensive Guide

how to clear a hard drive with cmd

There are several ways to clear a hard drive using Command Prompt, also known as cmd.exe or cmd. These methods can be used to wipe a specific drive or partition, or an entire disk.

Before proceeding, it is important to back up any important data on the drive as these processes will result in permanent data loss.

To get started, open Command Prompt by pressing Windows + S, typing cmd in the search box, and selecting Run as administrator.

Characteristics Values
Operating System Windows 11/10/8/7
Command diskpart
Command list disk
Command select disk # (replace # with the specific number of your targeted disk)
Command clean
Command clean all
Command format f: /fs:NTFS /p:1
Command create partition primary
Command select partition 1
Command format fs=ntfs quick
Command format fs=fat32 quick
Command assign drive letter=G
Command active
Command exit

shunclean

Delete all partitions

The DiskPart Clean Command will delete all partitions at once, quickly cleaning the drive data. However, the deleted partitions and data are recoverable. To use this command:

  • Press Windows + R keys to open the search menu, type cmd, right-click Command Prompt and select Run as Administrator.
  • Click Yes to let Windows run Command Prompt in Admin mode.
  • Type `diskpart` and hit Enter.
  • Type the following command lines one by one and hit Enter each time:

`select disk # (Replace # with the number of your target disk.)

Type `exit` to close the DiskPart command window when the cleaning process completes.

The DiskPart Clean All Command will delete all partitions and wipe the hard drive at once, erasing and resetting the hard drive. The deleted partitions and data are permanently erased and unrecoverable. To use this command:

  • Open DiskPart by pressing Windows + R keys, type cmd, and right-click Command Prompt.
  • Click Run as Administrator and type `diskpart`, then hit Enter.
  • Click Yes to allow DiskPart to run on Windows as Admin.
  • Type the following command lines and hit Enter each time:

`select disk 1 (Replace 1 with the disk number that you want to wipe.)

When the process completes, type `exit` to close the DiskPart window.

Now your drive is reset as a new disk, and all your data is gone.

shunclean

Wipe the disk

To wipe a disk using CMD, you need to use the diskpart utility. This is a command-line utility that has been included in Windows since the Windows 2000 operating system.

Important: Before proceeding, it is critical that you back up any important data on the drive. The wiping process will delete all data on the disk.

To wipe a disk using diskpart:

  • Open an elevated command prompt. To do this, click on the Start menu and type "cmd" in the search bar. Then right-click on "cmd.exe" or "Command Prompt" and select "Run as administrator". Click "Yes" on the prompt.
  • Once the Command Prompt window is open, type "diskpart" and press Enter.
  • Type "list disk" and press Enter. This will display a list of all the disks on your system.
  • Type "select disk #" and press Enter. Replace "#" with the number of the disk you want to wipe. For example, if you want to wipe Disk 2, type "select disk 2" and press Enter.
  • Type "clean all" and press Enter. This command will delete all data, partitions, and folders from the selected disk. This process may take a long time, depending on the size of the disk.
  • Once the process is complete, type "exit" and press Enter to close the Command Prompt window.

Note: The "clean all" command will completely wipe the disk and make data recovery challenging, but not impossible. If you want to ensure that data cannot be recovered, you may need to use a third-party disk wiping tool or perform multiple passes of writing zeros to the disk.

shunclean

Defragment hard disk

Defragmentation is the process of reducing the degree of fragmentation of a storage device to improve its performance. This process organises the contents of the mass storage device and stores the files in the smallest number of contiguous regions. It also uses compaction to release more free space for the disk.

To defragment a hard disk on Windows using the Command Prompt, follow these steps:

  • Click the Start Button and type 'cmd.exe' into the search box.
  • Right-click on 'cmd.exe' and select 'Run as Administrator'.
  • In the window that pops up, type 'defrag [drive name] [parameter] [extra parameters]'. For example, to defragment your main C drive, type 'defrag C:'.
  • You can also add specific parameters to the command. For instance, to force a defrag with less than 15% free space, add '-f' to the command.
  • Wait for the defragmentation to complete. This will take some time depending on the size and fragmentation of your disk.

Note: It is recommended to have at least 15% free space on the disk partition to complete a full defragment. If your disk has less than 15% free space, only a partial defragment will be performed.

Additionally, Solid State Drives (SSDs) do not need to be defragmented. Defragmenting an SSD can decrease its performance and even reduce its lifespan.

shunclean

Delete temporary files

Temporary files are created by your Windows operating system and the applications running on your computer. They are used for several reasons, including providing space for virtual memory and storing data while a program is running.

Over time, temporary files can take up a lot of storage space and slow down your computer. Here are some methods to delete temporary files using the Command Prompt:

Using the Command Prompt

  • Press the Windows key + S simultaneously.
  • Type "cmd" or "command prompt" and select "Run as administrator".
  • Type or paste the command `del /q/f/s %TEMP%\*` into the dialogue box and press Enter.

If you see messages stating that certain files are being used by another process, reboot in Safe Mode and refer to guidance on removing temporary files that cannot otherwise be deleted.

Using Disk Cleanup

  • Press the Windows key + S simultaneously.
  • Type "disk cleanup" and press Enter.
  • Click "Run as administrator".
  • If prompted, select the drive you want to search for temporary files to clean and click OK.
  • Review the description for each file type and select or deselect them as needed, then click OK.

Using the Temporary Files Menu

  • Open the Windows Start menu and select Settings.
  • Ensure "System" is selected and choose "Storage".
  • Click "Temporary Files".
  • Choose the temporary file types you want to delete, then click "Remove Files".

Be careful not to delete the Downloads folder if you are actively using those files. All other folders are safe to delete.

Other Methods to Remove Temporary Files

You can also delete temporary files by cleaning your browser, or by using third-party software such as Avast Cleanup or Cleaner One Pro.

shunclean

Delete prefetch files

Prefetch files are created by the Windows operating system each time an app is launched for the first time. They are designed to make apps open faster and don't usually take up much space on your hard drive. However, if you're running low on disk space, you can delete them without causing any problems.

Step 1: Open Command Prompt with Admin Privileges

  • In Windows 10/11, type "cmd" into the search box.
  • Right-click on "Command Prompt" and select "Run as administrator" from the popup to open the CMD window.

Step 2: View Prefetch Files

  • Type "%SystemRoot%\explorer.exe C:\Windows\prefetch\ " into the Command Prompt window and press Enter.
  • This will open the Prefetch folder in File Explorer, allowing you to see the prefetch files.

Step 3: Delete Prefetch Files

  • To delete the prefetch files, use the command: "del C:\Windows\prefetch\./s/q"
  • Hit Enter to execute the command.
  • This will delete all the prefetch files in the folder.

Alternatively, you can delete the prefetch files without using Command Prompt by following these steps:

Step 1: Open the Run Dialog

  • Press the Windows key + R to open the Run dialog.
  • You can also type "run" into the Windows search bar and click "Run" in the results.

Step 2: Open the Prefetch Folder

  • Type "prefetch" into the "Run" box and press Enter.
  • This will open the Prefetch folder in File Explorer.

Step 3: Display Hidden Files and Folders

  • If the folder appears empty or you get an error, click on the "View" tab in the File Explorer.
  • Click on Options near the top-right corner and select the View tab in the Folder Options window.
  • Select "Show hidden files, folders, and drives" and click "OK".

Step 4: Select and Delete Prefetch Files

  • Press Ctrl + A to select all the prefetch files in the folder.
  • Press the Delete key to remove the selected files.

Deleting prefetch files is generally safe and will not harm your system. However, it is recommended to delete them only when necessary, as they help improve the loading speed of your applications.

Frequently asked questions

To open Command Prompt, press the Windows + S keys and type "cmd" in the search box. Then, locate Command Prompt, right-click, and select "Run as administrator".

You can use the cleanmgr command followed by a drive letter to run the Disk Cleanup tool against that drive. For example, to run the Disk Cleanup tool against the C drive, you can use the following command: cleanmgr /lowdisk /d.

You can use the diskpart utility and its clean command to wipe an entire disk. This will delete all the data and convert the disk into unallocated space. Here are the steps:

Type diskpart and press Enter.

Select the disk you want to wipe by typing "select disk n" (where n is the disk number).

Written by
Reviewed by
Share this post
Print
Did this article help you?

Leave a comment