Sanitizing Your Usb Drive: A Guide To Using Cmd Prompt For A Thorough Clean

how to clean a usb drive in cmd prompt

If your USB flash drive is old, corrupted, or infected with a virus, you may want to clean it. Cleaning a USB drive can also help free up space and prevent unexpected information disclosure before throwing it away. One way to do this is by using the Command Prompt (CMD) on Windows.

Before you begin, make sure you have backed up any important files, as this process will completely wipe your USB drive.

First, plug your USB drive into your computer. Then, open Command Prompt as an administrator. Type diskpart and press Enter. Next, type list disk and press Enter to see a list of all the disks connected to your computer. Identify your USB drive from the list, then type select disk [Your disk number] and press Enter.

Finally, type clean and press Enter to start the cleaning process. Once the process is complete, you can close the Command Prompt window.

Characteristics Values
Step 1 Plug your USB drive into your computer
Step 2 Open Command Prompt as an administrator
Step 3 Type "diskpart" and press Enter
Step 4 Type "list disk" and press Enter
Step 5 Type "select disk [Your disk]" and press Enter
Step 6 Type "clean" and press Enter
Step 7 Type "create partition primary" and press Enter
Step 8 Type "format fs=ntfs" and press Enter
Step 9 Type "exit" and press Enter

shunclean

Launch Command Prompt as Administrator

To launch Command Prompt as an administrator, you can follow these steps:

For Windows 10 or 8.1:

Right-click the Start button (or press Windows Key + X) and select "Command Prompt (Admin)". If you see PowerShell instead of Command Prompt, you can switch back or give PowerShell a try, as it can do everything Command Prompt can and more.

For Windows 7:

Open the Start menu and search for "cmd". Right-click the "Command Prompt" shortcut that appears and then choose "Run as Administrator."

For Windows Vista or Windows 7:

Click on Start and type "cmd" in the search bar. Then right-click on "cmd.exe" and run as administrator. It will prompt you with a message asking if you want to allow the program to make changes to your computer; click yes.

For Windows 8:

Move your mouse to the bottom left-hand corner of the desktop screen and right-click. Select "Command Prompt (Admin)" from the pop-up menu.

Alternative method:

Open Windows Explorer and navigate to the following directory to find Command Prompt shortcut: C:\Users\YourUserName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories.

C is your Windows drive and YourUserName is your user account name).

Right-click on the Command Prompt shortcut, click Properties, switch to the Shortcut tab, click on Advanced, check "Run as administrator", and then click OK and Apply.

Another alternative method:

  • Open your Windows drive and navigate to the following directory: C:\Users\YourUserName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories.
  • Delete the Command Prompt shortcut from this directory.
  • Open your Windows drive, navigate to the Windows\System32 folder, locate the "cmd.exe" file, right-click on it, click "Send to", and then click "Desktop (Create Shortcut)".
  • Now, right-click on the Command Prompt on the desktop and select Properties. Switch to the Shortcut tab, click on Advanced, check "Run as administrator", click OK, and then Apply.
  • Finally, move the newly created shortcut to: C:\Users\YourUserName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories.

shunclean

Use diskpart to clean the disk

The diskpart command is a useful tool for cleaning a USB drive. It can be used to fix various logical issues with a storage drive, such as data corruption. It is also a good option when other methods, such as formatting the drive, do not work.

  • Launch a Command Prompt as Administrator: On Windows 10 or 8.1, right-click the Start button and select "Command Prompt (Admin)". For Windows 7, open the Start menu, search for "cmd", right-click on "Command Prompt", and choose "Run as Administrator".
  • Type "diskpart" and press Enter: This will launch the diskpart tool.
  • List the disks: Type "list disk" and press Enter to see all the disks connected to your computer. Identify the number of the disk you want to clean. Be very careful to select the correct disk, as you could accidentally wipe the wrong one and lose important data.
  • Select the disk: Type "select disk #" and press Enter. Replace "#" with the number of the disk you identified in the previous step.
  • Clean the disk: Type "clean" and press Enter. This will completely wipe the selected disk's partition table. Again, be absolutely sure that you have the right disk selected, as this action cannot be undone.
  • (Optional) Convert the partition style: If needed, you can convert the partition style using the "convert" command. For example, to convert to an MBR partition style, type "convert mbr" and press Enter.
  • Create a new partition: Type "create partition primary" and press Enter.
  • Select the new partition: Type "select partition 1" and press Enter.
  • Activate the partition (MBR only): If you are using an MBR partition style, set the partition as active by typing "active" and pressing Enter.
  • Format the partition: Type "format fs=FILE-SYSTEM label=DRIVE-LABEL quick" and press Enter. Replace "FILE-SYSTEM" with the desired file system (e.g., NTFS or FAT32) and replace "DRIVE-LABEL" with the name you want the drive to have. The "quick" option will perform the format faster but skip it if you are unsure about the drive's condition.
  • Assign a drive letter: Type "assign letter=DRIVE-LETTER" and press Enter. Replace "DRIVE-LETTER" with the letter you want to assign to the drive.
  • Exit DiskPart and Command Prompt: Type "exit" and press Enter to close DiskPart. Type "exit" again to close the Command Prompt window.

