A USB drive is susceptible to various issues such as the file system becoming RAW, USB drive not recognized error, being corrupted, unreadable, or being damaged. For Windows users, one course of action is to repair the pen drive using CMD. This essentially means you can fix the flash drive without software (third-party) and without formatting it. Since you’re dealing with the Windows Command Prompt, it’s recommended you pay attention to each step.

Did you know? You can use CMD to run any program that is installed on your computer. It’s a simple two-step process–first type cd [filepath] in the Command Prompt, replacing [filepath] with the Windows Explorer path to the file you want to run, and press Enter. After this, type start filename, replacing “filename” with the executable file you want to run.

Backup Important Data With a Specialized Tool

Before we fix the USB flash drive using CMD, it’s important to first create a backup of the affected USB drive. Since Windows cannot read the pen drive properly, you will need a third-party program to do this. There are many programs that let you create backups of an unreadable USB drive.

In our tutorial, we’ll use Disk Drill–one of the best data recovery programs on the market. It also has an easy-to-use backup feature. Disk Drill lets you create a backup, right down to the byte level, so you can rest assured none of your files will be skipped.

For an in-depth look at Disk Drill and its various features, read our review of Disk Drill.

Create a byte-to-byte backup of your USB drive using Disk Drill:

  1. Download Disk Drill and run the setup file.
  2. Connect the USB drive to your computer.
  3. Open Disk Drill, and click on the Drive Backup option visible in the left navigation pane.Drive backup option in Disk Drill's navigation pane.
  4. Now, select the USB drive from the list of devices and click on the Byte-to-byte Backup option.Byte-to-byte backup screen in Disk Drill.
  5. In the next window, you can choose where you want to save the disk image of the USB drive and modify the name of the disk image. Ensure that Format is set to Bytes. Click OK. Wait for Disk Drill to create the backup. It may take some time, depending on the storage capacity of the USB drive.Byte-to-byte backup parameters windows.
  6. Click on Done once Disk Drill has created the image.Disk image creation complete screen.
You can use this disk image to recover data from the corrupt USB drive if you fail to fix it using the methods below. Besides this, even if you have to format the USB drive, you can use the disk image to recover all the data you lost, because the disk image is the exact virtual copy of your drive.

Here is how to scan the disk image and recover your data using Disk Drill itself:

  1. Open Disk Drill, click Attach disk image and select the disk image you created earlier.Attach disk image option in Disk Drill.
  2. It will be added as a separate device, and you can simply select it, then click Search for lost data.Mounted disk image in Disk Drill.

How to Repair a Flash Drive Using CMD

Let’s take a look at a few methods that will help you fix a USB drive using CMD. Three of the methods work without downloading additional software, they are all run using Windows Command Prompt. The last method will require you to download an open-source data recovery program.

Method 1: Fix Hidden Files on Pen Drive Using CMD (Attrib)

One of the ways to recover files from USB using CMD, is to use the attrib command. Sometimes, malware can modify the attributes of files and directories, rendering them inaccessible or hidden from view.

The attrib command in CMD restores these attributes so you can regain access to your files and folders.

Instructions on how to use the attrib command:

  1. Type cmd in Windows Search (Windows Key + S) and right-click on Command Prompt > Run as administrator from the search results.The Command Prompt in Windows Search,
  2. In the console, type X:, where X is the drive letter of your USB drive and press Enter.The drive letter command in Command Prompt.
  3. Now, enter the following command and press Enter: attrib -h -r -s /s /d *.*.The attrib command in Windows Command Prompt.
  4. You should now be able to view any files that went missing because of a virus.

It’s good to know what the parameters at the end of the attrib command mean:

  • -h unhides the files.
  • -r removes the Read-only attribute from the files.
  • -s clears the System file attribute from the files.
  • /s and /d apply attrib and any other command line options to directories as well as all matching files and subdirectories.
  • *.* informs Windows that you want to apply attrib to all files in the current directory.

Method 2: Repair Corrupted USB Drive With CHKDSK

CHKDSK is Windows’ in-built command line utility that can help repair a USB drive using CMD. It automatically scans and checks for errors on a disk. This includes detecting and repairing bad sectors, thus fixing the corrupted USB drive. While CHKDSK can restore some of the data on your USB drive, it can also rewrite it, so it’s best to first create a backup of your USB drive.

Note: If your flash drive has turned RAW, the CHKDSK command will not work. The only exception to this is if your USB drive was first formatted in the NTFS file system before it turned RAW.

After running the CHKDSK command, you can also scan the drive using USB data recovery programs to get back any information that may have gone missing.

Here is how to fix a USB drive in CMD using the CHKDSK command:

  1. Again, run Command Prompt as administrator. You can use Windows Search (Windows Key + S).
  2. In the CMD console, type chkdsk X: /r (replace X with the drive letter of your USB drive), and press Enter.The CHKDSK command syntax.
  3. Wait for CHKDSK to finish scanning and repairing the USB drive. The time taken may vary depending on the size of your USB drive.CHKDSK command complete Command Prompt.

Method 3: Format Flash Drive Using DISKPART Command

Diskpart is a command line utility in Windows that is used to manage and make modifications to physical as well as virtual drives on your computer. Formatting a RAW or corrupt USB drive to a recognized format using diskpart is one of the ways you can repair a flash drive using CMD.

While formatting will delete all the data on your USB drive, you can still recover it using data recovery software like Disk Drill. This only works if you Quick Format the drive. Thus, closely read the commands in our diskpart tutorial and remember to add all the parameters specified in each command.

Tutorial on how to run a Quick Format on the USB drive using diskpart:

  1. Search for CMD in Windows Search (Windows Key + S). Run Command Prompt as administrator.
  2. Type diskpart in the console and press Enter.The diskpart command in Command Prompt.
  3. Type list disk and hit Enter to list the storage devices connected to the PC.The list disk command in Command Prompt.
  4. Now, type select disk x (replace x with the disk number of the USB drive) and press Enter. In our case, the disk number was 1.The select disk command in Command Prompt.
  5. Type list volume and press Enter.The list volume command in Command Prompt.
  6. Type select volume x (again, replace x with the number of the volume), and press Enter. In our case, the volume number was 5. You can determine this by looking at the size of the volume or the drive letter.The select volume in Command Prompt.
  7. Finally, type format fs=ntfs quick and press Enter. Diskpart will Quick Format the USB drive. You can also replace ntfs with any other file system of your choice, such as FAT32 or exFAT.The format command in Command Prompt.

Method 4: Recover Lost or Corrupted Partitions With TestDisk

TestDisk is a third-party, open-source recovery program that can help you recover lost or corrupted partitions on your USB drive, and restore its functionality. The software is quite adept at data recovery and is one of the best USB repair tools currently. Unlike Disk Drill, TestDisk doesn’t have a GUI, so using it is similar to how you would recover a flash disk using CMD.

How to fix a corrupted USB drive and get back lost data using TestDisk:

  1. Download TestDisk and extract the archive.
  2. Run the testdisk_win.exe application.
  3. Select whether you want to create a log file or not. Use the arrow keys to navigate and press Enter to confirm the option.Log creation screen in TestDisk.
  4. Now, select the USB drive from the list of media and press Proceed.Select media screen in TestDisk.
  5. Choose a partition table. TestDisk detects this by default, so it’s recommended you simply leave the highlighted option as it is and press Enter.Partition table selection screen.
  6. Choose Analyse and press Enter.Analyse option in TestDisk.
  7. Ensure that Quick Search is highlighted and press Enter.Quick Search option in TestDisk.
  8. Here, press P to view recoverable files in TestDisk. After confirming, press Q to go back.
  9. Use the left and right arrow keys to make sure that there is P at the beginning of the partition, as shown in the image below. Press Enter.
  10. View recoverable files in TestDisk.Select the Write option using the arrow keys and press Enter.Write option in TestDisk.
  11. Press Y to confirm on the next screen.Confirmation screen TestDisk.
  12. Wait for TestDisk to perform the operation and then reboot your PC.

The methods above highlight how you can repair a flash drive using CMD or using TestDisk. In case none of the methods work, it’s best to contact experts and send in your USB to repair service. You can also contact a data recovery service to recover files from the broken USB drive.

FAQ

Conclusion

It may be convenient to fix a USB drive using CMD because it eliminates the need to download third-party programs, but it’s likely that you will need a utility like Disk Drill to create a backup of the drive first. Additionally, if the drive is severely corrupted, your only option may be to recover the data first because the USB drive will be unfixable without formatting it first.