Sadlly, I compiled a .c file with the following command:
$ gcc a.c -o a.c
so a.c became the executable file covering my old c file... I want to ask can i have the real a.c file back and how ?
Sadlly, I compiled a .c file with the following command:
$ gcc a.c -o a.c
so a.c became the executable file covering my old c file... I want to ask can i have the real a.c file back and how ?
Unfortunately, that's close to impossible, unless you're adept at reverse-engineering binary code, AFAIK.
You can restore it from a backup, or you can restore it from your source code control system.
If you have neither of those, you should start using both (and now you know why!).
You may also be able to recover the file with file recovery tools for the OS you are using, or failing that, you may be able to decompile the object file. Here is a decompiler:
http://boomerang.sourceforge.net/cando.php?hidemenu
That was the first one on the list after searching Google with "c decompiler".
Here's a stackoverflow question about decompilers.
When you overwrite a file, the operating system does not physically put the data exactly in the same spot, it simply marks the old data as available for use, and writes the new data to the disk. It might overwrite your file, it might not. Midnight commander has a tool that can try to get your file back.
Currently the Midnight Commander is packaged with some Virtual File Systems (VFS): ... the undelfs, used to recover deleted files on ext2 file systems (the default file system for Linux systems)
In the mean time, you should probably not save any other files on the computer, especially in the directory your deleted file is in.
EDIT: By the way, this is an old article, linux hasn't used ext2 for a while. But I think it should still work.
grep
is a great tool to recover lost C files.
grep -a -B 25 -A 100 'some string in the file' /dev/sda1 > recover.txt
The above command recovers the lost text 25 lines before and 100 lines after the 'some string in the file' line in your C file and outputs the recovered text in in recover.txt
file.
So you can change the value of 25 and 100 as desired.
The above command also assumes the partition name is /dev/sda1
. You can use the mount
command to find your partition name.