After completing these steps, your USB drive should be cleaned and you can use it normally. Remember to always back up important data before performing any disk cleaning or formatting operations to avoid data loss.

shunclean

Identify the disk number

Before you proceed with cleaning your USB drive, it is important to identify the disk number of your USB drive. This is because the cleaning process will completely wipe the entire disk you select, so you must be sure to back up any important files first and be careful to specify the correct disk, or you could accidentally wipe the wrong one.

To identify the disk number, first, connect your USB flash drive to your computer. Then, open the Command Prompt window as an administrator. On Windows 10 or 8.1, you can do this by right-clicking the Start button (or pressing Windows Key + X) and selecting "Command Prompt (Admin)". For Windows 7, open the Start menu, search for "cmd", right-click on "Command Prompt", and choose "Run as Administrator".

Once the Command Prompt window is open, type "diskpart" and press Enter. This will open the diskpart prompt.

At the diskpart prompt, type "list disk" and press Enter. This will list all the disks connected to your computer. Examine the output of the command to identify the number of the disk you want to clean, which, in this case, is your USB drive. Be careful to select the correct disk number.

In the list of disks, you can identify your USB drive by its size. For example, if your USB drive is 14 GB in size and you see "Disk 1" is 14 GB in size, then you know that Disk 1 is your USB drive. Additionally, you can cross-reference the disk numbers with the letters assigned to them in the Disk Management tool. To open Disk Management on Windows 10 or 8.1, right-click the Start button and select "Disk Management". On Windows 7, press Windows Key + R, type "diskmgmt.msc" into the Run dialog, and press Enter.

Once you have identified the disk number of your USB drive, make a note of it, as you will need to enter this number in the next step of the USB cleaning process.

shunclean

Type clean all to wipe the flash drive

To "clean all" and wipe a flash drive using the Command Prompt, follow these steps:

  • Plug your USB flash drive into your computer.
  • Open the Command Prompt as an administrator.
  • Type "diskpart" and press Enter.
  • Type "list disk" and press Enter.
  • Identify your USB flash drive from the list of disks that appears.
  • Type "select disk x" and press Enter. Replace "x" with the disk number you identified in Step 5.
  • Type "clean all" and press Enter.

Note that this process will take a significant amount of time, so please be patient. Do not exit the Command Prompt until you see the message: "DiskPart succeeded in cleaning the disk".

Compared to the "clean" command, the "clean all" command will ensure that your flash drive is wiped thoroughly, and the deleted data will be unrecoverable.

It is important to exercise caution when using the "diskpart" utility. Always back up important data before performing any disk wiping operations, as incorrect commands can lead to permanent data loss.

shunclean

Partition and format the disk

Once you have cleaned the disk, you can now partition and format it.

To do this, first, open the Command Prompt window as an administrator. Then, type the following commands, pressing Enter after each one:

  • Diskpart
  • List volume
  • Select volume +volume number (e.g. select volume 5 if you want to format volume 5)
  • Format fs=ntfs quick label=data (this formats the partition using the NTFS file system and names the partition "data". You can replace NTFS with FAT32 if you want to format the partition using the FAT32 file system. Data can be replaced by any other name)
  • Assign letter = drive letter (replace the "drive letter" with the letter you want, and be careful not to use a letter that is already assigned)
  • Exit (to close the Command Prompt window)

Frequently asked questions

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

Leave a comment