Ubuntu – Revert moving root directory recursively

data-recoverymv

I have an Ubuntu Desktop used as a Server.
This morning I accidentally moved all my root to ../

 root@server:/tmp/UPS/up/upsilon# mv /* ../
 mv: impossibile spostare "/dev" in "../dev": Dispositivo o risorsa occupata
 mv: impossibile spostare "/proc" in "../proc": Dispositivo o risorsa occupata
 mv: impossibile spostare "/run" in "../run": Dispositivo o risorsa occupata
 mv: impossibile spostare "/sys" in "../sys": Dispositivo o risorsa occupata
 mv: impossibile spostare "/tmp" in una sottodirectory di sé stessa, "../tmp"
 root@server:/tmp/UPS/up/upsilon# ls
 -bash: /bin/ls: No such file or directory

I was connected remotely in ssh. Now, I can't access anymore. I can't also view Webmin.

So, now I can't restart system correct? And I must physically access to the system console and type this command:

../bin/mv ../{bin,boot,etc,home,media,mnt,opt,root,sbin,selinux,usr,var,vmlinuz*}

right?

Where did my root directory go and how can I get it back? Will the above command work?

Best Answer

  • You haven't moved the root directory (you can't), you've just moved nearly everything in it to the parent directory of whatever path you were on.

    To complicate things, you've also moved mv so that won't work as expected. The following should work (as long as you haven't rebooted since asking this!) if you're still in the same directory you were when you fired your last mv off.

    ../bin/mv ../{bin,boot,etc,home,media,mnt,opt,root,sbin,selinux,usr,var,vmlinuz*} /
    

    If you don't have any of those, just omit them from the command.

    And if you don't have access (you won't be able to do a fresh login while things are in this state) you'll have to mount the filesystem externally (through something like LiveCD and mount the filesystem and then move the files into the right place. Braiam's answer should help with this part.