2019-02-04基本正则习题

2019-02-04  本文已影响0人  Yann1

1、显示/proc/meminfo文件中以大小s开头的行(要求:使用两种方法)

grep -e ^s.* -e ^S.*  /proc/meminfo

grep ^[s,S].* /proc/meminfo

2、显示/etc/passwd文件中不以/bin/bash结尾的行

grep -v "/bin/bash$" /etc/passwd

grep -v "/bin/bash\>" /etc/passwd

3、显示用户rpc默认的shell程序

grep "^rpc\>" /etc/passwd |cut -d":" -f7

4、找出/etc/passwd中的两位或三位数

grep "\<[0-9]\{2,3\}\>" /etc/passwd

5、显示CentOS7的/etc/grub2.cfg文件中,至少以一个空白字符开头的且后面存非空白字符的行

grep "^ .\+" /etc/grub2.cfg

6、找出“netstat -tan”命令的结果中以‘LISTEN’后跟任意多个空白字符结尾的行

netstat -tan|grep "LISTEN *"

7、显示CentOS7上所有系统用户的用户名和UID

cut -d":" -f 1,3 /etc/passwd| grep ":[^0][0-9]\{1,2\}\>"

8、添加用户bash、testbash、basher、sh、nologin(其shell为/sbin/nologin),找出/etc/passwd用户名同shell名的行

useradd testbash -s /sbin/nologin

useradd basher -s /sbin/nologin

useradd sh -s /sbin/nologin

useradd nologin -s /sbin/nologin

grep "^\(.*\)\>.*\1\>$" /etc/passwd

9、利用df和grep,取出磁盘各分区利用率,并从大到小排序

df|egrep "[0-9]{1,3}\>%" -o |sort -t "%" -k1 -nr

df|egrep "[0-9]{1,3}\>%" -o |tr -d %|sort -nr

上一篇 下一篇

猜你喜欢

热点阅读