I mistakenly edited the .bashrc file for my WSL (Windows Subsystem for Linux) Bash using a Windows text editor (Notepad++).

Now whenever I run Bash I get the following error:

bash: /root/.bashrc: Input/output error

How can I fix this? I tried saving with Linux file endings (LF only) but that didn't work.

  • I'm curious how exactly you broke it, because I can't seem to replicate (despite this being a known bad idea). Also, what version of Windows are you running? 1703? 1709? Older? My general idea for fixing it and preserving file contents (in a generic way) was to read it on the Windows side, base64 it, and write it back on the WSL side. Untested until I can reproduce the issue... – Bob Oct 30 '17 at 0:54
  • I opened it up in NotePad++, commented 3 lines at the end and saved it. That was enough to corrupt it. Did not make any deliberate changes to EOL or encoding. – urig Oct 30 '17 at 7:54

How can I fix this? I tried saving with Linux file endings (LF only) but that didn't work.

There are a couple of solutions:

Use a Linux / Ubuntu app to modify files these files (vim, emacs, nano, etc...).

One person said editing with nano and re-saving the file fixed the issue.

If that doesn't work you can try the nuclear option of re-installing:

In my case, nothing got it fixed. I used following command to delete BashOnWindows and then reinstall it:

lxrun /uninstall /full

lxrun /install /y

Source bash command not work for me after edit .bashrc using ST3

Further Reading

  • I nearly crossed with your answer, yet again! @urig's own answer confirms your diagnosis. – AFH Oct 29 '17 at 17:55
  • Thanks @DavidPostill but your first suggestions did not work because WSL was unable to recognize the bad .bashrc file. The last suggestion is quite aggressive in that it completely reinstalls WSL. Luckily I managed to solve using a simpler, quicker operation - See my own answer to my question. – urig Oct 29 '17 at 17:56
  • 1
    @urig Great! Good job you hadn't personalised the file though ... – DavidPostill Oct 29 '17 at 17:57
  • FYI lxrun is deprecated as of 1709. wslconfig is the new CLI tool, while the Store is the correct place to install/uninstall distros. See: blogs.msdn.microsoft.com/commandline/2017/10/11/… – Bob Oct 31 '17 at 2:14

I've found a minimal solution to my problem. My WSL is running Ubuntu. In Ubuntu there is a pristine copy of .bashrc under /etc/skel.

  1. I deleted my bad copy of .bashrc using Windows Explorer.
  2. In Bash I copied over the pristine copy like so: cp /etc/skel/.bashrc ~/

(Based on this AskUbuntu answer: https://askubuntu.com/questions/198730/how-to-restore-bashrc-file)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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