How to Recover Data from Hard Disk Using Command Prompt?

How to recover data from hard disk using command prompt? Turn to this detailed guide and recover data from hard drive in Windows 10 easily.

Lora

By Lora / Updated on September 13, 2024

Share this: instagram reddit

How do I undo a delete in CMD? Can chkdsk recover files?

While using the hard drive, users tend to meet situations like partition or data loss due to misoperation or inadvertent deletion. For example, some users have accidentally deleted a partition and asked how to recover it;

What’s more, thousands of users report that they have mistakenly removed the wrong files.

I have deleted 2GB from my documents by mistake. I only deleted the folder and its content from my documents and then emptied the recycle bin. Can I use CMD to get my files back?

- Question from Spiceworks

Users don't know whether the deleted data is recoverable. Some of them heard that they could recover files using Command Prompt, e.g., the attrib command, the "recover" command in CMD, etc.

Is it feasible? If so, how to recover data from hard disk using Command Prompt? Check out the following part.

Is it possible to recover data using CMD?

As a quite useful inbuilt tool utility on Windows, Command Prompt indeed can enable users to solve their hard drive recovery issue.

Command Prompt, commonly referred to as CMD/cmd.exe, is a default command-line interpreter users can utilize on Microsoft Windows 10/8/7/Server 2003/Vista/XP and other OS.

command-prompt-interface

When running CMD, users can operate or interact with the system, including managing disks, retrieving documents, fixing bad sectors, and so on.

As for the files deleted, they are indeed recoverable. When the OS deletes a file, it just removes it from the allocation table.

At this time, the first letter of the file name in the disk storage area will be wiped, and the space used by the deleted file is marked as free space.

But the file content itself will not be erased immediately, which means that the file data can still exist and can be restored. E.g., you could also recover flash drive files using CMD.

Then how to recover files using command prompt? Check it out in the solution part as follows.

How to recover data from hard disk using Command Prompt?

In this section, we will walk you through 2 commands and teach you how to recover files using Command Prompt.

Case 1. Show hidden files using CMD

If you find your files lost from your hard drive, perhaps they are not indeed deleted but invisible. At this time, you could use CMD to let them be accessible again.

Notes:✎...
This tool only fits the situation where your files are hidden or unchangeable, and it is not recommended for those who do not possess computer expertise. 

If you are Windows 7 user, please check this guide to show hidden files in Windows 7.

Step 1. Input cmd in the search bar of Windows, then choose Run as administrator.

Step 2. Now you are in the Command Prompt interface, input chkdsk x:/f. Here x refers to the drive letter of the disk in which your lost data was stored.

Step 3. Input the drive letter again. Then input attrib –h –r –s /s /d diver-letter: \*.*.

attrib-cmd

Here the command line “attrib” enables users to view or change the attributes of the files.

-” means clearing the attribute;
/s” enables users to process matching files in the current folder and all subfolders.
/d” supports users to process folders as well.
h” means the hidden file attribute;
r” means the read-only file attribute;
s” means system file attribute.

Thus you have performed hard drive recovery by removing the hidden attributes of the data.

Case 2. Recover deleted data from hard drive using CMD

How to recover data from hard disk using Command Prompt if they were removed? If you are sure you have deleted the files, you can use the Recover command to get them back.

It uses the exact filename and path to search for the target files, thus restoring readable info from a defective drive.

The command format is:

recover [drive:][path]filename
Notes:✎...
It only restores 1 file at a time. So, it is unsuitable for users who want to recover multiple files.

Step 1. Input cmd in the Windows search box > click Run as administrator > start Command Prompt

run-as-administrator

Step 2. Input diskpart > list disk > select disk 0 > list volume > select volume 1. Input the actual drive letter your hard drive is using.

Step 3. Input recover [drive:][path]filename

recover-command-usage

For instance, input:

recover d:\documents\weekrepots\1124.doc

This way, you can restore the wanted file one by one using the CMD.

Recover files using command prompt via Windows File Recovery

Except for CMD, Windows File Recovery also uses commands to retrieve data from hard drives.

As an official tool developed by Microsoft, it can provide a relatively high recovery rate. Using this tool, you could recover permanently deleted files Windows 10 using cmd from external/internal hard drives in Windows 10 2004 and later.

Notes:✎...
Please avoid using your computer after an unintentional deletion to avoid overwriting files. 
If you meet the error "failed to create destination folder" in Windows File Recovery, please get help.

