grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来
1、输出真实的(不包含注释#信息)配置项
-v ,Invert the sense of matching, to select non-matching lines.显示不包含匹配文本的所有行
-E Interpret PATTERN as an extended regular expression,使用扩展正则表达式
^,基本正则表达式,行首定位符
$,基本正则表达式,行尾定位符
^$,空行
|,扩展正则表达式,或
行首定位符
-
# 查看/etc/sysconfig/selinux全部内容
-
[root@oracle /]# cat /etc/sysconfig/selinux
-
# 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=disabled
-
-
# SELINUXTYPE= can take one of these two values:
-
# targeted - Targeted processes are protected,
-
# mls - Multi Level Security protection.
-
-
SELINUXTYPE=targeted
-
# 查看不包含注释行的/etc/sysconfig/selinux
-
[root@oracle /]# cat /etc/sysconfig/selinux | grep -v '^#'
-
-
SELINUX=disabled
-
-
SELINUXTYPE=targeted
# 查看不包含注释行和空行的/etc/sysconfig/selinux
[root@oracle /]# cat /etc/sysconfig/selinux | grep -v '^#' | grep -v '^$' --基本正则表达式
[root@oracle /]# cat /etc/sysconfig/selinux | grep -vE '^#|^$' [root@oracle /]# cat /etc/sysconfig/selinux | grep -vE '^#|^$' --扩展正则表达式
SELINUX=disabled
SELINUXTYPE=targeted
2、匹配IP、MAC地址1、匹配IP、MAC地址
-o Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line,只输出匹配字符串
{m,n},扩展正则表达式,m到n次匹配
-
[root@oracle ~]# ifconfig eth0
-
eth0 Link encap:Ethernet HWaddr 00:0C:29:50:CB:D9
-
inet addr:192.168.17.202 Bcast:192.168.17.255 Mask:255.255.255.0
-
inet6 addr: fe80::20c:29ff:fe50:cbd9/64 Scope:Link
-
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
-
RX packets:258 errors:0 dropped:0 overruns:0 frame:0
-
TX packets:199 errors:0 dropped:0 overruns:0 carrier:0
-
collisions:0 txqueuelen:1000
-
RX bytes:24411 (23.8 KiB) TX bytes:24063 (23.4 KiB)
-
Interrupt:19 Base address:0x2000
-
[root@oracle ~]# ifconfig |grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}'
-
192.168.17.202
-
192.168.17.255
-
[root@oracle ~]# ifconfig eth0 | grep -oE '([0-9a-zA-Z]{1,2}:){5}[0-9a-zA-Z]{1,2}'
-
00:0C:29:50:CB:D9
阅读(1677) | 评论(0) | 转发(0) |