8月5日作业

课堂练习:

1、找出ifconfig命令结果中本机的所有IPv4地址

[root@localhost ~]# ifconfig | tr -s " " |head -2 | tail -1 |cut -d: -f2 | cut -d" " -f1

2、查出分区空间使用率的最大百分比值

[root@localhost ~]# df -h | tr -s " " |cut -d" " -f5 | sort -n

3、查出用户UID最大值的用户名、UID及shell类型 

[root@localhost ~]# cat /etc/passwd | cut -d: -f1,3,7 /etc/passwd |sort -n -t: -k2| tail -1

4、查出/tmp的权限,以数字方式显示 ?

[root@localhost ~]# stat /tmp/ | tr -s " " |head -4 | tail -1| cut -d/ -f1 | cut -d"(" -f2

5、统计当前连接本机的每个远程主机IP的连接数,并按从大 到小排序

[root@localhost ~]# netstat -net |tr -s " " | cut -d" " -f5 |cut -d":" -f1 |uniq -c

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

[root@localhost ~]# grep -i ^s /proc/meminfo
[root@localhost ~]# grep  "^[s|S]" /proc/meminfo

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

[root@localhost ~]# grep -v "/bin/bash" /etc/passwd

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

[root@localhost ~]# grep "\<rpc" /etc/passwd -w |cut -d: -f7

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

[root@localhost ~]# grep "[0-9][0-9][0-9]\?" /etc/passwd
[root@localhost ~]#  grep "\<[0-9]\{2,3\}\>" /etc/passwd

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

[root@nzg7 ~]# grep "^[[:space:]]\+[^[:space:]]" /etc/grub2.cfg

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

[root@localhost ~]# netstat -tan | grep "LISTEN[[:space:]]*$"

12、添加用户bash、testbash、basher以及nologin(其shell为 /sbin/nologin),而后找出/etc/passwd文件中用户名同shell名 的行

[root@localhost ~]# grep "^\([^:]\+\>\).*\<\1\>$" /etc/passwd

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

[root@localhost ~]# grep -E "^(root|mage|wang)\b" /etc/passwd |cut -d: -f1,3,7

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

[root@localhost ~]# grep -E "^[_[:alpha:]]+\(\)" /etc/rc.d/init.d/functions -o

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

[root@localhost ~]# echo "/etc/sysconfig/network-scripts/ifcfg-eth0/" | grep -E "[^/]+/?$" -o |grep -E [^/]+ -o

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

[root@localhost ~]# echo "/etc/sysconfig/network-scripts/ifcfg-eno16777736/" | grep -E -o "^/.*[^/]" |grep -E -o "^/.*/"

17、统计以root身份登录的每个远程主机IP地址的登录次数 

[root@localhost ~]# last |tr -s " "|cut -d" " -f1,3 |grep "^root [[:digit:]]" |sort -n|uniq -c

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

[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]

19、显示ifconfig命令结果中所有IPv4地址

[root@localhost ~]# ifconfig |grep -E "(\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"

课后作业:

1、取本机ip地址

[root@localhost ~]# ifconfig |grep -E "(\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"

2、取各分区利用率的数值

[root@localhost ~]# df -h | tr -s " " |cut -d" " -f5 |tr -sc [0-9] '\n' |sort -n

3、统计/etc/init.d/functions 文件中每个单词出现的次数,并按频率从高到低显示

[root@localhost ~]# cat /etc/init.d/functions |grep -E "\<[[:alpha:]]+\>" -o |sort |uniq -c |sort -n

4、/etc/rc.d/init.d/functions或/etc/rc.d/init.d/functions/"  取目录名

echo "/etc/rc.d/init.d/functions/" | grep -E "^/.*[^/]" -o |grep -E "^/.*/" -o

原创文章,作者:闹钟哥,如若转载,请注明出处:http://www.178linux.com/31726

(0)
闹钟哥闹钟哥
上一篇 2016-08-15 14:31
下一篇 2016-08-15 14:31

相关推荐

  • 马哥教育网络班第21期+第六周课程作业

    1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的1、以至少一个空白字符开头的行的行首加#; :%s@^[[:space:]]\+@#@   2、复制/boot/grub/grub.conf至/tmp目录中,删除/tmp/grub.conf文件中的行首的空白字符; :%s@^[[:space…

    Linux干货 2016-08-22
  • NoSQL—mongodb常见使用和入门

    NoSQL介绍: NoSQL数据管理系统是目前非常流行的一种非关系性、分布式、不支持ACID设计规范式的数据库;NoSQL简单的数据模型、元数据和数据分离、弱一致性、高吞吐量、高水平扩展能力和低端硬件集群使其流行的主要原因,而mongodb就是NoSQL数据库一种非常流行的实现方式。   常见的NoSQL数据存储模型 列式模型 文档类型 应用场景:…

    2015-09-01
  • N27_第五周作业

    一、显示当前系统上root、fedora或者user1用户的默认shell; [root@localhost ~]# grep -E “^(root|fedora|user1)” /etc/passwd | cut -d: -f7 /bin/bash /bin/tcsh /bin/bash二、找出/etc/rc.d/init.d/fu…

    Linux干货 2017-10-20
  • MBR与GPT分区结构的不同及磁盘分区命令总结

    一、MBR分区结构 主引导记录(Master Boot Record,缩写:MBR),又叫做主引导扇区,是目前比较流行的一种分区结构。磁盘的0磁道0扇区称为MBR,它的大小是512字节,这个区域被分为三个部分: 第一部分为boot loader(主引导程序),占446字节; 第二部分为Partition table(分区表),即DPT,占64字节,每个分区项…

    Linux干货 2016-08-29
  • N22-第一周博客作业

    1、计算机的组成和及其功能? 计算机由硬件,操作系统,软件三大部分组成。 硬件: 计算机系统中所使用的电子线路和物理设备,主要由中央处理器( CPU )、存储器、外部设备(输入输出设备、I/O设备)及总线等组成。 a、中央处理器(CPU)的主要功能是根据存储器内的程序 ,逐条地执行程序所指定的操作。中央处理器的主要组成部分是:数据寄存器、指令寄存器、指令译码…

    Linux干货 2016-08-15
  • 关于文件权限管理了解和使用

                    文件权限管理   文件属性格式              文件属性操作 chown          设置文件的所有者…

    系统运维 2016-08-05