How to modify "/etc/bash.bashrc"? It is read only?
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.
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.
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
asroot
, run:echo some-text | sudo tee some-file
-
To do the work of
echo some-text >> some-file
asroot
, run:echo some-text | sudo tee -a some-file