第五章 文本处理工具和正则表达式

显示/proc/meminfo文件中以大小s开头的行(要求:使用两种方法)
[root@10-13-9-63 litao]# grep -i ^s meminfo
[root@10-13-9-63 litao]# grep [1] meminfo

显示/etc/passwd文件中不以/bin/bash结尾的行
[root@10-13-9-63 litao]# grep -v /bin/bash$ /etc/passwd

显示用户rpc默认的shell程序
[root@10-13-9-63 litao]# grep ^rpc /etc/passwd | cut -d : -f 7

找出/etc/passwd中的两位或三位数
grep -o "<[0-9]{2,3}>" /etc/passwd

显示CentOS7的/etc/grub2.cfg文件中,至少以一个空白字符开头的且后面有非空白字符的行
grep “[[:space:]]+.*[[:space:]]$” /etc/grub2.cfg

利用df和grep,取出磁盘各分区利用率,并从大到小排序
df |grep “/dev/sda”|grep -o “[0-9]{1,2}%”|sort -nr

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

显示CentOS7上所有UID小于1000以内的用户名和UID

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


  1. Ss ↩︎

posted @ 2021-02-22 21:26  湘北10#  阅读(50)  评论(0编辑  收藏  举报