The Best Ways To Recover Data On Linux

Danny Stieben 06-04-2013

recover data on linuxNo 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 command sudo 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 The Best Linux Software and Apps Whether you're new to Linux or you're a seasoned user, here are the best Linux software and apps you should be using today. Read More , 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 Ubuntu: A Beginner's Guide Curious about Ubuntu, but not sure where to start? Everything you could possibly need to get started with the latest version of Ubuntu is right here, written in easy-to-understand, plain English. Read More . 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!

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Marje Kimberly
    December 27, 2016 at 9:20 pm

    All of a sudden my videos will not play, and I've done nothing different to my Linux (cinnamon) system. I don't know where to begin to get my videos back.

  2. Darren Price
    December 27, 2016 at 2:36 am

    Surprised you missed out on MorpheusArch Linux since its got photorec and testdisk installed by default.

    • Mark Vance
      November 2, 2017 at 8:23 pm

      Yeah its even got a desktop envioronment now. No more dealing with the terminal!

  3. David Moreira
    May 11, 2013 at 6:36 pm

    This came in pretty handy, thanks.

  4. Michel
    May 5, 2013 at 11:11 pm

    I hate Linux & Ubuntu I installed it on my Dell >what a mistake that was< the freekin thing doesn't want to uninstall so what do I do....delete any file that as something to do with Ubuntu, Big No No now I have a dual boot but only one OS that I had to build up from scratch, theres nothing human about Ubuntu if you ask me its a bunch of crap pure and simple
    Q: how in the world do I delete this ''dull'' boot even tough Ubu what you ma call it from my PC ?

  5. Mai Shun Han
    April 12, 2013 at 8:22 am

    WOW!!! Didn't know that there's such recovery tools... :D

  6. Joel
    April 12, 2013 at 7:27 am

    Hey Danny Very Impressive post about recovering data on Linux.I wanted to know if these tools work on any flavor of Linux?Thanks for sharing such a great post

    • Danny Stieben
      April 29, 2013 at 3:43 am

      They definitely should!

  7. Oliver
    April 8, 2013 at 4:41 am

    Using Linux recovery software is bit tricky as most of them need to run using commands. So novice users might face difficutlties while recovering their precious data.

    Though, Stellar Phoenix Linux Recovery software is made for users from basic to advanced and will run only in GUI mode. At the end, you'll have pretty fast and flawless recovery experience,

    Thanks for your useful article though.

  8. Aungmyo H
    April 7, 2013 at 4:35 pm

    Can you post "how to make Java, MySQL, and Eclipse configuration in Ubuntu." Because I am totally new in Ubuntu. And I hope your post will be good pointer for me.

    • Danny Stieben
      April 29, 2013 at 3:43 am

      I'm not very experienced in those, sorry!

  9. Nevzat A
    April 7, 2013 at 9:02 am

    Linux rocks as a portable recovery option!

    • Danijel C
      April 10, 2013 at 7:38 pm

      It rocks in many other things too :)

      • Nevzat A
        April 10, 2013 at 7:40 pm

        definitely :)

  10. Chris Marcoe
    April 6, 2013 at 11:43 pm

    As someone who is just starting to p[lay with Linux, these are invaluable. thank you for these tools.

  11. Danijel C
    April 6, 2013 at 7:15 pm

    All these are only command line tools, or available with GUI?