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*}


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

  • 10
    Wow! That is an impressive mistake! :( – Sparhawk Aug 13 '13 at 11:15
  • 3
    Do I understand correctly that the working directory at the time was /? If so, when I try mv tempdir/ ../, I get mv: ‘tempdir/’ and ‘../tempdir’ are the same file, with nothing moved. – Sparhawk Aug 13 '13 at 11:17
  • Next time, don't login as root. And if you are going to do mv add the -i switch. – Braiam Aug 13 '13 at 11:32
  • 1
    I disagree. Sometimes you do want to log in as root rather than learn to mindlessly put 'sudo ' in front of every command. However be careful when logged in as root. Especially with delete and move commands. --- Still, errors do happen and we learn from those. @MaxDL: Can you restore the / partion from a backup? Do you have backups? Can you use a Dell DRAC, a HP ILO or other remote access tool to access the servers console without booting the OS ? – Hennes Aug 13 '13 at 12:27

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.

  • What confused me was the line root@server:/# ls, which suggested to me that the current directory was /. (Hence my second comment above.) – Sparhawk Aug 13 '13 at 11:43
  • Sorry, that is the complete command: root@server:/tmp/UPS/up/upsilon# mv /* ../ I was connected remotly in ssh. Now, I can't access anymore. – MaxDL Aug 13 '13 at 12:17
  • Then the command to fix is /tmp/UPS/up/bin/mv /tmp/UPS/up/{bin,boot,etc,home,media,mnt,opt,root,sbin,selinux,usr,var,vmlinuz*} / – Sparhawk Aug 13 '13 at 13:13

If you already rebooted or got logged out, you can boot in a liveCD/USB to fix your system. I'm going to omit the part where you know how to create a Live system and boot with Ubuntu (the alternative cd also works, just drop into a root shell):

First you should mount your system to somewhere, so:

mkdir /mnt/system
mount /dev/sda1 /mnt/system

I'm assuming /dev/sda1 is your root. If you have separated /bin or /usr you should mount them too:

mount /dev/sda2 /mnt/system/usr

Now, you should arrive to the directory you were before the catastrophe:

cd /mnt/system/tmp/UPS/up/upsilon

Now with the command that Oli gave, which I will copy with blatancy:

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

Now verify everything is in order:

# ls /mnt/system/
bin boot etc home media mnt opt root sbin selinux usr var etc...

Reboot your system and be more cautious in the future.


I had this issue, I found that I needed to call the mv command like this:

/tmp/UPS/up/lib/ld-linux-x86-64.so.2 --library-path /tmp/UPS/up/lib/ /tmp/UPS/up/test/bin/mv /tmp/UPS/up/{bin,boot,etc,home,media,mnt,opt,root,sbin,selinux,usr,var} /

Hope this helps others.

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.