Using this tool requires users to pick a recovery mode and switches. To get a more detailed introduction to modes and switches, please refer to "How to use Windows File Recovery". It provides two basic modes: Regular & Extensive;

Two advanced modes are also available: Segment & Signature. Segment only supports file recovery on hard drives using NTFS, while Signature can recover files under all File Systems.

To decide which mode to use, you need first to check the File System your hard drive is using.

Go to This PC> locate the hard disk where your files are lost > right-click on it > Properties.

check-file-system

Then this chart will help you decide the recovery mode.

File system Scenarios mode
NTFS Deleted recently Regular
NTFS Deleted for a while Extensive
NTFS Formatted disk Extensive
NTFS Corrupted disk Extensive
FAT and exFAT Any Extensive

Parameters are available for folder filter, too.

Switches Meaning Supported mode(s)
/n Filter the scan range: scans for a specific file with its file name/path/type, etc. All
/y: Recover specific extension groups. Signature
/k Recovers system files. NTFS
Segment​​​​​
/u Recovers undeleted files, for example, from the Recycle Bin. NTFS
Segment

Now follow the guide here.

Step 1. Install Windows File Recovery from Microsoft Store.

get-windows-file-recovery

Step 2. Run it. Instructions are shown on the window. Input the recovery command:

winfr source-drive: destination-drive: [/mode] [/switches]

For instance, if you need to recover Excel files from C: drive to E: drive, and the files are deleted several days ago, then you should take advantage of Segment mode.

winfr-segment-xlsx

Step 3. Then after the processing, a folder named Recovery will be created automatically in the target place.

Some users may find it too complicated to use Windows File Recovery because commands are so difficult to handle.

Then for these users, a file recovery tool with a graphical user interface could be of help. To recover deleted files from SD card using this tool is also feasible.

How to recover data from hard drive effortlessly?

Though the inbuilt tool Command Prompt is quite powerful, it can be pretty dangerous for those who do not possess some troubleshooting experience and computer expertise.

Once an individual step or line gets input wrongly, users may carry out an improper operation, leading to severe results like further data loss or device malfunction.

Also, the recover command and Windows File Recovery are far from convenient for users because they offer no graphical user interface and are not flexible enough to meet users’ needs.

Then, for those who are using Windows OS under Windows 10 and don't know much about commands, how to restore data from hard drives easier? You might as well let MyRecover help you.  

♦ MyRecover  – recover data from hard drives without CMD
  • Restore deleted files and meanwhile keep their original file formats, filenames, and file paths.
  • Restore more than 200 types of data, including photos, texts, docs, charts, zip files, etc.
  • Support data recovery during the scanning process - no need to wait till it ends.
  • Highly compatible with Wide Windows OS from 7 SP1, 8, 10, to 11.
Download SoftwareWin 11/10/8/7/Server
Secure Download

Step 1. Run MyRecover > Hover the mouse over the drive saved deleted files before, and click Scan.

select-a-partition-to-scan

Step 2. Search for your wanted files by inputting filenames, extensions, etc. Also, you can sort them by Type, Modified date, Size, etc.

scan-lost-data

Step 3. Select the files you need > click Recover x files to store your deleted or lost data.

recover-lost-data

Using this tool can free you from difficult commands and save your precious time. Also, it is feasible to restore permanently deleted files from hard drive using this utility.

Prevent data from loss in the future

On this page you can find a detailed introduction about how to recover data from hard disk using Command Prompt, what’s more, steps to operate a recommended alternative are provided as well.

Compared with performing hard drive recovery, taking precautions is much wiser for users to do so. The top priority for users to use their devices is to form a habit of making a backup of their valuable data.

To carry out this precaution, you may as well utilize a third-party tool AOMEI Backupper, whose easy-to-operate inbuilt tool “System Backup”,  “Disk Backup”, “File Backup”  etc. facilitates users to backup their cherished data and prevent future risks.

Lora
Lora · Editor
Lora is an editor of AOMEI Technology. She is also a tester and editor of AOMEI Data Recovery Tools. -- "Keep testing, write the most useful tutorials for helping people recover the lost data for Windows and phones" is the most meaningful thing for her. Dedicated to creating helpful tutorials, she hopes her tutorial can assist users to effortlessly solve data loss problems on their personal computers and mobile phones.