问题
I am trying to edit bash_profile file to add path to my sdk through the following command on my mac machine. sudo touch ~/.bash_profile; open -e ~/.bash_profile
It opens the file in TextEdit but does not allow me to edit it. Though i have given super-user permission and password while running the above command. It is giving me following message when i try to edit it.
"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." I am new to mac. So please elaborate your answers.
回答1:
The problem is that the file isn't owned by your user, but by root
. You need to change the owner of the file to your user, then you can open and edit the file without the use of sudo
:
sudo chown farheen ~/.bash_profile
This will, as the super-user, change the owner of the file back to you.
回答2:
OR
You can give permission and make it executable file using like below:
That error likely means that 'bash_profile' isn't executable. If it's in the current directory, you can make it executable with chmod +x bash_profile.
来源:https://stackoverflow.com/questions/28065542/sudo-open-e-bash-profile-permission-denied-mac