Editing files?

TheAnvil

macrumors regular
Original poster
Nov 25, 2013
162
18
Hi,

New to OSX here, just got my Mini :D

But I can't seem to edit /etc/hosts file. But I get the following message:
Code:
You don't own the file "hosts" and don't have permission to write to it.
I have tried doing "open -e hosts", "sudo -e hosts" and even "sudo su" & "open -e hosts"; all to no avail

What have I missed?

Thanks!
 

TheAnvil

macrumors regular
Original poster
Nov 25, 2013
162
18
That article helped.

I could edit the files in nano, however I still don't understand why I couldn't with "sudo open -e".

Thanks.
 

mfram

macrumors 65816
Jan 23, 2010
1,056
138
San Diego, CA USA
Because the of way 'open' works compared to a Terminal program like nano or vi. Programs started with 'open' wouldn't have root privs. The system isn't designed to do that.
 

TheAnvil

macrumors regular
Original poster
Nov 25, 2013
162
18
Because the of way 'open' works compared to a Terminal program like nano or vi. Programs started with 'open' wouldn't have root privs. The system isn't designed to do that.
Yep. I found this:

To run applications as root, we use sudo. However combining open and sudo in this form:
sudo open /path/to/some.app
results in sudo running open as root, but open still opens the application as the original user!!!

Therefore, the longer method of specifying the full path name for Cocoa applications (not just to the .app package, but to the actual executable):
sudo "/Applications/TextEdit.app/Contents/MacOS/TextEdit"
So, this works perfectly well.
Code:
sudo -b  /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts