3

I'm using Ubuntu 14.04 and I've accidentally moved /usr/bin to another location.

Now most of the commands don't work anymore: sudo, cp...

The OS is not booting and I can't put the directory back as I have no permissions.

I also use zsh, and I suspect there were some zsh related files and symlinks.

How can I move the directory back?

Zanna
  • 70,465
hugronaphor
  • 223
  • 3
  • 7

2 Answers2

6

If you simply moved the directory elsewhere (say /some/where), then move it back:

/some/where/sudo /some/where/mv /some/where /usr/bin

mv is no longer /bin/mv now that Ubuntu has completed the usrmerge.

If you don't have an open terminal in which you can run this, and have trouble opening another terminal, press AltF2 to get GNOME Shell's prompt for running commands, and then try one of these command:

/some/where/gnome-terminal.real -- /some/where/bash
/some/where/xterm /some/where/bash

Alternatively, if you have the file manager open, press CtrlL to open the address bar and go to admin:///some/where. This should prompt for you to authenticate and then open that directory in privileged mode, allowing you to move things back to /usr.

muru
  • 197,895
  • 55
  • 485
  • 740
  • I can't, it says: "zsh: command not found: mv" – hugronaphor Aug 30 '17 at 02:54
  • Looks like /usr/bin is not the only thing you moved. – muru Aug 30 '17 at 02:55
  • Also​ "zsh: ..."? Is your root shell also zsh? – muru Aug 30 '17 at 02:57
  • Yes, zsh is my default shell. And apparently commands like mv, cp are working when I'm in /bin directory. However when I'm trying to move or copy I have no permissions to do it and sudo is not available. – hugronaphor Aug 30 '17 at 03:06
  • @CornelAndreev you do know where you moved /usr/bin to, right? sudo is wherever you moved it, so run it from there. Did you read the answer at all? – muru Aug 30 '17 at 03:08
  • 2
    If you can only run mv when in /bin that means your PATH is messed up. Reset to a sane default: export PATH=/usr/sbin:/usr/bin:/sbin:/bin – muru Aug 30 '17 at 03:14
  • Alright, now I moved it back. As you said, I ran the command(sudo mv) from the location I moved it. I didn't know these commands are working like this and I didn't understand all the meaning of your example that I have to run it from the location I moved it. Thank you! – hugronaphor Aug 30 '17 at 03:19
0

To move it back you need superuser permissions.

So navigate to the path where you moved using "cd".Yes, cd command will be available even you move the bin.

Then in the new bin directory

use:

./sudo /new/bin/path/mv new/bin/path /usr/bin/

./sudo to access sudo

./sudo /new/bin/path/mv to run mv (move command)

This should move back the folder in it's place.