grep正则表达式

1.

[root@localhost ~]# grep bash /etc/passwd
root:x:0:0:root:/root:/bin/bash
open:x:1000:1000:open:/home/open:/bin/bash

2.

[root@localhost ~]# grep -o "\<[0-9]\{3,4\}\>" /etc/passwd
100
999
997
998
997
996
177
177
996
994
995
992
990
990
989
989
988
988
1000
1000

3.

[root@localhost ~]#   grep E "^[[:space:]]+[^[:space:]]+" /etc/grub2.cfg 
grep: ^[[:space:]]+[^[:space:]]+: No such file or directory
/etc/grub2.cfg:# DO NOT EDIT THIS FILE
/etc/grub2.cfg:### BEGIN /etc/grub.d/00_header ###
/etc/grub2.cfg:### END /etc/grub.d/00_header ###
/etc/grub2.cfg:### BEGIN /etc/grub.d/00_tuned ###
/etc/grub2.cfg:### END /etc/grub.d/00_tuned ###
/etc/grub2.cfg:### BEGIN /etc/grub.d/01_users ###
/etc/grub2.cfg:### END /etc/grub.d/01_users ###
/etc/grub2.cfg:### BEGIN /etc/grub.d/10_linux ###
/etc/grub2.cfg:menuentry 'openEuler (5.10.0-153.12.0.92.oe2203sp2.x86_64) 22.03 (LTS-SP2)' --class openeuler --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-5.10.0-153.12.0.92.oe2203sp2.x86_64-advanced-ebb79a5c-063b-4f85-9c57-4d690e736c5e'

4.

[root@localhost ~]# netstat -tan | grep "\<LISTEN.*\>"
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN    

5.

[root@localhost ~]# fdisk -l | grep -E "^/dev/[sh]d[a-z]"
/dev/sda1  *       2048  2099199  2097152   1G 83 Linux
/dev/sda2       2099200  6293503  4194304   2G 82 Linux swap / Solaris
/dev/sda3       6293504 41943039 35649536  17G 83 Linux

 6.

[root@localhost ~]# ldd /usr/bin/cat | grep -o "/[^[:space:]]\+"
/usr/lib64/libc.so.6
/lib64/ld-linux-x86-64.so.2

7.

[root@localhost ~]# grep -i ^s /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB


[root@localhost ~]# grep -i ^[sS] /proc/meminfo
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:             17352 kB

8.

[root@localhost ~]# grep -E "(root|centos|spark)" /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin

9.

[root@localhost ~]#  echo /mnt/sdc/ | grep -E -o "[^/]+/?$" | cut -d "/" -f 1
sdc

10.

[root@localhost ~]# ifconfig | grep -o -E "\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>"
192
168
30
130
255
255
255
192
168
30
255
64
29
61
9
5
73
127
1
255
1
128
8
8

11.

[root@localhost ~]# grep "^\(.*\):.*\1$" /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值