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.
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.