in

How to Recover Deleted Files in Linux

- - 4 comments
Oops! You accidentally deleted files that you were supposed to submit in 2 hours! Trust me, even the smartest of geeks have been in such situations. And yes, it’s not the lack of technological savoir-faire that puts people in such tough spots; it’s just the general clumsiness and nervousness in certain situation that makes us make such blunders.

On Windows and Mac, you can simply Google for it and you’ll find a plethora of sharewares and freewares that will help you recover files. However, on Linux, there’s a dearth of such applications thus making it harder for new users to get back the files they deleted. Don’t worry though, as we at TechSource have listed a simple method of getting back the stuff you lost without going through hoops. So, without much ado, here’s how to recover deleted files on Linux:

PhotoRec is a free and open-source application that lets you recover lost files from hard disk, digital camera and CD-ROM. It can help you get back lost videos, documents, and photos from your digital card memory. The application works equally well even when the file system is severely damaged or even formatted, thus making it one of the best hard drive data recovery tools for Linux.

To get started, simply install PhotoRec by typing in or pasting the following command in your terminal (Ctrl + Alt + T):

sudo apt-get install testdisk

The program is around 650 KB, so it wouldn't take much time to install even on slow connections. Once installed, type in ‘photorec’ without any quotes. The program has an ncurses UI, so there won’t be any need to type in commands, simply navigate the interface using the arrow keys and punch in the return key to select a menu.


Firstly, select the hard disk from which you want to recover the files from. If you can’t recognize your hard disk easily, just look at your laptop or desktop’s manual and see the amount of hard disk space your computer has. Now match that space with the options mentioned in the list and select the correct one. Hit proceed and the app will then ask you to choose the file system. If you have fewer partitions, you won’t have much trouble identifying the right one; however, in case you have many disk partitions like me, then you’d have to guess the right one by its size. Simply look at the column that denotes the size of the partition in sectors. Then, match it approximately with the disk in which your lost data was stored.


Once that is done, choose an output folder wherein your recovered files will be stored. Now, sit back and relax as your precious file return to where you want them to be.

Note: It’s always better to backup your data instead of scrounging around for recovery solutions. We've already covered some of the best backup solutions for Linux. These are all open-source applications and most of them don’t require the use of the dreaded command-line.


Written by: Abhishek, a regular TechSource contributor and a long-time FOSS advocate.

4 comments

  1. AnonymousJune 11, 2012

    What about other distributions which don't use apt-get command to install stuff? This is only for Debian/Ubuntu-based distributions.

    ReplyDelete
  2. AnonymousJune 11, 2012

    check your distro documentation

    ReplyDelete
  3. AnonymousJune 17, 2012

    This article is way too simplistic as an overview - to the point of being harmful. Photorec is just as likely to restore file fragments with obscure file names and there are key decision points that need some prior knowledge to navigate.

    ReplyDelete
  4. You missed an important step for recovering deleted files on Linux: First you need to go back in time to when you first installed the operating system, and use the ext2 file system instead of the ext4 file system that is default for all modern Linux distros.

    Granted, you will have problems with fragmentation and file corruption, because ext2 is not a journaling file system, but that's the price you pay for making the how-to actually work.

    ReplyDelete