By accident, I used rm on a file I didn't want to delete. Is there a way that I can get it back under Linux?
|
|
||||
|
The following are generic steps to recover text files.
Found at http://www.cyberciti.biz/tips/linuxunix-recover-deleted-files.html |
|||||||||||||||||||||
|
Edit: sometimes |
|||||||||
|
|
|
||||
|
|
|
Testdisk has an undelete option that should work with Linux. There is a walkthrough for Linux. Note that it works for ext2, ext3, and ext4. |
|||||
|
|
If it's the standard rm, I hope you have a backup. The procedure to recover a deleted file would be different for each file system, if it can be done at all. Linux doesn't have a built-in "recycle bin"; once you delete a file, it's all but gone. Any way you do it, you'll want to unplug the computer -- as soon as possible, as continuing to run the computer (even to shut it down) causes writes to the disk and increases the chance that some blocks formerly occupied by the file will be overwritten. Once you've done that, either put it in another computer, reboot off a live CD (making sure not to mount the drive unless you mount it read-only), or remove the hard drive and take it to a data recovery specialist. |
||||
|
|
|
||||
|
|
|
I did this a couple of years ago. My approach was to directly, no time to lose, unmount partition and then
to have a backup file of the exact state of the partition. Then you can mount the partition again and continue with business as usual as you search for the the deleted file in your created image. The image will probably be VERY large since you need all the "empty" space, so it might be a practical problem to store it. Then it was just to perform boring searches after text snippets I expected to be somewhere in the soup of partition content. E.g. to find .tex-files, I ran
which printed a large context around the phrase "subsection" and saved the output to a file to be manually searched through. I printed such a large context since it took such a long time to search the image that I'd rather not do it more times than I had to. Also the command To find binary files in the same way, one might have success in finding a characteristic header or something of a certain file, but I imagine it to be a rather big adventure. Brief technical notes: there are technical difficulties with disk recovery and Ext3/4. It is a long thing to explain, but briefly (and inadequately): Ext3/4 removes the "markers" that tell the OS where files are located on disk when you delete them. The files aren't scrubbed, but no one knows where on the disk they start and end anymore, and sometimes they even are fragmented at several places. Some other file systems just set the files' statuses to "deleted", but keep the location data. Then undelete is not harder than to look at file pointers with this flag (they should still be available if not too much activity has occured), and then hope their content has not been overwritten. What is best? Rhetorical, in my view. Frequent backup is the answer to all these problems. Important data without an automated backup system is an accident waiting to happen, IMHO. Obligatory personal anecdote: I was going to remove
, which sadly, since
I pressed Enter and sat there looking at the command, which should have taken a second at most. After a bit longer time |
|||
|
|
|
Set your expectations low. If anything was written over the 'deleted' data, you will lose it. I have done a small amount of recovery and the best tools I found were often designed towards certain formats. For example 'photorec' was great when I wanted to get tens of thousands of jpegs recovered. Recuva has also helped me before now and might be your best choice. (Its free, don't get tricked into paying by their ads) At the end of the day, if what you lost is important, take the drive offline and stop writing to it. Use every piece of recovery software you can find until you get your data back or it stops being worth it. If its really important, send it to professionals at a high price. If you've had luck with a tool before, try it again seen as you're familiar with it. At the end of the day, they shouldn't be writing to disk and so you can use software until you find one that works. |
||||
|
|
|
The "correct" answer is to assume there isn't a method to reliably recover, and instead restore from backups or a cloned system or reinstall. TestDisk is a great tool, and there are other ways of being able to salvage some data from the physical drive depending on file system and recency of deletion, but the time and pain involved can be just too great, so KEEP BACKUPS (and also test that they are valid and restorable)! |
|||
|
|
|
Here is a great document for you. You will find a load of practical tips there. BTW, there are two groups of people:
Congratulations, you just promoted yourself to group 2. ;-) |
||||
|
|
|
If you have an application open which is currently reading the file, such as VLC or LibreOffice, then this terrific L&U.SO answer helped me out of this mess. Here is an alternative method for doing the same. The general idea is to find the link in |
||||
|
|
|
If accidentally you have deleted the file from Linux then you can use this command:
in place of |
|||||
|
|
I had the same problem last week and I tried a lot of programs, like debugfs, photorec, ext3grep and extundelete. ext3grep was the best program to recover files. The sintax is very easy:
or:
This video shows is a mini tutorial that can help you. |
|||
|
|
rmis a "dangerous" UNIX/Linux command (read$ man rm). Use it with extreme caution. With that said, it is a quick way to delete files you are sure of. Modern Linux and Unix Desktop Environments do provide with a solution of "Trash Can", so the user easily can recover accidentally deleted files. – Jose Elera Jan 21 '13 at 8:23