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

57,737

Solution 1

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.

Solution 2

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.

Solution 3

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

Solution 4

sudo nano /etc/bash.bashrc

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

Share:
57,737
hliriani
Author by

hliriani

Updated on September 18, 2022

Comments

  • hliriani
    hliriani over 1 year

    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 ?

  • Matt
    Matt over 12 years
    This does not work. You are echoing as root.. but the regular user is doing the appending.
  • RusGraf
    RusGraf over 12 years
    sudo chmod 777 /etc/bash.bashrc: Terrible idea.
  • Matt
    Matt over 12 years
    They asked, I answered.
  • RusGraf
    RusGraf over 12 years
    No one asked you how to create system-wide security holes. That was your own suggestion. The responsible thing for you to do would have been to explain how to modify the contents of the file in accordance with Ubuntu's documented best practices for privilege elevation.
  • Andrejs Cainikovs
    Andrejs Cainikovs almost 12 years
    Can't see any reason on chmod'ing a /etc/bash.bashrc.
  • Andrejs Cainikovs
    Andrejs Cainikovs almost 12 years
    Clean and mean.
  • Matt
    Matt almost 12 years
    @AndrejsCainikovs,some people have computers that they are the sole user. So permissions don't really matter that much to us [me being one of them].
  • Andrejs Cainikovs
    Andrejs Cainikovs almost 12 years
    @Matt, the fact is that even after chown, this file will still be readable by others because of 644 permission. Hence it makes no sense at all.
  • Matt
    Matt almost 12 years
    @AndrejsCainikovs, after chown the user can edit the file without a password, hence making sense?
  • Andrejs Cainikovs
    Andrejs Cainikovs almost 12 years
    Well, this is leading to a dead end. While you are trying to give a direct answer to the incorrect question, I'm trying to explain author that he is going wrong way.
  • Matt
    Matt almost 12 years
    @AndrejsCainikovs happy now?
  • Andrejs Cainikovs
    Andrejs Cainikovs almost 12 years
    Yes, Matt :) +1'd.
  • dylnmc
    dylnmc over 7 years
    su -c "echo 'text'" >> /etc/bashrc ^.^