I was planning to move a directory into another. The intended command is

mv evaluateA2P/ action2pose_bk/evaluateA2P/

However, I had a typo and executed

mv evaluateA2P/ action2pose_bk/ evaluateA2P/

Now, without a warning or prompt, the content of action2pose_bk/ is overwritten with that of evaluateA2P/. Can I somehow restore the content, or I'd better hire a lawyer?

System information

Linux XXXXXXX-workstation3 5.3.0-28-generic #30~18.04.1-Ubuntu SMP Fri Jan 17 06:14:09 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Here is a demo of what just happened:

/tmp$ mkdir test1 test2
/tmp$ touch test2/important_file
/tmp$ mv test1 test2 test1
mv: cannot move 'test1' to a subdirectory of itself, 'test1/test1'
/tmp$ ls test2
ls: cannot access 'test2': No such file or directory
  • The command you posted that you said overwrote the contents of action2pose_bk would have actually errored and did nothing because you can't move a directory into itself. Some other command is responsible for your issue. – jordanm Feb 20 at 22:21
  • It's not clear what you are saying the result is. That command should have resulted in action2pose_bk being moved into evaluateA2P. To undo that you just need to do: mv action2pose_bk/evaluateA2P . – kaylum Feb 20 at 22:21
  • @kaylum no, it should have resulted in mv: cannot move 'evaluateA2P/' to a subdirectory of itself, 'evaluateA2P/evaluateA2P' – jordanm Feb 20 at 22:22
  • @jordanm Yes but that's only for the first src arg. It will not abort the whole command and will still move the second src arg into the final dest. – kaylum Feb 20 at 22:23
  • 1
    @ctrl-alt-delor You certainly have the privilege to downvote, but I'm not threatening to set a lawyer on you! I was saying if there is no way I can restore the data, then I'd better find a lawyer in case my employer is going to sue me for the damages I have caused. – nalzok Feb 20 at 22:55
mv evaluateA2P/ action2pose_bk/ evaluateA2P/

The result of that command would be to move the action2pose_bk directory into the evaluateA2P directory. To undo that, simply move it back by running:

mv action2pose_bk/evaluateA2P .
| improve this answer | |

Try this,

mv test1/test2 . && mv test1 test2
| improve this answer | |

Just like in your demonstration, here is what I get when I try your real scenario:

mv evaluateA2P/ action2pose_bk/ evaluateA2P/
mv: cannot move 'evaluateA2P/' to a subdirectory of itself, 'evaluateA2P/evaluateA2P'

Your command has not run to completion successfully. What it has done is move action2pose_bk into evaluateA2P, so simply move it back again

mv evaluateA2P/action2pose_bk .

Or, with your demo,

mv test1/test2 .

At this point you can try your intended command once more. Note, however, that it will succeed only if the target action2post_bk/evaluateA2P directory is either empty or does not yet exist:

mv evaluateA2P/ action2pose_bk/evaluateA2P/
| improve this answer | |

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.