2

I was trying to rename (mv) few of my files and ran a wrong loop resulting into renaming all the 10 files into one. Now I can see only one file whereas there should have been ten files. How do I recover all the files?

  • 3
    You dont. You moved them all in top of one another in turns, deleting them effectively. – Rui F Ribeiro Feb 16 '16 at 3:42
  • 1
    unix.stackexchange.com/q/80270/3929 might help you. (What you are now looking for is general undelete/recovery functionality.) – Ulrich Schwarz Feb 16 '16 at 4:38
  • 1
    Uh, Linux or cygwin? They're not the same – roaima Feb 16 '16 at 5:14
2

Restore the files from backup.

If you don't have a backup, the files were important and you are lucky, you might try extundelete tool. Possibly use another machine to install it and mount the disk as external.

To protect yourself from such mistakes in future: make backups, test before you run, and add following to your bash profile:

alias cp='cp -i'
alias mv='mv -i'

This will require a confirmation on an attempt to overwrite.

  • 1
    If it's really cygwin, it's not going to be an ext3 or ext4 partition, it's likely to be NTFS or FAT. – EightBitTony Feb 16 '16 at 14:57
1

If extundelete doesn't do it for you, the Sleuth Kit has a few tools that might help. fls can give you info about the deleted files in a directory. Testdisk is sometimes helpful, too. Sometimes.

Also, it probably goes without saying, but do not write to the drive after you lose a file! The data is still there but the space becomes marked as unallocated and can potentially be overwritten. Only mount it as read only (at least until you've recovered your files or made a backup image).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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