I am using Mac and want to edit the file .bash_profile using a text editor.
These are the file's permissions:
$ ls -l .bash_profile
-rw-r--r-- 1 root staff 55 Feb 24 12:07 .bash_profileWhen I run sudo open -a "TextEdit" .bash_profile and try to edit the file the following error appears in the text editor:
You don’t own the file “.bash_profile” and don’t have permission to write to it. You can duplicate this document and edit the duplicate. Only the duplicate will include your changes.
How do I edit this file?
42 Answers
As you are using the terminal the easiest way is to fix the ownership of the file first..
e.g.
sudo /usr/sbin/chown <your username> ~/.bash_profileThen use normal editor commands
I don't have OS X to test this but found this answer on the net (source):
Because of the way
openworks [...] programs started withopenwouldn't have root privileges. The system isn't designed to do that.[...] However combining
openandsudo[...] results insudorunningopenas root, butopenstill opens the application as the original user!
Avoiding open should work:
sudo -b /Applications/ .bash_profile 1