13

I was hiding some of the folders on my Ubuntu machine. By mistake, I have hidden bin folder too by using

cd /
mv bin .bin

Now I could cd to .bin, but I am not able to unhide the bin directory. Can someone help? I was trying the following command:

mv .bin bin

I am getting the following error

bash: /bin/mv: No such file or directory

I tried to login as root, but my machine is asking me to install login. On doing apt-get install login, I am getting a message login is currently the latest version.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Apricot
  • 487
  • 1
  • 8
  • 15
  • 5
    To help others in similar cases, the first rule is don't panic. Then read below's top answer. But to get even more ideas of what is possible : http://www.lug.wsu.edu/node/414 (different system, different os, but the ideas are still relevant, and unix's reliability is (almost, if distribs remember to keep it sane) still shining) – Olivier Dulac Dec 04 '17 at 10:02

1 Answers1

35

If you still have a root shell open, run

cd /
/.bin/mv .bin bin

Your shell can’t find mv because it’s no longer on the path; giving the full path to it will allow it to run.

(As a general rule, it’s best not to rename directories outside of your home directory — they are managed by the package manager, and you are likely to confuse it and prevent updates from being applied in the future.)

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • Thank you so much....I thought i s***wed up my machine and started taking backup like a maniac. – Apricot Dec 04 '17 at 08:29
  • 3
    @Apricot No need to panic. Even if you could not have been able to restore the directory names from within your running (and broken) system, you could have still used a live system for rescuing it. – Richard Neumann Dec 04 '17 at 09:05
  • 9
    @Apricot: well, that's good, but backup should be taken *before* something bad happens ;) Continue taking backups regularly from now on. – Olivier Dulac Dec 04 '17 at 09:49
  • 1
    Yes, making backups is always good, even if they turn out to be not necessary for the current situation. – Mr Lister Dec 04 '17 at 11:21
  • What happens to `/.bin/mv` itself after executing this command? Is the binary locked while the process is running or will it move itself without complaint? – user3490 Dec 04 '17 at 13:24
  • 3
    @user3490 it moves itself without complaint; see [Overwriting a running executable or .so](https://unix.stackexchange.com/q/404551/86440) for details. – Stephen Kitt Dec 04 '17 at 13:27
  • 2
    Abstractly, renaming `/.bin` to `/bin` changes neither any file within the renamed directory, nor the directory itself; the only thing that is changed is the name of one entry in the _root_ directory! – zwol Dec 04 '17 at 20:11
  • Indeed @zwol, which means `mv` doesn’t actually move itself at all, so my comment above is rather moot. – Stephen Kitt Dec 04 '17 at 20:49