Erased /usr/local/bin directory by mistake

The canonical answer, of course, is to restore /usr/local/bin from your latest backup...

The good news is that if that mv command succeeded and created a file called bin, then /usr/local/bin didn't already exist as a directory on your system, and you've lost nothing. Otherwise, hello.sh would have been moved into the /usr/local/bin directory (which was presumably the intention of the tutorial), it wouldn't have replaced it.

This is not unexpected, as /usr/local/bin doesn't generally exist on Macs until you or a 3rd party app creates it. But now you have learned the awesome power of the command line, you know why it's important to keep good backups ;)

Had you mangled /usr/bin you'd need to reinstall the system:

  • Deleted /usr/local/bin and /usr/bin on OS X

The good news is system integrity protection (SIP) is making it harder to mangle system files with sudo

PS: An easy way to prevent the issue from happening is to always add a trailing / if moving files to another directory (or rely on tab completion wich does the same thing): sudo mv hello.sh /usr/local/bin/. This way you'll get an error message if the target directory doesn't exist.