练习7

作者: jie0112 | 来源:发表于2017-06-05 20:44 被阅读0次

1、显示/proc/meminfo文件中以大小s开头的行(要求:使用两种方法)
grep "^[sS]" /proc/meminfo
grep "^(s|S)" /proc/meminfo
egrep "^(s|S)" /proc/meminfo
grep -e ^s -e ^S /proc/meminfo
2、显示/etc/passwd文件中不以/bin/bash结尾的行
grep -v "/bin/bash$" /etc/passwd
3、显示用户rpc默认的shell程序
getent passwd rpc|cut -d: -f1,7
grep "^rpc>" /etc/passwd |cut -d: -f1,7
4、找出/etc/passwd中的两位或三位数
grep -o "<[0-9]{2,3}>" /etc/passwd
5、显示CentOS7的/etc/grub2.cfg文件中,至少以一个空白字符开头的且后面存非空白字符的行
grep "[[:space:]]{1,}[[:space:]]{1,}" /etc/grub2.cfg
6、找出“netstat -tan”命令的结果中以‘LISTEN’后跟任意多个空白字符结尾的行
netstat -tan|egrep -o "<LISTEN>[[:space:]]$"
7、显示CentOS7上所有系统用户的用户名和UID
cat /etc/passwd|cut -d: -f1,3|egrep "<[0-9]{1,3}>"
8、添加用户bash、testbash、basher、sh、nologin(其shell为/sbin/nologin),找出/etc/passwd用户名同shell名的行
cat /etc/passwd|egrep "(^.
)>./\1$"
egrep "(^.
)>.*<\1$" /etc/passwd
9、利用df和grep,取出磁盘各分区利用率,并从大到小排序
df |gerp -o "^/dev/sd"|egrep "<[0-9]+%>"|tr -d %story -nr
df |grep "^/dev/sd"|tr -s " " "%"|cut -d% -f5|sort -nr

10、显示三个用户root、mage、wang的UID和默认shell
grep "^(root>|mage|wang)>" /etc/passwd|cut -d: -f1,3,7
egrep "^(root|mage|wang)>" /etc/passwd|cut -d: -f1,3,7
11、找出/etc/rc.d/init.d/functions文件中行首为某单词(包括下划线)后面跟一个小括号的行
egrep -o "^.\b()" /etc/rc.d/init.d/functions
egrep -o "^.
>()" /etc/rc.d/init.d/functions
egrep -o '^([[:alnum:]]|)+()' /etc/rc.d/init.d/functions
egrep -o '^[[:alnum:]
]+()' /etc/rc.d/init.d/functions
egrep -o '^[a-zA-Z0-9_]+()' /etc/rc.d/init.d/functions
12、使用egrep取出/etc/rc.d/init.d/functions中其基名
echo /etc/rc.d/init.d/functions|cut -d"/" -f5
echo /etc/rc.d/init.d/functions|egrep -o "[^/]+$" 文件
echo /etc/rc.d/init.d/functions |grep -Eo "[[:alnum:]]+$" 文件
echo /etc/rc.d/init.d/functions|egrep -o "[^/]+/?$"
basename /etc/rc.d/init.d/functions
13、使用egrep取出上面路径的目录名
echo /etc/rc.d/init.d/functions|egrep -o "/./."|grep -o ""/./"
dirname /etc/rc.d/init.d/functions
14、统计last命令中以root登录的每个主机IP地址登录次数
last |egrep -o "^root>"|egrep -o"([0-9]|[0-9]{2}|[0-9]{3})(.([0-9]|[0-9]{2}|[0-9]{3})){3}"|sort|uniq -c

15、利用扩展正则表达式分别表示0-9、10-99、100-199、200-249、250-255
[0-9]
[1-9][0-9]
1[0-9]{2}
2[0-4][0-9]
25[0-5]
(([0-9]|[1-9][0-9]|[1[0-9][{2}|2[0-4][0-9]|25[0-5]).){3}(([0-9]|[1-9][0-9]|[1[0-9][{2}|2[0-4][0-9]|25[0-5])
16、显示ifconfig命令结果中所有IPv4地址
ifconfig |egrep -o "<(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])>"
17、将此字符串:welcome to magedu linux 中的每个字符去重并排序,重复次数多的排到前面
echo "welcome to magedu linux" |tr -d " " |egrep -o [[:alnum:]] |sort|uniq -c|sort -nr
echo "welcome to magedu linux" |grep -o '.'|sort |uniq -c|sort -nr

相关文章

  • UG编程练习图持续更新,需要的小伙伴请自行保存哦!

    练习1 练习2 练习3 练习4 练习5 练习6 练习7 练习8 练习9 练习10 练习11 练习12 练习13 练...

  • 练习7

    九宫格 关键词:旅游 时间:5分钟 编故事 时间:10分钟 关键词:旅游、高山、山泉

  • 练习7

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

  • 练习7

    练习下下 唉,手残,涂个颜色就把眼睛画毁了

  • 练习7

    用while循环完成以下练习1.编写脚本,求100以内所有正奇数之和 2.编写脚本,提示请输入网路地址,如192....

  • 练习7

    此刻,我坐在卧室的床上,听见远远的鞭炮声,听见孩子的呼吸声,抬头看见黑乎乎的一片天空,看见两个红红的灯,像两团火。...

  • 练习7

  • 练习7

    练习七 【如何面对自己的不愿意和害怕】 观察自己一整天的工作,当发现自己面对其中 [一件事], 心里感觉 [不愿意...

  • 练习(7)

    读书读得越来越多,就越发现这么一个道理:你不知道的永远比你知道的更有意义!

  • 练习7

    梅甘和朋友刚从购物中心出来,正朝她们的车走去。 这时,梅甘看到一个女人多次打自己年幼儿子的屁股,然后把他推进了自己...

网友评论

      本文标题:练习7

      本文链接:https://www.haomeiwen.com/subject/qlnsfxtx.html