Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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 for recovery? I'm asking the cpp angle on the unix site in case that tool saves a copy of files before it clobbers them, but what Mac tools exist to get my original file back?


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
share|improve this question
3  
locate works on a pre-computed index (rebuilt on a weekly basis), use find / -name Scriptname.py -print instead. But cpp is just a preprocessor which should have left the input intact (especially with a directory as the second argument), did you do something else with the file as well? –  patrix Apr 10 '12 at 16:06
2  
Sorry to say, but the second cpp(with the directory first and the script second) deleted MYSCRIPT.PY (as I've just verified with some dummy file). Unless you have a backup there is no easy way to get the file back. –  patrix Apr 10 '12 at 18:41
    
@patrix Ah sugarplums... Alright, thanks for your help –  ironcyclone Apr 10 '12 at 20:08
2  
1  
That second call to cpp deleted the files. You need to restore from a backup, or to try to recover the data from the deleted script (but that won't be easy) as indicated on U&L. If you want to try recovering, stop writing to the disk immediately. –  Gilles Apr 10 '12 at 23:52
show 1 more comment

3 Answers

Here are a few options to recover a file from user error of this type:

  1. TimeMachine - your best hope.
  2. Dropbox also keeps deleted files and versions if you stored that file in a folder that synced.
  3. mdfind MYSCRIPT.py #better than locate and searches inside files, not just file names
  4. Check your repositories if you use code control software like git or mercurial or svn or other tools
  5. General undelete software like Data Rescue

As you're now aware, the terminal is unforgiving and doesn't have an "are you sure you meant to clobber that file?" design mentality. It gets worse when you realize recursive commands and the fact that everything is a file (directories, disks, disk images, etc...) and errant commands can delete vast amounts of work in the blink of an eye.

share|improve this answer
add comment

Sleuth Kit works well and is free but takes sometime to learn.

http://www.sleuthkit.org/sleuthkit/desc.php

share|improve this answer
4  
Can you explain it bit more about how this would help in the situation described in the question? –  patrix Aug 10 '12 at 15:08
add comment

If it is truly still in your user directory, perhaps it is marked as hidden. Use ls -a to see all files in your home directory, including hidden ones.

share|improve this answer
    
Useful trick, but no dice ;( –  ironcyclone Apr 10 '12 at 18:19
1  
No, there is absolutely no chance that the file was magically renamed to a name beginning with a dot. –  Gilles Apr 10 '12 at 23:50
    
Files can be marked with the hidden attribute without being named with a dot. –  stephenwade Apr 11 '12 at 11:36
    
There is also no chance that copying will hide the file using meta data. –  Chris Page Aug 11 '12 at 0:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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