How to recover deleted files on Ubuntu Linux

Have you unintentionally removed the files from Ubuntu? This article will demonstrate how to recover deleted files on Ubuntu Linux. Everyone has had the experience of accidentally deleting something.

This is why every operating system has a Recycle Bin or Trash where deleted items are stored as a security measure for a while. This makes it easier to recover deleted files. Some people want to hold Shift while deleting things.

This will completely delete the files, skipping the Recycle Bin. If you accidentally delete such a file, or if you accidentally delete something from the Recycle Bin, there isn’t much hope, but there are some. The Linux user can quickly recover deleted files, even in Ubuntu and Linux in general. Let’s see some solutions for recovering a deleted file on Ubuntu.

Recover an accidentally deleted file

When a file is completely deleted, it is still not deleted. The operating system rejects the active allocation of hard disk space to the file and overwrites it if necessary. So, if the operating system overwrites the deleted files, they can still be recovered.

READ ALSO: How to restore your YouTube history

If you are Google, you will usually find tools and guides to recover deleted files on Windows. This is not surprising given the popularity of the operating system. There aren’t that many tools on Linux, but the process is still pretty simple and easy if you can.

Install the TestDisk Data Recovery utility

TestDisk is a free and open-source data recovery utility. Primarily lost data, storage partitions, etc. Use TestDisk to delete deleted files on Ubuntu Linux. TestDisk is a command-line utility that makes it scary for some people. But this file recovery tool is not hard enough to use. All you have to do is open the terminal to get started and start the test disk.

Most Linux distributions already include the tool in their official repositories. Therefore, if you do not already have one, you can easily install the following command in the terminal. If you type “testdisk” into an airport and not installed, you must specify that you enter this command.

 sudo apt-get installer testdisk 

Although we focus on Ubuntu Linux here, “TestDisk” can be used similarly to any other Linux distribution. The above command can also be used for other Ubuntu-based Linux distributions, such as Linux Mint, Elementary OS, and so on. Arch Linux users can install from the AUR, while users of different Linux distributions can follow the link below.

Download link: TestDisk

Run TestDisk on Linux

As mentioned above, TestDisk can be quickly started by simply typing an in the terminal after installing the utility testdisk. Let’s see how to recover a deleted file after running the utility.

Recover deleted files on Ubuntu Linux

After the “TestDisk Data Recovery Utility” starts, a screen similar to the following appears on the screen. Since this is a command-line utility, you need to be careful with the option you choose. Since TestDisk 7.0, the tool automatically highlights the next logical step. This is usually right, but it can also be wrong. It always prints some text, so be sure to read this selection as well.

As shown in the image above, you have the option to create a log file or add information to an existing log file. You can also choose not to create one. Creating a log file can help you find online help in the Ubuntu or Linux forums if things don’t plan out.

Select Disk to check for Deleted Files

After the selection, you must enter the password, after which TestDisk will restart with root privileges. Again, you are prompted to create or skip creating the log file. You can then select the disk from which you want to recover the lost files.

Select a partition table

You will then be prompted to select the partition table, but do not worry because the TestDisk Data Recovery Utility will automatically detect the partition table type and let you know. Therefore, it is essential to read the text that appears.

Select Advanced (optional)

Once you have selected the partition table, it provides all the options for which TestDisk can be used. Yes, TestDisk can be used for many other things except recovering deleted files on Ubuntu Linux. Of course, if you read everything the Terminal showed, you would know.

The options presented can be confusing, but the choice can be pretty apparent if you know what you want. We are not trying to lose a lost partition, so there is no point in parsing the disk. Similarly, we do not try to change the disk’s geometry, modify anything, and so on. The only reasonable choice is a unique option that includes File System utilities.

Delete a file

On the next screen, use the up and down arrows to highlight the drive. Then use the left and right arrow keys to select Undelete and press Enter. As soon as this happens, TestDisk will begin reading the deleted files.

Delete deleted files

When you have finished scanning, TestDisk displays a list of deleted files to recover. Select the file you want to recover with the arrow keys and press c on the keyboard.

You can then use the arrow keys to select exactly where to save the recovered file. You now need to know the input and selection process.

The default setting is to recover deleted files in the home folder, which is usually the best choice because navigation within the command-line utility can be cumbersome. It will be much easier for most users to later navigate to the home folder using the file manager and place the file wherever they want.

As shown in the image above, the selected file has been restored to the selected location. After the first file is recovered, TestDisk returns it to the file selection screen. Here you can choose the file you want to recover and press “ c” again to recover the deleted files you want to restore.

When done, you can close the terminal window. If you press q to exit or Exit TestDsik, you will not end the program. It simply works as a step backwards. This can be useful if you find yourself somewhere in the command line utility where you don’t want to be.

Alternative solutions for recovering deleted files under Linux

For those who don’t want to depend on this free tool, there are many other Linux tools for reading and recovering a deleted file.


Foremost can be installed on any Debian-based Linux distribution, such as Ubuntu and its derivatives, such as Linux Mint. The command to install is listed below.

 mostly Sudo apt-get is installed 

After installing Foremost, create a folder where you want to restore deleted files.

 mkdir / root / restored

Now run the most critical command and restore the deleted file. In this example, we will fix all deleted JPG files. This is primarily possible with the following step in a single step.

 mainly -i / dev / sda3 -t jpg -o / root / restored / 

The above command finds the deleted jpg files on the / dev / sda3 partition and restores them to the created folder. Similarly, you can restore other types of files. For the full list, see the Linux page.


Scalpel is a file system-independent recovery tool for Linux and Mac OS. It can also be installed on Windows using MinGW. For Ubuntu and its derivatives, you can install it using the command below.

 sudo apt-get install scalpel

If it is installed, locate the / etc / scalpel / folder and open the scalpel.conf file in the text editor of your choice. You will notice that everything has been memorized in the file. You must remove the type of file you want to restore. Save the file if you have done so. The command to restore a deleted file is given below.

 sudo scalpel [device / directory / filename] -o [output directory] 


Photorec is the most straightforward utility to use the bunch mentioned above. Moreover, even the testdisk utility installs it, so if TestDisk doesn’t do it for you, you’ll already get another easy-to-use tool. Like TetDisk, Photorec includes a text-based user interface, but you do not need to use actual commands with the aforementioned tools. Use the following command to run Photorec.

 sudo photorec / dev / sda3 

Here / dev / sda3 is the partition you want to delete. You will then see a text interface similar to TestDisk where you need to select the disk. After selection, you must specify the partition table type. Use the up and down arrow keys to highlight and use the left and right arrow keys to highlight the search, then press Enter.

If you do this, you must select the file system and then an output folder where you will store the recovered files. This is the same as TestDisk. It also asks if you want to scan the entire disk or just the free space. Selecting to check the whole disk will be more time-consuming.

Digital storage has been a blessing for professionals and even the public. The world has more than 7 billion people, most of whom create new documents and take new images unprecedentedly. All of them physically retaining would have been a driving nightmare. Not to mention, physical copies can be accidentally damaged or lost in several ways.

Digitally stored files can be accidentally deleted or lost. And luckily, you can recover, and there are plenty of built-in solutions and tools available to recover deleted files on Linux

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button