How to modify "/etc/bash.bashrc"? It is read only?
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
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
Solution 4
sudo nano /etc/bash.bashrc
Do the changes you want. Save it (Ctrl+X) and confirm with y
and Enter.
hliriani
Updated on September 18, 2022Comments
-
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 over 12 yearsThis does not work. You are
echo
ing as root.. but the regular user is doing the appending. -
RusGraf over 12 years
sudo chmod 777 /etc/bash.bashrc
: Terrible idea. -
Matt over 12 yearsThey asked, I answered.
-
RusGraf over 12 yearsNo 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 almost 12 yearsCan't see any reason on chmod'ing a
/etc/bash.bashrc
. -
Andrejs Cainikovs almost 12 yearsClean and mean.
-
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 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 almost 12 years@AndrejsCainikovs, after
chown
the user can edit the file without a password, hence making sense? -
Andrejs Cainikovs almost 12 yearsWell, 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 almost 12 years@AndrejsCainikovs happy now?
-
Andrejs Cainikovs almost 12 yearsYes, Matt :) +1'd.
-
dylnmc over 7 years
su -c "echo 'text'" >> /etc/bashrc
^.^