According to Canonical, the creators of Ubuntu, there are 25 million users at this time. Surprisingly, this Debian-based system is ranked third among PC operating systems worldwide. Consequently, when this many users are storing, exchanging, and sharing data for business and personal use, there are possibilities of data loss.
If you ever wanted to bring a deleted file back, we can presume you might have deleted it accidentally. It’s an unspoken rule that even if you regularly backup your data and remain careful not to erase crucial files by accident, sooner or later, you’ll wind up in a scenario where you lose data that wasn’t backed up. The precautions you took, as well as some outside help, will be invaluable methods to recover your deleted files in Ubuntu at that time. Let’s start.
Recovering deleted files in Ubuntu via Trash
If you have deleted a file, it will end up in the Ubuntu Trash. We have already gone over the recovery of Trash data in Ubuntu. But there’s something else you can try to retrieve a specific file:
- Open a Terminal window and run the command: sudo trash-put <filename>
- Enter your user account password when prompted, and the file will be restored to its original location.
Get your Ubuntu files back from a backup
Have you backed up your files to a storage drive previously? You can also restore them by following these steps:
- Open the Terminal and type this command: sudo mount -o rw,remount/
- Type your user account password when requested.
- Run the command: sudo cp <filename> /media/<backup_location>
- Do the same as in step 2 and the file will be sent back to the original location.
Employ third-party recovery tools to recover deleted Ubuntu files
First, there are a few things you need to understand before using recovery tools. Ubuntu, for example, uses journaling file systems like ext4. A journaling file system is named because it maintains a log of files that are stored on your hard drive. Put another way, consider your file system as a neighborhood and the journal as an address book. When you remove a file on Linux, it’s like removing its listing from your address book. The file itself is not deleted from your journal.
Data remains in place until another piece comes along and overwrites it. Erasing a file is similar to crossing an address out of your address book without actually razing the structure it relates to. The structure will remain there until someone builds a new building on its site. You’ll be able to discover the deleted files if someone has not overwritten them.
In a nutshell, Ubuntu restoration tools inspect your file system for telltale signs of data removal that still exist on the disk. There’s a good chance you’ll be able to undelete the deleted data if you deploy the tool before something overwrites the data. With that said, here are a handful of Ubuntu recovery tools you can use. Keep in mind that we have no affiliation with them and are merely giving examples.
1. Extundelete
Extundelete is a relatively new data recovery program for ext2, ext3, and ext4 file systems, although it is built on existing technologies such as ext3grep. It’s an easy-to-install tool from the software repositories of most mainstream Linux distributions. Type the command sudo apt-get install extundelete to install it. With that done, unmount the partition where your deleted file was kept, if possible. Extundelete worked with mounted partitions for us. However, the program gives an error if you do so because it might result in the loss of other data on top of your deleted files. If you use the tool on a mounted partition, proceed at your discretion and responsibility.
Have you deleted files on the Ubuntu system partition that you can’t unmount? You certainly don’t want to risk it by running the tool from a mounted partition. Therefore, you may shut off the system, boot to a Live CD or USB, and run extundelete from there. Next, run extundelete command to restore the deleted files like this: extundelete /dev/sdb1 –restore-file deletedfile.txt
Here, “/dev/sdb1” is the partition where the file was, and “deletedfile.txt” is the name of the file you erased. You can use the –restore-all flag if you don’t know the name of the file, or you want to recover multiple files. For example, extundelete /dev/sdb1 –restore-all
2. TestDisk
TestDisk is also a reliable program to recover deleted Linux files from the system. You can install TestDisk on Ubuntu using the command: sudo apt-get install testdisk. Launch it by typing “testdisk” in your terminal. Testdisk should begin by asking how you want to manage the testdisk logs (which is fine), followed by what you want to recover. Choose the Advanced option instead. Now:
- TestDisk will show you a list of detected disk partitions next. Choose the one where your deleted data was located.
- Select it, then pick the Undelete option at the bottom of the screen.
- Go to the screen where you can view deleted files and select which ones you wish to restore. Follow the directions on the screen for listing erased files and selecting those you want to restore.
TestDisk can also restore removed files, damaged partition tables, and boot sectors. This comes in handy if your disk structure has been destroyed, and you can’t boot, or the system can’t find all your partitions. These features are out of the scope of this article, but they’re a lifesaver for people who make serious mistakes with their disks.
3. PhotoRec
This tool is yet another solution to recovering deleted Ubuntu files with ease. For Ubuntu users, the PhotoRec software is included in the TestDisk package. You can also install it using the command we mentioned above. Run it by typing photorec in the Terminal.
PhotoRec works similarly to TestDisk, with one exception: it will prompt you to select the partition where your removed items are stored. It will then guide you through the discovery and recovery process.