A friend who just used the MAC OS X Lion system asked me how to modify the Hosts file under the system, said online search a lot of methods do not work, as long as the edit Hosts file appears "You are not the owner of the file hosts, so there is no permission to write to the file" hint, to resolve this issue of permissions than More cumbersome, not easy to understand for users who just use Macs. So, with this tip, I'll share four ways to modify the Hosts file in the Mac OS X Lion system, which will not have permission prompts, and Mac OS X Snow Leopard (10.6) Users can use these methods entirely.
1, through the VI editor modified
Open the terminal (Application-utility), run: sudo vi/etc/hosts. You will be prompted to enter the password (enter the password will not have any character display, and even * will not show, after the loss of the press enter just after), open the Hosts file press I key into the insert mode ( can be interpreted as edit mode, and then according to your needs for the file to edit, edit finished press ESC to exit Insert mode, and then press: wq+ return to save the exit, remember the English colon is to be input oh.
This is the author has been using the method, VI editor for users who often use Linux should not be unfamiliar, and the editor is the default built-in MAC system
Of However, for users who have not used VI, it really takes a while to learn the basics of how to use them. In addition VI editor is a very good powerful tool, want to play good Mac, it is best to master the use of this tool.
2. Modify with Nano Editor
Similar to the above method, the editor is simpler and easier to use than VI, but not powerful and does not seem to be a VI fashion. The method is also run in the terminal:
sudo nano/etc/hosts
The same is the input password, open the Hosts file, according to your needs to edit the file, edited after the press Ctrl+o save, appear File Name to Write:/etc/hosts When press ENTER confirmation, and then press Ctrl+x exit can.
3. Merging files with cat commands
This method is more suitable when you want to add some content to the hosts file, first of all you need to add to the hosts file to save the content as a txt text file (recommended directly saved in your user directory), I take the save in the user directory 123.txt as an example description.
The same is the boot terminal, and then run the following two commands: Sudo-scat ~/123.txt>>/etc/hosts. By the way, the ~ symbol is used in the MAC and even all Unix and Linux based systems to represent the current user's directory. Represents the current directory, and this time you should understand why the above command is ~/123.txt.
4, directly in the graphical interface to modify
Open the Finder and click on the menu bar to go--Go to the folder (or shortcut key shift+command+g), enter/private in the path, enter the
Right-click on the ETC folder--show introduction, at the bottom of the folder Introduction window, find "Share and Permissions", the permissions of everyone to read and write, if you find that you can not modify the lower right corner of the small lock can be modified. Modify the permissions of the ETC folder, and then enter the ETC folder below, modify the name of the Hosts file permissions (the same is everyone read and write), after the modification, you can directly in the Hosts file point right, through "text editing" to open and edit the file, No prompts will appear without permissions. When you have finished modifying and saving, remember to restore the permissions for the file and the ETC folder.
Last Words
This article to share the several Lion system to modify the Hosts will not appear without file modification permission hint, this hint is actually more Lion security performance, the above several methods in 10.6 system can be used, at least the Lion system under a few of the most simple modify Host The S-file approach. In addition, we can see that all of the above three methods need to operate in the terminal, and for just using the MAC, and did not play Linux users may feel very troublesome, in fact, the terminal is very simple, it is a few commands, and the function is very powerful, can achieve a lot of unexpected functions. So, for just using the MAC students must not be terminal this command line operation intimidated, basically you just need to copy the command, and then paste into the press ENTER on it, what is the difficulty?