1

I just wrote an important text and stored it as a simple text file. Then i accidentally cut out the content (with Ctrl+X) when i just wanted to copy it, and saved the file. Now it is of course empty. Is there any possibility to get the content back? Any help is very much appreciated, it really took some time to write it.

  • Without knowing how you "cut" the text there's little chance to offer a solution. Please edit your question to provide the missing information. (Remember that we didn't see you do it, and we don't know anything about your computing environment.) – roaima May 24 '16 at 21:57
  • I was able to restore it but thank you for your comment :) – divandc May 24 '16 at 22:20
  • I tried to but there's a message that says i can't do it before tomorrow. Will do it then – divandc May 25 '16 at 12:39
4

Solved it with help of the accepted answer here: Can overwritten files be recovered?

For larger files that may be in multiple non-contiguous blocks, I do this:

grep -a -b "text in the deleted file" /dev/sda1 13813610612:this is some text in the deleted file which will give you the offset in bytes of the matching line. Follow this with a series of dd commands, starting with

dd if=/dev/sda1 count=1 skip=$(expr 13813610612 / 512) You'd also want to read some blocks before and after that block.

I needed to set count to 10 to get my entire file, has to be chosen by file size.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.