I have corrupted my /bin/sh and have no idea how to replace it. I accidentally copied over it. How can I fix this?

I am running Ubuntu Server 11.10, no X.

update: I have tried the fix that was kindly offered by Eliah but i think i copied over /bin/dash too!

update: OUTPUT OF cd /bin; file sh dash bash; md5sum sh dash bash

sh:   symbolic link to `dash'
dash: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x5d23ca7cbab4993f295d1089b4860eb32d406fab, stripped
bash: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xf199a4a89ac968c2e0e99f2410600b9d7e995187, stripped
c229085928dc19e8d9bd29fe88268504  sh
c229085928dc19e8d9bd29fe88268504  dash
089ed56cd74e63f461bef0fdfc2d159a  bash

In all remotely recent versions of Ubuntu, /bin/sh is just a symbolic link to /bin/dash. So make sure that whatever is currently called /bin/sh is backed up somewhere if it's important, then delete it and make a new link.

To remove whatever is currently /bin/sh and restore /bin/sh to what it's supposed to be, run these commands:

cd /bin
sudo rm sh
sudo ln -s dash sh
  • I cannot thank you enough for replying so fast. I ran the commands you mentioned and logged out and back in and now I am seeing this "-bash: /usr/bin/lesspipe: /bin/sh: bad interpreter: No such file or directory". Is this right? – Joel May 10 '12 at 23:23
  • I fear i coped over /bin/dash. – Joel May 10 '12 at 23:30
  • @Joel What's the output of cd /bin; file sh dash bash; md5sum sh dash bash? (You can add this to your question and just comment here so I'm notified; that way it can be formatted in a way that makes clear where one line ends and where the next begins.) – Eliah Kagan May 11 '12 at 15:27
  • i am struggling to get him to boot now, stand by, it looks like a partition table is missing... – Joel May 11 '12 at 18:24
  • Ok take a look at the output Eliah... – Joel May 11 '12 at 23:15

Assuming you still have bash, use bash as sh.

sudo ln -s bash /bin/sh

Then reinstall dash

sudo apt-get install --reinstall dash
  • I ran it and got this..."E: Sub-process /usr/sbin/dpkg-preconfigure --apt || true returned an error code (100) E: Failure running script /usr/sbin/dpkg-preconfigure --apt || true" @eliah-kagan – Joel May 11 '12 at 15:04
  • @Joel Then it sounds like there's more broken stuff than just dash. What did you do to break it exactly? – geirha May 11 '12 at 15:37
  • The only exact thing I know I did wrong was accidentally wrote over the /bin/sh with a plain txt doc. I was however, in the process of re-configuring postfix when I fist saw this breakdown. The server stopped sending mail and thats why i was checking the config. I try to be very careful but obviously have done something bad. I just tried to reboot (Have been on SSH) and its not coming up, so i'm walking over to pull the server out of the server room now... What do you suggest I do? – Joel May 11 '12 at 15:40
  • @Joel From your description, it seems you edited /bin/dash through the /bin/sh symlink (which would be the usual behavior of a text editor), rather than overwriting the /bin/sh symlink with a real file. You're right that this would overwrite /bin/dash. This answer, as written, won't always work, but the idea is just right for your situation. Try cd /bin, then sudo rm sh, then sudo ln -s bash sh, then sudo apt-get update, then sudo apt-get install --reinstall dash. If that doesn't work, please add the console text to your question (you can use script to record it). – Eliah Kagan May 12 '12 at 19:47

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.