Recovery Linux Files by Testdisk
You may have deleted a file in Linux, but you need to restore it, in rare cases, you might just get your hand in your new files, but you forgot to back them up. Fortunately, there is a way to restore your files.
Rm Command
One way to restore files can be to use the rm command, but with this command, you have to stare at your computer screen for hours to restore the files, and this is incomplete, in this file recovery process, the operating system will give you access to restore files that you can find by name in the margins of your files, but sometimes you may delete some of your files at the same time as the files you tried to restore. , So it is better to avoid doing this method.
Usually, when you delete your files accidentally, it will often happen to you at the worst possible time, using the upper code can take a long time and this is only when you have backed it up in advance, in case Make sure the deleted file is newly created when it is not given to the system or you to back up.
This is where the test disk module comes in handy, as it is very easy to work with and does not require much knowledge.
Install test disk
To install the test disk on Ubuntu, enter the following command in a terminal:
sudo apt-get install testdisk
In Fedora you have to type the following command:
sudo dnf install testdisk
In Manjaro you must use pacman:
sudo pacman -Sy testdisk
Instructions for using test disk
Although the basic conditions for using test disk will start with the command in the terminal and continue, the test disk module will have a completely separate user interface and you will be able to use the Enter key to look through the menu and options, To get things done better, create a completely separate folder for the files you want to restore.
By executing the following command in the terminal, a folder will be created in your system called restored, you can also create the folder name according to the name you want:
mkdir restored
By entering the following code we will go to a new folder and run the test disk module from there:
cd restored /
We also have to use test disk with sudo, so the command code will look like this:
sudo test disk
The first question that the test disk module will ask you will be about logging in, it does not matter in all the data recovery process, whether your user is logged in or not.
After seeing the user menu in front of you, the first option called Create a new log file will be displayed for you, as we said if you do not already have the information you can create it during processing, click on the option After selecting, test disk will show you a list of all the hard disks in the operating system, and will ask you to select the disk you want to restore. Since all the hard disks in front of you are only capable of reading and viewing them is enabled, access to delete or change is disabled, so do not worry about accidentally deleting them.
If only one hard drive is connected to your system, on systems with newer SSDs or hard disk drives, your hard drive will be identifiable as sds, using the up and down keys on the keyboard. Stop dev / sda and use the right key on the keyboard to click on the Proceed option and press Enter.
Testdisk also needs to recognize the partition model, the module will automatically place a menu of options in front of you that the module itself has selected your partition model, we suggest you in this section to leave it as the way the module made it.
Press Enter to go to the next page, in the next performance menu that will appear in front of you, go to the Advanced option and press the Enter button. For example, the files we want to restore are in the Linux Filesystem partition, but In the case of any system, you may be looking for your file on any other partition. Navigate to the partition you want to recover the file from, use the left arrow key, stop at List, and press Enter.
Use the up and down keys or the PgUp or PgDn keys to move between lists of files, press the right key on the keyboard to enter one of the paths, and use the left key as the exit and return.
In this section, look for the word home, the path of all files in all accounts is home. Here you can look for the file you want, select it using the Enter key, and with the right key you can find all the information Look inside that account, the items shown to you in red are deleted files, now you can search among deleted cases, find the file you want and hit the c key in lower case Copy.
After selecting the file, the items displayed to you will change. On the next page, the test disk will ask you to select a path to save your file. We have already created the Restored path and started the test disk terminal with it. This is the first entry (.), click on it to restore the files and press c to move the deleted items to a new folder.