How to Recover Deleted Files Using TestDisk in Linux – Guide

Deleting a file on a Linux system doesn’t necessarily go away forever, especially if you’ve recently deleted it. Unless you’ve erased them with a tool like Fragment, the data will still be on your hard drive – and one of the best tools to recover deleted files, Testdisk, can help you recover them. Although testdisk has a wide variety of features, including recovering lost or damaged partitions and resetting unbootable disks, is also widely used to recover files that were accidentally deleted. We all know that feeling of looking for a file and not even finding it in the trash. The trauma that comes with losing files and data should be over thanks to TestDisk – a free and open source software originally designed to restore memory partitions and make unbootable hard drives bootable again. It is useful to recover data from partitions caused by human error or virus. TestDisk is a reliable and powerful command-line data recovery tool. It was written in the C programming language by Christophe Granier. In addition to Linux, TestDisk is available on almost all other operating systems, including Microsoft Windows, macOS, and OpenBSD.

Recover Deleted Files on Linux with TestDisk

The first step to recover deleted files is to create a log file. A TestDisk log file is important as it stores essential information related to data and partition recovery. Even in general, users should prioritize the system log to get information about the activities happening on their computer.

Create a log file

Start TestDisk using the following command: The system will display the output as follows. As TestDisk is an interactive utility, it will give you options on every screen to choose from. Notice in the output below that you have three options: Create, Append and No Log.

Choose the recovery drive

After creating a log file, you need to choose which disk drive you want to recover data from. The screen will display information associated with each drive on your system, including the drive name and size. Select the drive of your choice and press Enter. If you can’t find a specific drive, try starting TestDisk using the sudo testdisk command.

Choose partition type

The next step is to select the type of partition you want to recover. If you can’t figure out which partition is the correct one, simply proceed with the one TestDisk highlighted for you. Users can choose from the following seven partition types. Select the most appropriate option and press Enter. Now choose recovery options from the list. Although you are free to select whichever option suits you best, if you want to restore deleted files, choose Advanced. The system will list all available partitions on the selected disk. Highlight your choice and press Enter. If you are using an HDD, it is likely that the system will display multiple partitions. On the other hand, if it is a removable media drive, TestDisk will only display a single partition. TestDisk will ask you to choose a directory to store the partition image file. Choose an appropriate location and select Continue.

TestDisk will now display all files and folders stored on the selected partition. Change to the directory that contains the deleted file. For example, if the /Desktop directory contains the file, navigate to that folder. Deleted files will have a red font color. If you do not find any deleted file entries, unfortunately your files cannot be recovered. On the other hand, if you found file entries with red font, you cannot simply “restore” those files using TestDisk. What you will have to do is copy the deleted files and paste them in another directory. To copy a deleted file, highlight that specific file and press C on your keyboard. Now, navigate to the directory where you want to paste the file and press C again to paste. If the system successfully copied the file, you will receive a notification that the copy is complete! 1 ok, 0 failed in bright green color. Exit the application by selecting the Exit option on the screen. The system will take you back to the previous screen. Again, continue selecting Exit to return to the previous screen. It will take a few rounds to highlight and press Enter to close TestDisk completely.

Final note

I hope you like the guide How to Recover Deleted Files Using TestDisk in Linux. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.