How to restore a deleted file on Debian

Everybody already had to deal with an accidental file deletion on their computer. Usually, no drama, digging into the trash is enough to restore the file.

Alias rm ( heal… )

Under Linux, command rm is a command of irreversible deletion. In order to minimise the risk of inadvertent file deletion, we are going to force the prompt of the system to confirm any deletion.
This way we are going to rewrite the alias of command rm with argument -i :

Now, command rm is automatically substituted by rm -i, and by this way, you will have a confirmation request at each use of this command.

Foremost ( … prevent )

If, despite the confirmation request, you inadvertently deleted the file, the Foremost tool can help you :

Let’s imagine that you deleted the file /boot/images/file_deleted.jpg, you just need to launch this command :

The Foremost tool will then search for jpg-type files deleted on partition /dev/sda1 matching with folder /boot/images where the deleted file was placed to restore it in the folder /home/folder/restoration.

In the example, we can imagine that directory /boot is on partition /dev/sda1 and directory /home is on partition /dev/sda2.
It is actually important to restore the file in a different target partition from the original one in order to avoid taking the risk of writing on disk sectors previously used by the file to restore.

By using Foremost, you have to notice that :
– This tool is not a guarantee of results and the process will not always allow your files to get successfully restored,
– You have to stop any other activity before launching the process to avoid solliciting your hard disk during the restoration.

Above all, the concept you should embrace is to remain vigilant while using the command rm.

How to restore a deleted file on Debian