By Stephanie / Last update August 16, 2022

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

Nowadays, data security is particularly important to everyone. Because data is stored in kinds of storage devices, such as computers, smartphones, SD cards, USB flash drives, etc, it’s frustrating if you accidentally deleted or lost vital data from your hard drive.

Data loss could happen for various reasons like 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.


Users may wonder if is it possible to recover files from hard drives using CMD. The answer is yes.  

How to recover files from hard drive using CMD? Microsoft released an official command-line app (Windows File Recovery) to recover files in Windows 10 and above. If your Windows operating system is Windows 10 2004 below, you could use Windows data recovery freeware to recover files from hard drive. Before that, some lost files may be hidden instead of deleted. You could try attrib command to recover hidden files from hard disks first. 

Recover hidden files from hard drive using CMD in Windows 10/8/7

The Windows built-in utility, Command Prompt, is used to control your computer using various commands. It may also fix some Windows-related issues. It is a free alternative method of third-party Windows data recovery software.

CMD can be used to recover hidden files from a computer hard disk, USB flash drive, pen drive, memory card, or other external hard drives. 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 Windows + X keys, and select “Command Prompt (Admin)” or “Windows Powershell (Admin)” for Windows 10.

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


Step 3. Wait for the command to finish.

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 files from hard drive via Windows File Recovery

Windows File Recovery is a command-line application that can be used to recover files that have been deleted from your computer. In 2020, Microsoft released the file recovery tool, which you can use to try to restore data on your hard disk, external storage, and USB flash drives. It doesn’t support cloud storage and network files. It is currently available for Windows 10 2004 and above.

Windows File Recovery is free to solve "how to recover files from hard drive using CMD". However, it is important to understand that the Windows File Recovery tool is a command-line utility. It lacks a graphical user interface (GUI) with clickable buttons.

To use Windows File Recovery for restoring your data, you need to input corresponding commands. It could be complicated for common users. Users are required to input commands in the following command format:

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

There are two basic modes to use: 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.


Step 2. Input Windows File Recovery in the search bar and select “Run as administrator” to launch Windows File Recovery.


Step 3. View the File System of your hard drive. Right-click your Local Disk (C:) and select “Properties”.


File system


Recommended mode


Deleted recently



Deleted a while ago



After formatting a disk



A corrupted disk


FAT and exFAT



Step 4. There are some common parameters and switches to use. Find the meaning of those in the following chart.

Parameter / switch  


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 5. Here are some common examples for reference.

1. If you want to recover an entire folder, you could input the command like the following:

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

2. If you want to recover files with the string of “Test”, you could input:

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

The easiest way to recover files from a hard drive

If you find you couldn't recover files from the hard drive via using cmd or your Windows operating system is Windows 10 below,  the easiest way to recover files from hard drives is a professional data recovery program-MyRecover. This hard disk recovery tool is free software that can help you recover lost files from your hard drive.

It is a tool that knows everything about your hard disk and allows you to recover any data from hard drives. It's very simple to use, even for computer beginners. It will assist you in finding and recovering your data in kinds of data loss scenarios. 


▶ Enable permanently deleted files recovery, formatted file recovery, and other data recovery solutions.
▶ Recover deleted and lost files from HDDs, SSDs, SD cards, USB flash drives, external hard drives, and other Windows storage media.
Recover lost Word documents, Excel spreadsheets, PowerPoint, photos, videos, audios, emails, and hundreds of other file types.
▶ Compatible with Windows 11/10/8/7 and Windows Server.

Download FreewareWin 11/10/8/7/Server
10,000 people have downloaded it

Step 1. Download and install MyRecover on your computer. Select a partition of the hard drive, and click "Start Scan". 


Step 2. The program runs the scanning process quickly and deeply to find deleted files and other missing files in the partition.


Step 3. During scanning, you could recover any file you want. Besides,  you can type the file names or use Filter to find the lost files quickly. Select the file or the folder that you want. Click "Recover files".


To sum up

How to recover files from hard drive using CMD? You could try inputting the attrib command in CMD to recover hidden files from the hard disk first. If you accidentally deleted files from a hard drive, you could recover files from hard drive with the Microsoft official command-line app-Windows File Recovery.

However, it’s not easy for everyone to input the right commands to recover deleted or lost files from hard drives for Windows 10/11. You could try the free hard drive data recovery software-MyRecover to restore files with simple clicks.

Windows data recovery program isn’t a panacea to help you to recover all deleted files. Making a regular backup is the best way to avoid data loss. To keep your data safe, you could try AOMEI Backupper to back up partitions & disks and restore data when you need.