I think I had a typo when I add a path to ~/.bashrc and after I source it, I cannot use bash commands anymore.

Now I want to restore a normal ~/.bashrc, however most of the discussion I found (e.g. How to fix a .bashrc that's been edited wrongly?) needs to use bash commands e.g. cp

clam@cuerei:~# cp /etc/skel/.bashrc ~
cp: /home/cltam/script/lib/libc.so.6: version `GLIBC_2.17' not found (required by cp)

May I know how could I restore ~/.bashrc without using bash commands?

Thank you.

5 Answers 5


cp is not a bash command – it's an external program. This is why it fails; actual bash commands would be unaffected by library or path changes. So you want the opposite, i.e. using only bash commands.

You could delete the file's contents completely, using:

true > ~/.bashrc

Or overwrite with some other contents:

echo "" > ~/.bashrc

Or you could try to temporarily undo the bad changes within the live shell:

export PATH=/bin:/usr/bin
cp /etc/skel/.bashrc ~

Or you could copy the file's contents, line by line, using just shell built-ins:

while IFS="" read -r line; do
    echo "$line";
done < /etc/skel/.bashrc > ~/.bashrc
  • 2
    Surely I'm not the only one who keeps staticly linked copies of critical binaries lying around.
    – Joshua
    Commented Aug 21, 2020 at 18:08
  • 2
    Or a live USB to boot from
    – shay
    Commented Aug 21, 2020 at 19:33
  • 4
    in a locked low-humidity temperature-controlled vault accessible only when two keys are turned simultaneously in locks that are eight feet apart .... whups, sorry. Commented Aug 21, 2020 at 21:30
  • 4
    Or more simply, just unset LD_LIBRARY_PATH and use vim or whatever to fix the typo in your existing .bashrc, then re-source it. No need to wipe it out. Commented Aug 22, 2020 at 0:35
  • @PeterCordes Or even LD_LIBRARY_PATH= vim ~/.bashrc. Commented Aug 22, 2020 at 6:21

Are you currently logged into the system? If so, you can switch to another shell, then edit the file

> chsh
> vi ~/.bashrc
  • 1
    If cp won't run, what makes you think chsh will run?
    – Barmar
    Commented Aug 22, 2020 at 23:04

You broke your library path which is used for dynamically linked programs. Those do not contain all the code needed to execute the program, but load some from shared libraries at start up time.

Some programs are compiled to avoid this issue (for instance for programs running as root or needed very early in the boot process). They are traditionally placed in /sbin and /usr/sbin. What exactly is there depends on what is installed.

On my Mac it does not appear that there is an editor available, but your system might have.


I also have this problem. when I use /usr/bin/vi ~/.bashrc I can edit .bashrc again


I have followed @Peter Cordes suggestion to undo my edit by: unset LD_LIBRARY_PATH.

Thank you very much!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .