How to Use RecoverPy to Rescue Deleted Files on Linux
Accidentally deleting a file on your Linux system can completely ruin your day, and wreck your productivity. While there are dedicated tools and even complete distros for recovering accidentally erased files, RecoverPy is the quickest and easiest way to recover deleted files on Linux.
What Is RecoverPy, and Why Would You Need It?
It’s important to keep your Linux filesystem clean and uncluttered. Junk left over from scrapped packages, aborted projects, and seldom-used apps builds up over time. Before you know it, you’re completely out of space. Services fail to start, and your shell doesn’t work like it’s supposed to.
While you can root through your directories one at a time and inspect each file before selecting for deletion, it’s more likely that you’ll use one of the many excellent system cleaning apps available for Linux. These apps have an intuitive interface and allow you to delete files from multiple directories at once.
Disaster! In your rush to reclaim vital disk space, you’ve accidentally erased your almost-finished Ph.D. thesis, scanned copies of your wedding certificate, and numerous news articles you were saving for posterity.
After you’ve finished punishing yourself for failing to properly maintain an effective backup schedule, it’s time to get your files back!
RecoverPy is a powerful Python app, that leverages your system capabilities to recover lost files and even files that have been overwritten. Unlike better-known file recovery utilities such as Testdisk, which can be daunting to use, RecoverPy is designed to be straightforward.
The app can scan your whole system and locate strings in filenames, headers, and even inside binary files you might not otherwise have thought of. Best of all, RecoverPy boasts an intuitive and attractive terminal user interface (TUI), which makes it simple to recover deleted files on Linux.
How to Install RecoverPy on Linux
As RecoverPy is a Python app, you need to have Python installed on your Linux system. Check if you have it installed by typing this command into any terminal:
If you don’t have Python installed, then follow our instructions on how to install Python on Ubuntu.
RecoverPy depends on lsblk to gather information on block devices, grep to search and match patterns, dd for reading and writing files, and progress to give you an indication of how the search is going. You can install all of these dependencies on Debian-derived distros with:
sudo apt install grep coreutils util-linux progress
On Arch-related systems:
sudo pacman -S grep coreutils util-linux progress
Or on the Fedora family with:
sudo dnf install grep coreutils util-linux progress
Now you can install RecoverPy with:
sudo python3 -m pip install recoverpy
You’ll have noticed that we took the unusual step of installing the Python package using sudo, instead of as a regular user. This is because to search the filesystem, RecoverPy needs to be either run as root or invoked using sudo. Installing the package using sudo can prevent confusion later on.
Use RecoverPy to Rescue Deleted Files on Linux
Before you launch RecoverPy, it helps to know as much about your missing file as possible. A filename is a good start, and if you search this way, RecoverPy will also turn up entries from your shell history, deleted browser history, and more.
Other handy details to have include the file creation date, and if you’re looking for a deleted photograph, the model of the camera. These details are usually included in image file headers and can help you to locate your lost file.
For demonstration purposes, we created a file called “testdoc”, pasted a BBC news article in, saved it, then used rm to delete the file.
Ideally, you should unmount the partition you intend to search and run RecoverPy from a separate partition to prevent any further alteration to your lost file.
Start RecoverPy with:
sudo python3 -m recoverpy
…and enter your search string into the search box.
Use the Tab key to switch to the “Available partitions” menu, then the arrow keys to choose which partitions you want to search. When you’re happy, hit Tab again until “Start search” is highlighted, then Enter to start the search.
RecoverPy will keep you updated with progress, and when it’s completed, you’ll see a screen full of results. As you can see in the screenshot, these can relate to scraps of commands, file operations, search strings, and more.
It’s far better if you know something related to the file contents. For our next search, we managed to recall a few words of text from the file, and a few minutes later, RecoverPy narrowed down the results to one candidate.
Press Enter to select the entry you want to inspect, then on the next screen, decide if this is the deleted file you want to rescue. If it is, press Tab twice, then Enter to select “Add Block”, and Tab twice more, then Enter to save the file to a new location.
It’s that simple.
Recovering Deleted Files on Linux Is Easy With RecoverPy
Now you know how to quickly and simply recover deleted files on Linux, you don’t need to worry about accidentally erasing important documents. For extra piece of mind, consider storing important files online with affordable cloud storage.