Home ยป Accidentally deleted my /bin folder?

Accidentally deleted my /bin folder?


Dangerous? Not any more – you already did the dangerous thing.

You just deleted the part of the system that has essential things that belong every system needs. According to wikipedia’s article on the FHS /bin contains “Essential command binaries that need to be available in single user mode; for all users, e.g., cat, ls, cp.” These are MASSIVELY important in some contexts.

Assuming you want to fix this, you might be able to copy over /bin from a running system – maybe off a livecd of the same version of your distro. I’m not totally sure this would work.

Nonetheless, while you’re trying this, back up any essential files in case anything goes wrong. /etc/ /home and /var might be good ideas, as would /srv in distros that use it

Yes, what you just did is quite an essential mistake, maybe comparable to deleting Program Files on Windows (if that’s possible).

If you have another (virtual) machine around, you could try this quite decent and fast solution to this common problem:

What do we need?

  • ssh, rsync, sudo should all still be available
  • you should have a similar system reachable from your network (with


  1. Copy the bin directory:

The ‘#’ sign means, you should be root. Substituting ‘#’ with “sudo” will do on most systems. On others, use “su”.

# rsync -rv <remote-login>@<remote-server>:/bin /


# scp -rv <remote-login>@<remote-server>:/bin /
  1. Then ‘cd’ to the /bin directory (which should work again now)
# ln -s bash sh

This is important since most programs actually link to /bin/sh and many
scripts have it in the shebang (#!) line. You should link to bash (for
most people), or the shell you use (for those, who probably wouldn’t
delete the /bin directory anyway).

  1. Update and upgrade from your repository (on Ubuntu and Debian)
# aptitude update && sudo aptitude upgrade


# apt-get update && sudo apt-get upgrade

That should at least get you a working system. You should maybe
reinstall coreutils and in general be vary of any problems. You should
backup your data and be cautious.

I have done the following and was able to recover my fully functional Ubuntu within 5 minutes.

  1. Install a Copy of your Ubuntu (Same version which has crashed) into a pen-drive.

  2. Run Ubuntu live mode with pendrive on your sick machine

  3. Locate your crashed drive and mount it from the “places” tab, in the very top-left corner of your machine.

  4. Open terminal using Ctrl+Alt+T” and create a bin folder into the mounted drive using sudo, i.e. sudo mkdir /media/bin

  5. Copy all the bin files from your live session to victim device, with sudo, i.e. sudo cp /bin/* /media/bin

  6. Restart, it may show some message to update your firmwares (or other messages) just ignore for while and login.

Related Solutions

How can I pass a command line argument into a shell script?

The shell command and any arguments to that command appear as numbered shell variables: $0 has the string value of the command itself, something like script, ./script, /home/user/bin/script or whatever. Any arguments appear as "$1", "$2", "$3" and so on. The...

What is pointer to string in C?

argv is an array of pointers pointing to zero terminated c-strings. I painted the following pretty picture to help you visualize something about the pointers. And here is a code example that shows you how an operating system would pass arguments to your...

How do mobile carriers know video resolution over HTTPS connections?

This is an active area of research. I happen to have done some work in this area, so I'll share what I can about the basic idea (this work was with industry partners and I can't share the secret details ๐Ÿ™‚ ). The tl;dr is that it's often possible to identify an...

How do I change the name of my Android device?

To change the hostname (device name) you have to use the terminal (as root): For Eclair (2.1): echo MYNAME > /proc/sys/kernel/hostname For Froyo (2.2): (works also on most 2.3) setprop net.hostname MYNAME Then restart your wi-fi. To see the change, type...

How does reverse SSH tunneling work?

I love explaining this kind of thing through visualization. ๐Ÿ™‚ Think of your SSH connections as tubes. Big tubes. Normally, you'll reach through these tubes to run a shell on a remote computer. The shell runs in a virtual terminal (tty). But you know this part...

Difference between database vs user vs schema

In Oracle, users and schemas are essentially the same thing. You can consider that a user is the account you use to connect to a database, and a schema is the set of objects (tables, views, etc.) that belong to that account. See this post on Stack Overflow:...

What’s the output of this code written in java?

//if you're using Eclipse, press ctrl-shift-f to "beautify" your code and make it easier to read int arr[] = new int[3]; //create a new array containing 3 elements for (int i = 0; i < 3; i++) { arr[i] = i;//assign each successive value of i to an entry in...

How safe are password managers like LastPass?

We should distinguish between offline password managers (like Password Safe) and online password managers (like LastPass). Offline password managers carry relatively little risk. It is true that the saved passwords are a single point of failure. But then, your...

Can anyone tell me why this program go to infinite times?

while (i <= 2) { while (i > 0) { a = a + b; i--; <- out the inner while loop when i = 0 } printf("%d", a); i++; <- at here, the i==0 each time, so infinity loop } Because your nested loop always restores the value of i to 0, And 0 <= 2 is always...

How to conditionally do something if a command succeeded or failed

How to conditionally do something if a command succeeded or failed That's exactly what bash's if statement does: if command ; then echo "Command succeeded" else echo "Command failed" fi Adding information from comments: you don't need to use the [ ... ] syntax...

How to turn JSON array into Postgres array?

Postgres 9.4 or newer Obviously inspired by this post, Postgres 9.4 added the missing function(s): Thanks to Laurence Rowe for the patch and Andrew Dunstan for committing! json_array_elements_text(json) jsonb_array_elements_text(jsonb) To unnest the JSON array....

Implementing a 2D destructible landscape (like Worms)

I don't know how the landscape in worms was implemented exactly, but I'm pretty sure they used a bitmap for the landscape (at least in the older games of the series). A very basic approach would be a bitmap image (B/W) where black pixels represent air and white...

Huge procedurally generated ‘wilderness’ worlds

I think I better understand what you are asking now. Noise is not random - it's random-looking but is completely based on a mathematical formula and is repeatable. All the information is encoded in the formula. This means that you can have a formula that...

How does one prevent homing missiles from orbiting their targets?

First of all, you should make all calculations about what acceleration to apply in the missile's frame of reference (that's where the missile is stationary and everything else moves around it, also often called "object coordinates" or "local coordinates" in...

Is UDP still better than TCP for data-heavy realtime games?

No, UDP is still superior in terms of performance latency, and will always be faster, because of the philosophy of the 2 protocols - assuming your communication data was designed with UDP or any other lossy communication in mind. TCP creates an abstraction in...