2

I accidentally typed cpp Scriptname.py DestinationDirectory, intending to copy the Python script into the folder.

I realized afterward that I should have used cp, but now my Python script is completely gone. I have tried the locate command, but it says that it's still present in my user directory. When I type ls in my user directory, it is nowhere to be found.

What are my options here?

Edit: Here is an exact replica of what I did, showing how the script 'MYSCRIPT.py' disappears from the home directory.

vav7:~ tuc40953$ ls
 Desktop            Dropbox         Movies         New.java             
 Public         scripts
Documents       Library         Music           Peptoids      Theultimatescript.py
Downloads       MYSCRIPT.py     New.class       Pictures        rename.py
vav7:~ tuc40953$ clear

vav7:~ tuc40953$ cpp MYSCRIPT.py Desktop/Peptoids/Final-Structures/MyScript/
cc1: fatal error: opening output file Desktop/Peptoids/Final-Structures/MyScript/: Is a directory
compilation terminated.
vav7:~ tuc40953$ cpp Desktop/Peptoids/Final-Structures/MyScript/ MYSCRIPT.py 
cc1: error: Desktop/Peptoids/Final-Structures/MyScript/: No such file or directory
 vav7:~ tuc40953$ ls
Desktop         Dropbox         Music           Peptoids          Theultimatescript.py
Documents       Library         New.class       Pictures            rename.py
 Downloads      Movies          New.java        Public             scripts
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
ironcyclone
  • 143
  • 1
  • 3
  • See [these](http://unix.stackexchange.com/questions/2677/recovering-deleted-files-on-fedora) [posts](http://unix.stackexchange.com/questions/18685/how-to-recover-a-file-just-deleted) for info on attempting to recover a deleted file – Michael Mrozek Apr 10 '12 at 19:35
  • @IgnacioVazquez-Abrams I also tried find...Sorry I forgot to mention that. – ironcyclone Apr 10 '12 at 20:10
  • 1
    [Also posted on Apple.SE](http://apple.stackexchange.com/questions/48220/is-there-a-way-to-undo-the-cpp-command-in-terminal). [Please do not post the same question to multiple Stack Exchange sites](http://unix.stackexchange.com/faq#cross-posting). – Gilles 'SO- stop being evil' Apr 10 '12 at 23:49
  • Dammit, now that I know about this I'm *bound* to make the same mistake myself, at the earliest possible convenience. But why does `cpp` clobber the target if compilation is unsuccessful? – l0b0 Apr 11 '12 at 09:51
  • @Gilles I apologize for the repost, I did not know about this site when I posted on the apple site. – ironcyclone Apr 12 '12 at 00:35

2 Answers2

2

There are few ways to recover your file, one of which is using testdisk and/or photorec. I'd advice you to attach your harddrive to a different computer and mount the partition in read-only mode before doing that.

Deepak Mittal
  • 1,544
  • 13
  • 18
  • [`extundelete`](https://github.com/l0b0/tilde/commit/aea8244ef465fd1d0e47832b20329d68adcae857) has saved me before - Install (if the deleted files are on a different partition), remount read-only, and restore. – l0b0 Apr 11 '12 at 09:56
0

Actually, your problem was you've misplaced a SPACE between MyScript/ and MYSCRIPT.py:

cpp Desktop/Peptoids/Final-Structures/MyScript/ MYSCRIPT.py

— Namely that killed your script file.

So, your options now are either re-writing your script from scratch or using Mac OS X undelete software. To increase chances of recovery you should had powered off your system as soon as possible since every file operation might messed up the content of your unlinked script.

poige
  • 6,195
  • 2
  • 30
  • 57