加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

LINUX教学:Linux文本处理工具作业

发布时间:2020-12-13 17:49:35 所属栏目:Linux 来源:网络整理
导读:《LINUX教学:Linux文本处理工具作业》要点: 本文介绍了LINUX教学:Linux文本处理工具作业,希望对您有用。如果有疑问,可以联系我们。 1 、显示 /proc/meminfo 文件中以大小 s 开头的行 ( 要求:使用两种办法 ) 1 办法一: cat /proc/meminfo | grep -i ^ s

《LINUX教学:Linux文本处理工具作业》要点:
本文介绍了LINUX教学:Linux文本处理工具作业,希望对您有用。如果有疑问,可以联系我们。

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

1 办法一:cat /proc/meminfo |grep -i ^s
2 办法二:cat /proc/meminfo |grep ^[sS]

?

?

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

1 cat /etc/passwd | grep -v /bin/bash

?

3、显示用户rpc默认的shell法式

?

?

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

1 cat /etc/passwd |grep "b[0-9]{2,3}b"

?

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

1 cat /etc/grub2.cfg |egrep "^[[:space:]]+[[:graph:]].*"

?

6、找出"netstat -tan"命令的成果中以'LISTEN'后跟任意多个空白字符结尾的行

1 netstat -tan |grep "LISTEN[[:space:]]+$"

?

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

1 办法一:getent passwd |cut -d: -f1,3 |grep -v root |grep "b[[:digit:]]{1,3}b$"
2 办法二:getent passwd |cut -d: -f1,3 |grep -ve root -e "b[[:digit:]]{4,}b"

?

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

1 cat /etc/passwd |grep -o "^(.+b).*b1$"

?

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

1 df |grep sd |grep -Eo "[0-9]{1,3}%" |sort -nr

?

10、显示三个用户root、mage、wang的UID和默认shell

1 cat /etc/passwd |egrep "^(root|mage|wang)b" |cut -d: -f3,7

?

11、找出/etc/rc.d/init.d/functions文件中行首为某单词(包括下划线)后面跟一个小括号的行

1 办法一:cat /etc/rc.d/init.d/functions |grep -o "^.*[[:graph:]]()"
2 办法二:cat /etc/rc.d/init.d/functions |egrep "^.*[^[:space:]]()"
3 办法三:cat /etc/rc.d/init.d/functions |egrep -o "^.*&;()"

?

12、使用egrep掏出/etc/rc.d/init.d/functions中其基名

1 echo /etc/rc.d/init.d/functions | egrep -o "[^/]+/?$"

?

13、使用egrep取出上面路径的目录名

1 办法一:echo /etc/rc.d/init.d/functions | egrep -o "^/.*/b"
2 办法二:echo /etc/rc.d/init.d/functions |egrep -o ".*/." |egrep -o ".*/" /etc/rc.d/init.d/

?

14、统计last敕令中以root登录的每个主机IP地址登录次数

1 last |grep ^root |egrep -o "([0-9]{1,3}.){3}[0-9]{1,3}" |sort |uniq -c

?

15、利用扩展正则表达式分别表现0-9、10-99、100-199、200-249、250-255

1  b[0-9]b                       0-9
2  b[0-9]{2}b                    10-99 
3  b[1][0-9]{2}b                 100-199
4  b[2][0-4][0-9]b               200-249
5  b[2][5][0-5]b                 250-255

?

16、显示ifconfig命令成果中所有IPv4地址

1 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 中的每个字符去重并排序,反复次数多的排到前面

1 echo "welcome to magedu linux" |grep -o "." |sort |uniq -c |sort -nr 

本文永远更新链接地址

《LINUX教学:Linux文本处理工具作业》是否对您有启发,欢迎查看更多与《LINUX教学:Linux文本处理工具作业》相关教程,学精学透。编程之家PHP学院为您提供精彩教程。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读