Introduction
Accidentally deleting important files can be a stressful experience, especially on a robust system like Ubuntu where the command line is often involved. In this tutorial, we’ll explore various methods to recover your lost files on a system running Ubuntu Linux.
Before panicking, it’s crucial to understand that when files are deleted, they aren’t immediately removed from your hard drive. Instead, the space they occupy is just marked as available for new data, which means quick action can often result in successful recovery.
Method 1: Use the ‘TestDisk’ Tool
TestDisk
is a powerful open-source tool that can recover lost partitions and non-deleted file recovery.
Installation
sudo apt update
sudo apt install testdisk
File Recovery
sudo testdisk
Follow the on-screen instructions to select your disk and the partition table type, usually the default. Navigate to the Advanced file recovery option, select the partition containing your deleted files, and choose Undelete. Browse through the recoverable files and select the ones you want to restore.
Method 2: Use the ‘PhotoRec’ Tool
PhotoRec
is often bundled with TestDisk
. It focuses on recovering lost files including videos, documents, and archives from hard disks, CD-ROMs, and lost pictures from camera memory.
Recovery with PhotoRec
sudo photorec
Select the disk, then the partition. Choose the filesystem type and where recovered files should be saved. Then let PhotoRec
work its magic.
Method 3: Recover from Trash
If the files were deleted from within a graphical environment, they might just be in the trash can. Open the trash and look for your files. You can right-click and select Restore to move the files back to their original location.
Method 4: Use ‘Extundelete’
For ext3 and ext4 file systems, extundelete
is helpful.
Installation
sudo apt update
sudo apt install extundelete
Recovery Usage
sudo extundelete /dev/sdxn --restore-all
Replace /dev/sdxn
with the appropriate partition identifier. The recovered files will be placed under the RECOVERED_FILES directory.
Final Thoughts and Best Practices
Timeliness is crucial in data recovery scenarios. It’s also vital to routinely back up your files and to use tools like rsync
or Deja Dup
available in Ubuntu repositories. The chances of recovery depend greatly on not writing any new data to the affected partition.
Data loss can happen to anyone, but with the proper knowledge and tools, you can recover those precious files on Ubuntu Linux.