Easy & Free Ways to Recover Files from Hard Drive Using CMD

How to recover files from hard drive using CMD? You can easily recover files using different commands and the first one is to use the attrib command to exclude the hidden files.


By Lora / Updated on April 2, 2024

Share this: instagram reddit

Can I recover lost files from hard disks using command prompt?

Command prompt (short for CMD), also called cmd.exe, is actually a command-line version of software in the most popular operating systems and it helps you manage disk and partition, delete data, etc as well as perform hard drive data recovery in different situations. It also applies to recover files from flash drive, SD card, etc.

It’s frustrating if you accidentally deleted or lost vital data from hard drive due to accidental deletion, hard disk corruption, virus attack, etc. Whatever the causes leading to hard drive data loss, finding the data back is the most important. Be calm and you will get different methods to recover files using cmd in this article.


✍ How to recover files from hard drive using CMD?

❤ In CMD, you could use chkdsk, attrib, rescan, format, etc in different situations.

❤ Besides, Microsoft also release an offline command-line data recovery software to help you recover files in Windows 10 2004 and above. For lower systems or complicated data loss scenarios, try easy & free software - MyRecover.

Recover hidden files from hard drive using CMD

In some cases, your files are hidden instead of deleted. To exclude this possibility, try chkdsk & attrib command to recover hidden files from a computer hard disk. The same is true for other storage devices, such as USB flash drives, pen drives, memory cards, etc.

Hidden files are usually caused by a virus or simply because you do not have permission to view all hidden files. Follow the steps below to learn how to recover hidden files from hard drive using CMD.

Step 1. Press the Win + X keys, and select “Command Prompt (Admin)” or “Windows Powershell (Admin)” for Windows 10.

Step 2. Type attrib -h -r -s /s /d *:\*.* and hit Enter. Wait for the command to finish. (Replace * with the drive letter in which you lost files)​


✍ Attrib syntax meaning:

  • –h Used to clear the Hidden file attribute.
  • –r Used to clear the Read-only file attribute
  • –s Used to clear the System file attribute.
  • /s applies command lines to matching files in the current directory and all of its subdirectories.
  • /d applies command lines to directories.

Recover deleted files from hard drive using cmd

If you can’t see files in the hard drive or other storage devices, your files are likely to be deleted. In case, you need both chkdsk and attrib command to recover deleted files from hard drive using cmd. Or try to recover files from recycle bin.

Step 1. Open cmd with administrator.

Step 2. Type chkdsk *: /f and press Enter. The * stand for the drive letter of your drive containing deleted files.

chdsk cmd

Note: The chkdsk command only works for recognized drive. If your drive becomes RAW, you may receive the CHKDSK is not available for RAW drives error.

Step 3. You may be asked to run this command at the next system startup if the drive is locked. Type y and press Enter to confirm this.

Step 4. Restart your system and wait for the disk check process to complete. Type the drive letter in CMD and press Enter.

Step 5. Type attrib -h -r -s /s /d *.* and press Enter.

All the recovered files will be saved in .chk format. You can change them to the original format and save to a new location.

Recover deleted files from hard drive with Winfr.exe

If your files are still not showing in hard drive, you can try to recover deleted files from hard drive with command-line based data recovery software - Windows File Recovery. It also works for external disk and USB drive.

It requires you to learn the syntax, recovery mode and multiple switches. For details, please refer to how to use Windows File Recovery.

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

This software has two basic modes: regular & extensive. The extensive mode has two advanced modes according to different recovery options: Segment mode and Signature mode. Regular and Segment modes support only NTFS File System.

Step 1. Download and install Windows File Recovery in Microsoft Store. Input Windows File Recovery in the search bar and select “Run as administrator” to launch Windows File Recovery.​


Step 2. View the file system of your hard drive and confirm the recovery mode & switches you will use. Right-click your Local Disk (C:) and select “Properties”.​

The recovery mode & scenarios:

File system


Recommended mode


Deleted recently



Deleted a while ago



After formatting a disk



A corrupted disk


FAT and exFAT



The Winfr.exe switches:



Supported mode(s)


Scans for a specific file by using a file name, file path, file type, or wildcards. For example: 

  • File name: /n myfile.docx
  • File path: /n /users//Documents/
  • Wildcard: /n myfile.*
  • /n *.docx
  • /n **


Recover specific extension groups, comma separated



Saves a log file of the recovery operation in a different location than the default location on the recovery drive (for example, D:\logfile).



Segment mode, recovery option for NTFS drives using file record segments



Signature mode, recovery option for all file system types using file headers


Step 4. Follow the examples below to recover deleted files from hard disk.

  • To recover an entire folder, you could input the command like the following:

winfr C: D: /n \Users\Stephanie\Documents\Test\

  • To recover files with the string of “Test”, you could input:

winfr C: D: /r /n *Test*

To be honest, the command prompt is not easy to use for most users, especially since these require you to learn a lot. Thus, many users prefer an easy & free software based on GUI, such as MyRecover.

It is able to recover files from hard drive, external disk, USB drive, SD card, etc in Windows 7, 8, 10, 11, etc and Windows Server and handle different data loss scenarios, such as accidental deletion, virus infection, disk format, system crash, etc.

As for file types, it supports recovering deleted Word documents, Excel files, PPT, pictures, videos, compressed files, etc and more than 200+ types. And the recovered files will retain their original file name, format, quality, path.

Step 1. Download and install this easy & free data recovery software for multiple Windows systems - MyRecover. In the main page, hover the mouse over the drive and click Scan to scan.

Download SoftwareWin 11/10/8/7/Server
Secure Download


Step 2. The program runs the scanning process quickly and deeply to find deleted files and other missing files in the selected drive. You can search or view files displayed in the following.



  • You can filter files through file name or file type, date modified, size and path in the Filter features. It is able to recover files from a specific folder.
  • You can click the Stop or Pause button if you select the wrong disk or something goes wrong.

Step 3. During scanning, you could recover any file you want. Or wait for the final result and select all the files or folders in it. Then, confirm and click "Recover xxx files".​


Note: MyRecover displays the number of lost files to be recovered and their full size. You can use this to determine if you have selected all the lost files on this location.

Step 4. Select a new folder to store the deleted or lost files and click Select Folder to confirm it. It will automatically recover files from hard disk. Don’t save them to original location as it may cause data corruption or permanent data loss.

Select Folder


  • MyRecover allow users to recover deleted or lost files for free, up to 500MB in total. To recover unlimited files, try advanced editions.
  • You still can use it to recover files from formatted hard drive, recover files lost in cut and paste, fix Seagate external hard drive files not showing up. etc.

Recover formatted data from hard disk using cmd

Also, your disk may be formatted or ask you to format disk, resulting in data loss. In this case, try the rescan command in the DiskPart tool to recover data from a formatted hard disk.

Step 1. Open CMD with administrator.

Step 2. Type the following commands and press Enter to execute them one by one.

  • diskpart
  • list disk
  • select disk *: (Replace * with drive letter of your formatted disk.)
  • rescan

DiskPart Rescan

Step 3. Wait for the scan process to complete. It will recover data from a formatted hard disk.

✍ What if your hard drive is a system disk?

If your hard disk contain system partition, you need to boot into safe mode and run CMD to repair disk and recover data from it.

  • Press Win + I keys to open Settings and go to Update & Security.
  • Then, click Recovery and go to Advanced startup, hit Restart now to access Windows recovery environment.
  • Finally, click Restart and select Enable Safe Mode with Command Prompt.

Enable Safe Mode

Recover files from coruppted hard drive using cmd

If you suspect your disk is damaged, try the format command in the DiskPart tool. Please recover files from hard disk using above methods first if it contains your important data. MyRecover is highly recommended because it is suitable for multiple data loss scenarios and multi-system compatibility.

Step 1. Run CMD with administrator.

Step 2. Type diskpart as well as the following commands. Remember to press Enter after each line. 

  • list disk
  • select disk *: (Replace * with drive letter of the damaged disk.)
  • clean
  • create partition primary
  • format fs=ntfs quicks

Format RAW Drive to NTFS

To sum up

How to recover files from hard drive using CMD? If you not sure if your files are hidden or not, try the attrib command first. You can then use other 5 methods to recover files.

CMD or Windows data recovery program isn’t a panacea to help you to recover all deleted files. Thus, making a regular backup is necessary if you are worried about data loss due to unexpected failure. Try free backup software for Windows - AOMEI Backupper Standard

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.