简体   繁体   English

直接使用脚本或命令删除 solaris 上的主机文件条目

[英]Deleting a hosts file entry on solaris using a script or command directly

I have requirement where I want to delete a entry from /etc/hosts file matching a particular entry我有要求从 /etc/hosts 文件中删除与特定条目匹配的条目

For example例如

I want to delete an entry like below我想删除如下条目

192.168.1.1 test001 test001.test.test.com

How can I do this either using a single line command or a script.如何使用单行命令或脚本来执行此操作。

This deletes the string from your hosts file这将从您的主机文件中删除字符串

sed -i -e "/192.168.1.1 test001 test001.test.test.com/d" filename

You might need regular expressions to catch whitespace between the words which might be blanks or tabs:您可能需要正则表达式来捕获可能是空格或制表符的单词之间的空格:

sed -i -e "/192.168.1.1.*test001.*test001.test.test.com/d" filename

You can try something like:您可以尝试以下方法:

grep -v "192.168.1.1 test001 test001.test.test.com" /etc/inet/hosts >/tmp/hosts
mv /tmp/hosts /etc/inet/hosts

The file and path differ because /etc/hosts in Solaris is softlink to /etc/inet/hosts文件和路径不同,因为 Solaris 中的/etc/hosts是到/etc/inet/hosts的软链接

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

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