Pin Me

Recovering Excel Files in Linux

written by: Chad Anderson•edited by: Eric Stallsworth•updated: 10/26/2010

Losing important documents - especially spreadsheets - can be a big hassle and really interrupt work flow. Using PhotoRec - an open source tool for Linux - you can quickly recover lost documents.

  • slide 1 of 4

    So you got a little to hasty with the "rm" command, maybe tagged on the deadly "-rf" tags, and lost those spreadsheets that are due tomorrow? Don't panic! Linux doesn't come with the usual "recycling bin" where you can go to un-delete your files with ease, but there are a number of tools for data recovery. Furthermore, if you are looking to just grab specific file types, there is an amazing utility called PhotoRec. PhotoRec runs through file headers to determine the file type before yanking it off the disk and restoring it. The advantage of this is that PhotoRec can recover files from a corrupted file system or partition with ease. The only downside is that you will probably find yourself with every spreadsheet you've ever deleted by the time PhotoRec runs its course.

  • slide 2 of 4

    Recovery Preparation

    There are a couple of steps that you will want to take before you hop into recovery. First, PhotoRec recovers files by copying them to a recovery directory. You do not want to put this directory on the same partition you are recovering from since PhotoRec may overwrite other files it is trying to recover. You will want to create a folder on another partition, plug in an external hard drive, or set up a networked storage solution to copy the recovered files to. Secondly, you have to run PhotoRec as the root or superuser in Linux. Use the "su" command to gain superuser access or log out and re-login as the root user. Lastly, you will want to install PhotoRec on your system. This is pretty straight forward, but you will want to use your distribution's package manager to search for "testdisk" instead of "photorec" since the PhotoRec application comes bundled with the TestDisk partition checking tool.

  • slide 3 of 4

    Recovery Settings

    Once you have your recovery drive set up and have a root terminal open, go ahead and run PhotoRec by simply typing "photorec" and pressing "Enter" without any extra parameters. As always, you could preface the application with the "sudo" command to run it as root. When the program launches, you will need to select which physical disk you want to recover files from.Select Media  All of your hard drives should be in this list.

    Once you've selected your hard disk, you will be asked to select the partition table type. PhotoRec does this automatically for you, but you should check before hitting "Enter" just because the automator could be wrong.

    Before selecting the partition table you want to recover files from on the next screen, select "File Opts" from the list to bring up the file type selection menu. Press "s" to disable all file type families and then scroll down and select the "doc" option to restrict recovery to only Microsoft Office Documents, including doc, xls, and ppt files. Press "b" to save the settings and then "Quit" back to the partition selection menu. Select your partition from the list.

    File System Selection Next, select the partition's file system type. This will most likely be the "ext2/ext3" option, since you are running Linux, but you may see "reiserfs" or one of the more advanced, journaling file systems that some distributions offer. This should be automatically detected by PhotoRec as well, but double check, just in case, before you hit "Enter" to continue. Next, select if you want to search the "Free", unallocated portion of the partition or if you want to search the "Whole" partition, including unerased portions.

  • slide 4 of 4

    Finishing Up

    Finally, select where you want to save any recovered Excel files. This will need to be on another partition, an external hard drive, or a networked solution that you set up before. Make sure that you do not save recovered files to the same partition they are being pulled off of. This could really mess up your hard drive.

    Complete Once you've selected where you are going to save the selected files, PhotoRec will go to work and start scanning your partition for the missing Excel files. This process could take several minutes to an hour, depending on your hard drive's size.

    PhotoRec will display a list of results once the recovery is complete and you will be able to open your file manager and navigate to the recovery folder to open and view your Excel documents.