We all know the feeling of losing a file, finding it in the trash and not even finding it there. Fortunately, the injury is temporary, and there are various tools with which you can recover the lost file. Most of these tools recover lost files from previous images (memory status) of your system. One such tool is the tried, tested, and extremely reliable TestDisk utility. TestDisk is a free data recovery software designed to recover lost partitions and / or restore bootable disks without booting if these symptoms are caused by faulty software, certain types of viruses or human errors. It can also be used to fix some file system errors.
In this article, we will show you how to recover accidentally lost files in Debian using the TestDisk utility.
We ran the commands and procedures mentioned in this article on the Debian 10 Buster system.
So, the situation is that I mistakenly deleted, even from the trash, the document file (.docx) that was present in my / home /[user]/ Boot folder. Now I need to find a way out with which I can restore the file to its original location. Or at least restore it anywhere I can access it, and then move it to the correct directory.
Here is a step-by-step process that will help me, as well as you, recover a deleted / lost file in Debian by mistake.
Step 1. Install TestDisk Utility
Open the Debian command line, Terminal, using a search in the system application:
You can access the application launcher by pressing the Super / Windows key.
Then run the following commands on behalf of sudo to install the TestDisk utility:
$ sudo apt-get update
$ sudo apt-get install testdisk
Please note that only an authorized user can add / remove and configure software in Debian. Please enter the password for sudo, after which the utility will be installed on your system.
You can check whether the utility is really installed on your system, and also check its version number using the following command:
$ testdisk --version
$ testdisk -v
Step 2: Launch TestDisk and create a new testdisk.log file
Use the following command to run the testdisk command-line utility:
$ sudo testdisk
As a result, you will get a description of the utility. This will also allow you to create a testdisk.log file. Later this file will contain useful information about how and where your lost file was found, listed and resumed.
The above output gives you three options for what to do with this file:
Create: (recommended) – this option allows you to create a new log file.
Add: this option allows you to add new information to the information already listed in this file from any previous session.
No log: select this option if you do not want to record anything about the session for later use.
Important: TestDisk is a fairly intelligent tool. He knows that many beginners will also use the utility to recover lost files. Therefore, he predicts and offers an option that you should ideally choose on a particular screen. You can see the proposed options in highlighted form. You can select an option using the up and down arrow keys, and then enter to make your choice.
In the above output, I would choose to create a new log file. At this point, the system may ask you for the password for sudo.
Step 3: select a recovery drive
The utility will now display a list of drives connected to your system. In my case, it shows my hard drive, as this is the only storage device on my system.
Select Proceed using the left and right arrow keys, and press Enter. As indicated in the note in the screenshot above, to successfully restore the file, you must determine the correct disk capacity.
Step 4: Select the partition table type of the selected drive
Now that you have selected the drive, you need to specify its type of partition table on the following screen:
The utility will automatically highlight the correct selection. Press Enter to continue.
If you are sure that the data of the test disk is incorrect, you can make the right choice from the list and press Enter.
Step 5: select “Advanced” to restore files
When you specify the correct drive and its partition type, the following screen appears:
Recovering lost files is only one of the features of testdisk, the utility offers much more. Using the options shown in the screenshot above, you can select any of these functions. But here we are only interested in recovering our accidentally deleted file. To do this, select the Advanced option and press Enter.
In this utility, if you reach a point that you were not going to, you can go back using the q key.
Step 6: Select the disk partition where you lost the file
If the selected drive has several partitions, on the next screen you can select the appropriate one.
I lost my file when I used Linux, Debian. Make your selection, and then select the List option from the options shown at the bottom of the screen.
This will list all the directories in your section.
Step 7: Go to the directory where you lost the file
When the testdisk utility displays all the directories of your operating system, go to the directory from which you deleted / lost the file. I remember that I lost the file from the Downloads folder in my home directory. So, I will go to the house:
My username (san):
And then the Downloads folder:
Tip: You can use the left arrow to return to the previous directory.
When you get to the directory you need, you will see the deleted files in color or highlighted form.
And so I see my lost file “randomly_removed.docx” in the list. Of course, I deliberately called it the way I was supposed to illustrate the whole process to you.
Step 8: copy the deleted file to recover
By now, you must have found your lost file in the list. Use option C to copy the selected file. This file will later be restored to the location that you specify in the next step:
Step 9: Indicate the location where the found file will be restored
Now that we have copied the found file, the testdisk utility will display the following screen so that we can indicate where to restore it.
You can specify any available location, as this is just a simple interface for copying and pasting the file to the desired location.
I specifically choose the place where I lost the file, the “Downloads” folder:
Step 10: copy / restore the file to the selected location
After choosing where you want to restore the file, press the C button. This will restore your file to this place:
See the green text in the screenshot above? This is actually great news. Now my file has been restored to the specified location.
This may seem like a bit of a long process, but definitely worth the return of a lost file. The recovered file will most likely be in a locked state. This means that only an authorized user can access it and open it.
We all need this tool again and again, but if you want to remove it until you need it, you can do this with the following command:
$ sudo apt-get remove testdisk
You can also delete the testdisk.log file if you wish. It is such a relief to recover your lost file!
Recover Deleted Files in Debian with TestDisk