版权声明:作者-傲娇天子 博文主页地址:https://blog.csdn.net/qq_41116956 欢迎转载,转载请在文章页面明显位置给出原文链接,谢谢 https://blog.csdn.net/qq_41116956/article/details/82787787
在linux中,我们很多时候需要查看文件的配置内容,但是这样会总会看到很多含有注释的内容:
[root@localhost ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
那么,我们可以使用egrep命令:
[root@localhost ~]# egrep ^# /etc/selinux/config
^#:选择所有以#开始的
[root@localhost ~]# egrep ^# /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
使用反选:-v
[root@localhost ~]# egrep -v ^# /etc/selinux/config
SELINUX=enforcing
SELINUXTYPE=targeted
[root@localhost ~]#
当然,这里面有空格行,linux下的空格行是以$开始的,所以我们需要使用^$符号来选择空格行,并且反选
[root@localhost ~]# egrep -v '^$|^#' /etc/selinux/config
SELINUX=enforcing
SELINUXTYPE=targeted
[root@localhost ~]#
注意:^$|^#中间的"|"符号是或者的意思