Recovering a moved file in ubuntu

in flag

I meant to copy a file from one directory to another. Instead, I moved it using the mv command. I made a lot of changes to this file and now realize that I have lost the original file.

Is there a way I can recover the file I originally moved?

muru avatar
us flag
Did you move to a directory on the same filesystem or in a different filesystem?
user32882 avatar
in flag
What do you mean by the same file system? I assume so, yes... I didn't move it to another hard drive, if that's what your asking...
pLumo avatar
in flag
What was the command you used? Check `history`. Can't you just move or copy it back? Or do you mean a file with the same name in the other directory was overwritten?
user535733 avatar
cn flag
If you didn't use the `--backup` flag, then there recovery seems unlikely given the limited description. However, maybe you have a backup of your data somewhere else (smart folks do that). Or perhaps the application you used to edit the file tracks versions and changes (like LibreOffice).
cn flag

If the original file was moved, then, no. The only existing copy is the one you moved and edited in the mean time. If you make backups regularly, you may be able to recover an earlier version from the backup. Else, it would require advanced data recovery to retrieve traces of the original file - in as far as the disk space has not been overwritten. Depending on the complexity of the changes to your file, (an attempt at) recovery of the original file may not be worth the time and the trouble.

Photorec is a relatively accessible tool to recover deleted files, which you could attempt if this is really critical. To be safe, you would need to work on a binary disk image of the partition. Only making that copy already will take substantial time.


Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.