0

I was doing some C programming when I wanted to compile and test my program.

gcc -g -o main file.c file2.c file3.c ... worked for everything up till then, when suddenly I get a dozen undefined reference error message from gcc. ls and ls -la reveal that my file1.c is gone. I was in a screen, but was not connected from anywhere else. Is there any hope left?

I was running this on a remote terminal, so would my only hope be contacting the system administrator and requesting a rollback of my home directory?

UPDATE

I've managed to get a few-hour old backup made available to me, so all should be good for now. Whoever's reading this: Make backups. I didn't. I got lucky, and it's not something I would wager on happening again.

The only reason I didn't have backups was because I was linking it with some libraries and it was easier to debug it like this rather than with a makefile. I was wrong. Backup everything.

filpa
  • 3,651
  • 8
  • 52
  • 91
  • 8
    Cue the need for source control in 3... 2... 1... – David Apr 03 '13 at 19:37
  • 2
    Any backup file from the editor? – Daniel Fischer Apr 03 '13 at 19:38
  • This doesn't seem like a programming question. It's highly unlikely that gcc deleted a file. Most likely, you ran some other command. Regardless, if the file has really been `rm`ed, and was not backed up anywhere, you'll almost certainly have to rewrite it (unless your sysadmins provide some sort of automated backup system). Backups backups backups. – drewmm Apr 03 '13 at 19:38
  • 1
    What editor were you using? Some leave behind backups like emacs might create file.c~. – FatalError Apr 03 '13 at 19:38
  • I was using vi, and there is no .swp file of the file I can find (at least no in the working directory). @drewmm The only thing I ran was gcc. Literally, logged in, `screen -r #` => `gcc ...`. – filpa Apr 03 '13 at 19:42
  • 1
    @drewmm: gcc certainly can delete a source file if you tell it to: `gcc foo.c -o foo.c` – Keith Thompson Apr 03 '13 at 19:43
  • Can you scroll up in your terminal? Maybe it's in your terminal scrollback. http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer/ – 000 Apr 03 '13 at 19:44
  • 1
    This would be more appropriate on SuperUser, wouldn't it? – StarPilot Apr 03 '13 at 19:45
  • @KeithThompson: Fair enough. But still, I think, highly unlikely. :) OP: what was the exact `gcc` line you typed in? Does anyone else have write permissions to the directory who could have deleted the file? – drewmm Apr 03 '13 at 19:47
  • 1
    Why did you edit the question? The original version would have resulted in **exactly** the same behaviour as in your problem description. – wildplasser Apr 03 '13 at 19:48
  • 1
    He edited it because his first posted invocation was `gcc -g -o file.c file2.c file3.c ... `. If that was truly the command, then he told gcc to create the built file as file.c. If it wasn't the command used, then that sends posters down the wrong rabbit hole on where his missing file went. – StarPilot Apr 03 '13 at 19:51

1 Answers1

1

I would try history to see if you did not move the file somewhere accidentally. Also would try ls -la to see if there are no back up files.

Ola M
  • 1,298
  • 3
  • 12
  • 27