Whether you have accidentally deleted an important file or it has been removed from your device for other reasons, we all encounter data loss from time to time. This can be a downright traumatic experience if the file you have lost is significant to you. But don’t worry. There are multiple ways to recover a file deleted from your Ubuntu partition. In this article, we will use free open-source software, TestDisk Utility, to show you how to easily recover lost files from an Ubuntu partition. Without further ado, let’s dive in.
Step #1: Install the TestDisk Utility on Your Computer
To recover your lost Ubuntu partition and the files in it, you need to install the TestDisk Utility on your Linux device first. Follow these steps to do it:
- Press on the “CTRL + Alt + T” keys on your keyboard to open the “Terminal.”
- Next, type and execute this command: $ sudo apt-get install testdisk
- After that, you have to type the password for sudo to authorize the installation of the TestDisk utility.
With this, the TestDisk utility should be installed in your device within a few minutes, which will be visible from the Terminal. To confirm its installation, use any one of the following two commands and execute it:
- $ testdisk –version
- $ testdisk -v
If the TestDisk has been successfully installed on your computer, this command’s execution will show the version of the application.
Step #2: Create a testdisk.log File
Before you start the file recovery process, you need to run the TestDisk utility on your Linux device and create a “teskdisk.log” file. First, to run TestDisk on your computer, execute this command in the Terminal: $ testdisk
The output of this command will give you a brief introduction to TestDisk, and show you important information regarding the creation of a testdisk.log file. Consequently, it will ask you to select one of the following three options:
- Create – This option will help you create a new testdisk.log file.
- Append – This option will allow you to append new data to an already existing testdisk.log file.
- No log – You should choose this option if you don’t wish to create any new testdisk.log file in your current session.
In our case, we want to create a new testdisk.log file. In other words, choose the “Create” option.
Step #3: Select the Recovery Drive
After you choose the “Create” option in the previous step, the terminal will display all available storage devices currently connected to your computer. If there are no external storage devices attached to your machine, this window will show you the HDD or SSD of your computer under the “Select a media” section. Here are the steps to choose the recovery drive properly:
- If you have multiple storage media, choose one as the “Recovery drive” using the arrow keys and press the “Enter” key. If there are no external storage media connected to your computer, select the HDD or SSD displayed on the screen and press “Enter” to continue.
- Now, use the “Arrow” keys once again to select the “Proceed” option and press the “Enter” key.
Please Note: If the storage media you’re looking for isn’t listed under the “Select a media” section, there will be a different “sudo” option beside the “Proceed” option. Select the “sudo” option and enter the “sudo password” to display all the storage media that wasn’t displayed before.
Step #4: Pick the Partition Table Type
Once you’re done selecting the recovery drive, it’s time to choose a partition table type. In the next menu of the TestDisk utility, you will be presented with multiple partition table types. Thankfully, TestDisk is a smart application, and it will automatically highlight the correct partition table type for you. All you have to do is select the highlighted partition table type and press the “Enter” key.
Step #5: Select the Advanced Option
TestDisk utility has multiple features, and recovering lost partitions is just one. Thus, in this step, you can select which feature you would like to use according to your requirement. However, we want to recover lost files from Ubuntu partitions. Therefore, use your “Arrow” keys to select the “Advanced” option and press “Enter.”
Step #6: Choose the Ubuntu Partition You Want to Recover Files From
In this step, the application will show you all the partitions that are currently available on your Linux device. To continue to the next step, choose the partition you have lost your files from and press the “Enter” key. If you unmounted it to prevent further data loss in the past, mount it again.
Step #7: Browse the Chosen Directory
You will now see multiple directories available inside your selected partition. Here, you need to select the one that suffered data loss. To do that, follow these instructions below:
- First, choose the directory where your file was originally located.
- Now, select the appropriate “user name” if the TestDisk utility asks for it.
- Next, choose the folder where your files were located before deletion.
You can always use the “Left Arrow” key to move back to the previous directory. Once you reach the correct folder, you will see the deleted files highlighted in red color.
Step #8: Copy the Deleted File and Select a Location to Restore It
Once you see the files that were deleted from the directory, use the “Arrow” keys to select them. After that, press the “C” key to copy the selected file. You can also use the “A” key to select all the deleted files before pressing the aforementioned key to copy them. Next, the TestDisk utility will ask you to specify a location where you would like to restore the file you copied. Just select a specific directory and folder to recover the file or files.
Step #9: Recover the File from the Ubuntu Partition
Once you’re done selecting the location, press the “C” key again to restore the file in the chosen location. The files you have copied in the previous step will now be restored to the folder you picked. When the recovery is complete, a green text, “Copy Done,” will appear on the screen. This text will also indicate the number of files you have recovered, and if you have failed to recover any selected files.
Please remember that the retrieved files will most likely be in a locked state that only the authorized user, which is you, can open. To make sure there is no problem, log in to the user account that you have used to restore the files using the TestDisk application. Since the file has been successfully recovered from the Ubuntu partition, you can delete the TestDisk utility from your Linux device. To do that, open the Terminal and execute this command: $ sudo apt-get remove testdisk