2つの正規表現

クリエイティブコモンズライセンス クリエイティブ・コモンズ

3)基本的なメタ文字^が、$ - 、ラインの最後の行の先頭に一致する
IDラインで始まるデフォルトの実行構成レコードの出力レベルを():

[root@svr5 ~]# egrep '^id' /etc/inittab
id:3:initdefault:

出力のホスト名の構成レコード(HOSTNAMEラインで始まります):

[root@svr5 ~]# egrep '^HOSTNAME' /etc/sysconfig/network
HOSTNAME=svr5.tarena.com

ユーザー統計シェルをログに記録するローカルユーザの数は、「/ sbinに/ nologinに」されています。

[root@svr5 ~]# egrep -m10 '/sbin/nologin$' /etc/passwd  //先确认匹配正确
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
[root@svr5 ~]# egrep -c '/sbin/nologin$' /etc/passwd
32  									//结合 -c 选项输出匹配的行数

これは、再びパイプトイレ-l効果により、出力ライン数と一致するように、-cオプションは同じですが、簡単に表現。たとえば、「/ binに/ bashの」統計情報の使用は、ユーザーの通常の数としてシェルの実行にログインします。

[root@svr5 ~]# egrep -c '/bin/bash$' /etc/passwd
26
或者
[root@svr5 ~]# egrep '/bin/bash$' /etc/passwd | wc -l
26

4)基本的なメタキャラクタ-任意の1文字に一致します。
/etc/rc.localのファイルには、例えば、テキストの内容を確認します:

[root@svr5 ~]# cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

:行/etc/rc.localのファイルの少なくとも一つの文字(N除く\改行)、すなわち非空白行を含む出力

[root@svr5 ~]# egrep '.' /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local

/etc/rc.localのファイル内の空白のライン出力(反転状態で-vオプション):

[root@svr5 ~]# egrep -v '.' /etc/rc.local

[root@svr5 ~]#

同様の作用効果以下に空行の操作:

[root@svr5 ~]# egrep '^$' /etc/rc.local

[root@svr5 ~]#

おすすめ

転載: blog.csdn.net/weixin_44774638/article/details/91947343