Mac OS X system users, at some point may encounter the need to modify the system Hosts file, then how the Mac OS system to modify the Hosts file? What's the difference between a Windows system? We know that in fact, modify the Hosts file only need to find the file on the hard disk, and then edit the changes are OK, but many children's shoes found that just edit the Hosts file will appear "You are not the owner of the file hosts, so there is no permission to write to the file" prompt, to resolve this permission problem and more trouble, It's not easy for a user who just used a Mac to understand.
Therefore, we have collected and collated the following methods for everyone to use, hoping to help everyone.
1. Modify by VI Editor
Open Terminal (application-utility), run:
sudo vi/etc/hosts
The screen will prompt you to enter the password (the password will not be any character display, even * will not display, after the loss to press Enter), after opening the Hosts file press I key into the insert mode (can be understood as the editing mode), and then as you need to edit the file, after editing is completed press ESC Key to exit the insert mode, then press: wq+ Enter to save the exit, remember the English colon is also to enter OH.
The VI editor should not be unfamiliar to users who frequently use Linux, and the editor is built into the MAC system by default. However, for users who have not used VI, it really takes a while to learn the basics of how to use it. In addition VI editor is a very good and powerful tool, want to play a good Mac, it is best to master the use of this tool.
2. Use the Nano editor to modify
Similar to the above method, this editor is more simple and easy to use than VI, but the function is not strong, there seems to be no VI popular. 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, after editing, press Ctrl+o save, the file Name to Write:/etc/hosts when press ENTER to confirm, and then press Ctrl+x exit.
3. Merging files with cat commands
This method is more suitable when you want to add some content to the Hosts file, first you need to add to the hosts file to save the content as a txt text file (it is recommended to be stored directly in your user directory), I have saved in the user directory 123.txt as an example.
Also start the terminal, and then run the following two commands:
Sudo-s
Cat ~/123.txt/etc/hosts
The ~ symbol is a user directory representing the current user in Mac and even all Unix and Linux-based systems. For the current directory, you should understand why the above command is ~/123.txt.
4, directly in the graphical interface to modify
Open the Finder, and then click on the menu bar to go-to the folder (or shortcut shift+command+g), enter/private in the path, after entering the ETC folder right-click-Show Introduction, in the folder Introduction window at the bottom of the "Share and Permissions", Change the permissions of everyone to read and write, and if you find that you cannot modify it, you can modify it by unlocking the small lock in the lower right corner.
After modifying the permissions of the ETC folder, then enter the ETC folder, modify the permissions named Hosts file (same as everyone read and write), after the modification, you can directly in the Hosts file right-click, through the "text edit" to open and edit the file, No prompt will appear without permission. After modifying and saving, remember to restore the file and the permissions of the ETC folder.
The four kinds of Lion system to modify the Hosts of the method will not appear without file modification permission, this hint is also Lion security performance, the above several methods in the 10.6 system can be used, at least the Lion system is a few of the most simple way to modify the Hosts file. In addition, you can see that the above three methods need to operate in the terminal, and for the new MAC, and have not played Linux users may feel very troublesome, in fact, the terminal is very simple, is a few commands, and the function is very powerful, to achieve a lot of unexpected features. Therefore, for the classmate just with the MAC must not be the terminal this command line operation is intimidated, basically you just need to copy the command, and then paste in to press ENTER on it, what is the difficulty?
Teach your Mac OS system four ways to modify the Hosts file