Recover Files from External Hard Drive Using Command Prompt
In this article
Yes, you can recover files from an external hard drive using Command Prompt (CMD) on Windows, but only if the drive is still recognized by the system and the files are not physically damaged. CMD uses built-in tools like ATTRIB to unhide files, CHKDSK to fix file system errors, and ROBOCOPY to copy data off a failing drive. It does not perform deep data recovery; for physically damaged drives or deleted files that were overwritten, you’ll need dedicated recovery software. Before starting, stop using the drive immediately to avoid overwriting data, and make sure you have another storage location with enough free space to copy recovered files to.
What You'll Need
- A Windows PC (the steps work on Windows 10 and 11; labels may differ slightly by version).
- The external hard drive connected via USB.
- A second storage location (another external drive, USB stick, or a folder on your PC) with enough space for the recovered files.
- Administrator access to the PC (to run Command Prompt as administrator).
Step-by-Step
- Connect the external drive to your PC. If Windows asks to format the drive, click “Cancel” – do not format, as that will erase data.
- Open Command Prompt as administrator. Click the Start button, type
cmd, right-click “Command Prompt” and choose “Run as administrator”. Click “Yes” if prompted by User Account Control. - Identify the drive letter. Type
diskpartand press Enter. Then typelist volumeand press Enter. Look for your external drive’s volume – it will show a letter (like E: or F:) and a label. Note the letter. Typeexitto leave diskpart. - Run CHKDSK to repair file system errors. Type
chkdsk X: /f(replaceXwith your drive letter) and press Enter. If prompted that the drive is in use, typeYto schedule it on next restart, then restart your PC. This step fixes corruption that may be hiding files. - Try the ATTRIB command to unhide files. If the drive is accessible, type
attrib -h -s -r /s /d X:\*.*(replaceXwith your drive letter) and press Enter. This removes Hidden, System, and Read-Only attributes from all files and folders on the drive. Wait for it to finish – it may take a few minutes. - Check if files are now visible. Open File Explorer and browse to the drive. If you see your files, skip to Step 8. If not, proceed to Step 7.
- Use ROBOCOPY to copy files off the drive. Type the following command, replacing
Xwith your source drive letter andD:\Recoveredwith the full path to your destination folder (create that folder first):robocopy X:\ D:\Recovered /E /COPY:DAT /R:1 /W:1
Press Enter. This copies all files and folders (including hidden ones) to the destination. The/R:1 /W:1limits retries to avoid hanging on bad sectors. - If ROBOCOPY fails due to access denied, try copying manually. Open File Explorer, navigate to the drive, and try to copy the files. If you get an “Access Denied” error, right-click the drive in File Explorer, select “Properties”, go to the “Security” tab, click “Advanced”, then “Change” next to Owner, type
Administrators, click “Check Names”, then OK. Check “Replace owner on subcontainers and objects”, apply, and try copying again. - After copying, verify the recovered files. Open a few files in the destination folder to ensure they are not corrupted. If a file won’t open, it may be damaged; try recovery software later.
Common Mistakes
- Running CHKDSK without administrator rights – it will fail with “Access denied”. Always run Command Prompt as administrator.
- Using the wrong drive letter – double-check in diskpart before running any command. Typing commands on the wrong drive can cause data loss.
- Formatting the drive when prompted – this will erase everything. Always click “Cancel”.
- Copying files back to the same failing drive – that risks overwriting data. Always copy to a different location.
- Ignoring the “/R:1 /W:1” flags in ROBOCOPY – without them, ROBOCOPY may hang indefinitely on bad sectors.
Tips
- If the drive makes clicking or grinding noises, stop using it immediately – it may be physically failing. Do not run CHKDSK; instead, power off and seek professional data recovery.
- For deleted files that were not overwritten, you can try the
RECOVERcommand (typerecover X:\in CMD), but it only works on NTFS and may not recover all files. It’s less reliable than dedicated software. - If you know the file type (e.g., .jpg), you can use
dir X:\*.jpg /s /bto list all such files, then copy them manually. - Always create a system restore point before running CHKDSK, though it rarely causes issues.
- If the drive is not recognized at all, try a different USB port or another PC. If it still doesn’t show, CMD cannot help – you need data recovery software or a professional.
Troubleshooting
If CHKDSK says “The type of the file system is RAW” – your drive’s file system is corrupted. Do not format. Try running chkdsk X: /f anyway; if it fails, use recovery software like Recuva or TestDisk (open-source) to recover files before formatting.
If ATTRIB returns “Access denied” – the drive may be write-protected or have permission issues. Check if the drive has a physical write-protect switch. If not, run the command as administrator again. If it still fails, try the owner-change method in Step 8.
If ROBOCOPY crashes or freezes – it’s likely hitting a bad sector. Press Ctrl+C to stop it, then run it again with /R:0 /W:0 (no retries) to skip bad sectors quickly. You’ll lose files in those sectors, but you’ll get the rest.
If the drive is not visible in diskpart – check Device Manager (right-click Start > Device Manager) under “Disk drives”. If the drive is listed but with a yellow warning, right-click it, select “Uninstall device”, then restart your PC. If it’s not listed at all, try a different cable or port. If it still doesn’t appear, the drive may be dead – CMD cannot help.
If you see “The volume does not contain a recognized file system” – the drive is likely RAW. Do not format. Use TestDisk (free, open-source) to rebuild the partition table, or use a recovery tool to scan for files.
Frequently Asked Questions
Can I recover files from a formatted external hard drive using CMD?
No, CMD cannot recover files after a full format. You need data recovery software like Recuva, Disk Drill, or TestDisk, which scan the raw disk for remnants.
Does the ATTRIB command work on all file systems?
ATTRIB works on NTFS and FAT32, but it only changes file attributes. If the file system is corrupted, it may not work. CHKDSK can repair the file system first.
Is it safe to run CHKDSK on an external drive?
Yes, CHKDSK is safe for most drives, but it can cause data loss if the drive has severe corruption. Always back up what you can first. If the drive is making noises, do not run CHKDSK – it may worsen physical damage.
What if the external drive is not showing up in Windows at all?
CMD cannot help if the drive is not recognized. Try a different USB port, cable, or another PC. If it still doesn’t appear, the drive may have failed physically – consider professional recovery.
Can I use CMD to recover files from a drive that has bad sectors?
Yes, ROBOCOPY with /R:1 /W:1 can copy files while skipping bad sectors, but you may lose files in those areas. For better results, use recovery software that can read around bad sectors.
Will these commands work on a Mac or Linux?
No, these are Windows commands. On Mac, use Terminal with fsck or dd, but they are more complex. On Linux, use fsck or ddrescue.