What tools exist to recover a file I clobbered using cpp in terminal

backupcopy/pasteterminalunix

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

Best Answer

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.