How to edit ~/.bash_profile file?

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_profile

When 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?

4

2 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_profile

Then 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 open works [...] programs started with open wouldn't have root privileges. The system isn't designed to do that.

[...] However combining open and sudo [...] results in sudo running open as root, but open still opens the application as the original user!

Avoiding open should work:

sudo -b /Applications/ .bash_profile
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