Accidentally renamed /bin Help!

There are several ways to fix this issue.

If you have access to a shell (any open terminal), run:

sudo /D_bin/mv -T /D_bin /bin

sudo is in /usr/bin so there is no need to run it with absolute path.

The other thing you can do is, adding the /D_bin to your PATH environment variable, like this:

export PATH=$PATH:/D_bin

If you don't have access to any shell:

  1. reboot the system
  2. when grub appears press e to edit the grub
  3. at the end of the line which starts with linux, add:

    init=/D_bin/bash
    
  4. press CTRL+x

Now you will be dropped into a bash shell, you should remount file system as read and writable.

/D_bin/mount -o remount,rw /

And move the D_bin directory to bin:

/D_bin/mv -T /D_bin /bin

Then reboot the system.

It should work, but if nothing worked for you, you still can boot the system with a live ubuntu disk/usb and fix the issue.


To fix this problem if you have no running terminal open, I would first try to find a “shell substitute” that you can use instead of bash. Python is in /usr/bin, so that should still work.

Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.call(["sudo", "/D_bin/mv", "-T", "/D_bin", "/bin"])

If that doesn't work, I'd just straight boot from live CD / USB and fix everything from a known-sane running environment.

As a general advice, I'd second Jonathan Leffler in the comments: never use cd .. in scripts, it can easily lead to such problems. Better only cd into the $j directory within a subshell, this way you don't have to worry about getting back.

#!/bin/bash
files=~/Desktop/folder_1/*

for j in $files
do
  (
    cd "$j"
    for i in 10n*  #file names starting by 10n
    do
       find * -maxdepth 0 ! -path . -exec mv {} D_{} \;
    done
  )
done

Also, of course, don't run stuff as root unless absolutely necessary.