Recovering deleted files or folders from a server can be a complex task, especially if the server is not set up with a trash or recycle bin system. Here are some general steps you can follow:
If the files are deleted using rm -rf
then forget about them and focus on not repeating the mistake.
As soon as you realize that you've deleted a file or folder, stop using the system. When a file is deleted, the space it occupied is marked as free and can be overwritten by other data. By continuing to use the system, you risk overwriting the deleted files and making them unrecoverable.
There are several file recovery tools available for Linux systems. One of the most popular is extundelete
.
To install extundelete
, use sudo apt-get install extundelete
Use the lsblk
or df
command to identify the device identifier of the hard disk or SSD.
Use the umount
command to unmount the device. This is to prevent any further changes to the data on the device while we are trying to recover the deleted files.
# Replace /dev/sdb2 with your actual device if it's different.
umount /dev/sdb2
Run fsck
on the filesystem with sudo fsck /dev/sdb2
to fix any issues that fsck
finds.
Use this command to recover a deleted directory:
sudo extundelete --restore-directory /path/to/deleted/directory /dev/sdb2
This option will attempt to recover all deleted files from the filesystem. Be aware that this could recover a large number of files and take a long time.
sudo extundelete --restore-all /dev/sdb2