The Best Ways To Recover Data On Linux

No matter whether it was your fault or not, things can happen to the data stored on your devices. Hard drives, solid state drives, and removable media can all potentially “lose” files because of numerous different causes. Additionally, sometimes you may delete a file – no matter if on purpose or by accident – and then determine later on that you actually need it.

Instead of freaking out over the fact that the file appears to be gone, it may be a better idea to try a file recovery tool first to recover data on Linux.

How Does File Recovery Work?

File recovery tools work on the fact that, although systems may recognize a file as “deleted”, the data may still be physically present on the storage device. For example, modern file systems determines whether space is “free” or “taken”, and can declare a space to be “free” although the data is still technically there. It simply allows the new free space to eventually be overwritten with new data.

File recovery tools can scan through the storage device to see if it can find any files that are physically still on the device, even if the file system claims that it’s gone. There are plenty of these tools available under Linux, but here are some that I recommend the most.


recover data on linux

Safecopy is a rather simple data recovery tool which simply copies data to a new location. As such, it doesn’t recover individual files, but instead is a way to copy data off of a failing device.

The difference between this utility and a normal copy command is that Safecopy doesn’t quit at the first sign of file corruption, whether it be from a bad write operation or a damaged sector. There plenty of additional options to customize what the utility actually does, including the ability to create a filesystem image from damaged media, recover data as thoroughly or quickly as possible, combine data from partial sources rather than a single source, and access RAW (unpartitioned) areas of your storage media.

The utility can be installed by searching for Safecopy in your distribution’s repositories. Ubuntu users can also run the command sudo apt-get install safecopy. Once installed, you can recover files from partition X on drive “a” and write them to a pendrive with the commandsudo safecopy /dev/sdaX /media/PENDRIVE_PATH/recovery_image.


linux data recovery

TestDisk is a different kind of data recovery tool because it doesn’t try to copy data off a failing device, but instead can fix some partition-level issues that may be messing with your data. The utility helps recover lost partitions, make disks bootable again, fix the partition table, restore the master boot record, restore boot sectors and filesystem tables, undelete files from NTFS, FAT, exFAT, and ext2 filesystems, and copy files from deleted NTFS, FAT, exFAT, and ext2/3/4 filesystems.

The different commands for accomplishing all of these will vary widely, so it’s best to look at the utility’s documentation before getting started or look at the program interface carefully. However, it has a very nice set of features that is sure to help a lot of people get their data back onto safe hands. You can install the utility by searching your distribution’s repository for testdisk. Ubuntu users can also run the command sudo apt-get install testdisk.


recover data on linux

Last but not least, if you’re focusing specifically at looking to recover videos, documents, and archives, you should check out PhotoRec. The advantage of PhotoRec, however, is that it completely ignores the file system and looks at the underlying data, which means it’ll still work if the device has been damaged or reformatted.

To prevent any issues from arising while using PhotoRec, it uses read-only access to recover the data – that way it won’t accidentally overwrite something that you may have been looking to recover. Just note that with PhotoRec, you’ll need to stop all writing operations immediately after you have the need to recover a file. Otherwise, the possibility exists that the underlying data will be overwritten with something new, making recovery impossible.

Again, there are plenty of options to look at while using this utility, including the selection of file extensions which you’re going after, so it’s best to look at the documentation for correct usage or look at the program interface carefully. In order to install, you’ll need to search for either the testdisk or photorec packages in your distribution’s repositories.

Some distributions, such as Ubuntu, combine the two programs into one package as they come from the same developer. Therefore, Ubuntu users can also install it using the command sudo apt-get install testdisk.


These three recovery tools should cover a broad range of data recovery needs, but undeleting files to copying over data that may be found on damaged media. Just be sure to look at the documentation for each of them carefully so that you’re doing exactly what you need to. As there aren’t many tools with graphical interfaces for system tasks, these will run solely through the terminal. Thankfully, TestDisk and PhotoRec have a terminal interface, which is still better than being driven by commands only.

Also, in case you didn’t know, all three of these tools to recover data on Linux are featured on our Best Linux Software page, along with loads of other great programs. Plus, if you’re new to Linux, then you should probably check out our guide on getting started, or even our guide specifically targeted at Ubuntu. Finally, if you need any help, just comment below or submit a question at MUO Answers!

What are your favorite data recovery utilities? Any tips on common issues or workarounds? Let us know in the comments!


post: By Danny Stieben


      • The Big BOSS

        well…I’m doing the same…but I asked for that and they said it’s okay if I :
        1- keep the Author name
        2- do not hotlink the images in the article(they mean to download it to your server then upload it again)—-when I asked why not to hotlink in another site…they said that :it cost the site money
        thanks….It’s just an advise I wanted to share 😉

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s