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
  • 69,223
  • 56
  • 216
  • 327
hugronaphor
  • 223
  • 2
  • 7

2 Answers2

6

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

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

(mv is /bin/mv, so no worries there.)

muru
  • 193,181
  • 53
  • 473
  • 722
  • 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.