How to modify "/etc/bash.bashrc"? It is read only?

Trying to modify /etc/bash.bashrc I get an error:

$ echo "my edit" >> /etc/bash.bashrc
bash: /etc/bash.bashrc: Permission denied

ls -ll /etc/bash.bashrc shows:

-rw-r--r-- 1 root root 1975 2011-05-18 19:54 /etc/bash.bashrc

How could I modify /etc/bash.bashrc ?

3

5 Answers

sudo bash -c "echo 'text' >> /etc/bashrc"

Don't change the owner. Don't chmod it. Just use sudo. Open it with sudoedit if you need to do complicated things.

By the way, you can make changes for one user by just editing ~/.bashrc without requiring any special permissions.

2

You need superuser permissions to edit the file.

To become the superuser, type in sudo -s then enter your password. After you log in, then try your command, and it will work.

11

You've probably discovered by now that there are many ways to do this. But I think this one is the most elegant of all. (It often involves the least typing, too, when everything is said and done.)

echo "my edit" | sudo tee -a /etc/bash.bashrc

See man tee if you're interested in the technical details of how this works.

In general:

  • To do the work of echo some-text > some-file as root, run:

    echo some-text | sudo tee some-file
  • To do the work of echo some-text >> some-file as root, run:

    echo some-text | sudo tee -a some-file
sudo nano /etc/bash.bashrc

Do the changes you want. Save it (Ctrl+X) and confirm with y and Enter.

sudo echo "my edit" >> /etc/bash.bashrc
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like