简体   繁体   English

Mac OS X Bash托管脚本

[英]Mac OS X Bash Hosting Script

After adding a hosting file using etc/hosts on Mac OS X machines manually we found out we needed to remove the current hosts and add a new one. 在Mac OS X机器上使用etc / hosts手动添加托管文件后,我们发现我们需要删除当前主机并添加一个新主机。 I'm wondering if it's possible to add a hosting file for Mac OS X using Bash. 我想知道是否可以使用Bash为Mac OS X添加托管文件。

This is the current state. 这是当前状态。 How do we change the final line or add one to it? 我们如何更改最后一行或添加最后一行?

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1             localhost Computer_Name
255.255.255.0     broadcasthost
::1                        localhost
10.24.82.5           server_name

I guess you are asking how to edit the file from the command line, then 我猜您在问如何从命令行编辑文件,然后

$ sed -i.OLD 's@10\.24\.82\.5 @8.8.8.8 @' /etc/hosts

The -i option allows sed to edit in-place. -i选项允许sed就地编辑。 You may need sudo to have write permission to that file. 您可能需要sudo才能对该文件具有写权限。

您可以简单地使用sed进行更改,只需提供新的IP地址即可:

sed 's/^.*\(server_name\)/new_ip_address \1/' file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM