0805作业

课堂练习

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

  ifconfig|tr -cs '[0-9].' '\n'|sort -ut '.' -k3

blob.png

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

  df|tr -s ' '|cut -d" " -f5|sort -n|tail -1

blob.png

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

  getent passwd |sort -n -t: -k3|cut -d: -f1,3,7|tail -1

blob.png

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

  如果无特殊权限位,将rwx—>421,权限位每三个求和

  str=`ll -d /tmp|cut -d " " -f1|cut -c2-10|tr rwx- 4210`

echo $(echo ${str:0:1}+${str:1:1}+${str:2:1}|bc) $(echo ${str:3:1}+${str:4:1}+${str:5:1}|bc) $(echo ${str:6:1}+${str:7:1}+${str:8:1}|bc)|tr -d [:space:]

输出755

 

 

stat /tmp|sed -n 4p|cut -d: -f2|cut -d" " -f2|grep [[:digit:]]|cut -d/ -f1|cut- c3-6

blob.png

stat /bin/cat |head -4|tail -1|tr " " "\n"|head -n2|tail -1|tr -cd '[:digit:]'

blob.png

stat /tmp –c %a

blob.png

 

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

netstat -nt|tr -s " "| cut -d" " -f5|grep "[0-9]"|cut -d: -f1|uniq -c|sort

blob.png

 

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

cat /proc/meminfo |grep -i ^s.*

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

grep '^[sS].*' /proc/meminfo

blob.png

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

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

blob.png

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

getent passwd rpc|cut -d: -f7 

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

blob.png

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

cat /etc/passwd|grep -w '\b[1-9][0-9]\{1,2\}\b'

blob.png

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

cat /etc/grub2.cfg |grep "^[[:space:]]\+.*[^[:space:]]"

blob.png

11.找出"netstat -tan" 命令的结果中以'LISTEN' 后跟0 1或多个空白字符结尾的行

netstat -tan|grep 'LISTEN[[:space:]]*$'

blob.png

12.添加用户bash testbash basher 以及nologin( shell /sbin/nologin),

而后找出/etc/passwd 文件中用户名同shell

useradd bash; useradd testbash; useradd basher

useradd –s /sbin/nologin nologin

cat /etc/passwd|grep '^\<\(.*\)\>.*/\1$'

blob.png

13.显示当前系统root mage wang 用户的UID 和默认shell

grep -E "^(root|wang|mage)\b" /etc/passwd|cut -d: -f3,7

blob.png

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

cat /etc/rc.d/init.d/functions |egrep "^[[:alnum:]_]+\(\)"    —最后括号转义

blob.png

 

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

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

blob.png

注意对比下面

blob.png

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

echo "/etc/rc.d/init.d/functions" |egrep -o "(/.*/)"

blob.png

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

last|grep -E -o "^root\>.*([[:digit:]]+\.)[[:digit:]]+"|tr -s " "|cut -d" " -f1,3|sort|uniq –c

blob.png

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

grep -E "[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]" file

 

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

ifconfig|grep -E -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])"

blob.png

 

作业

1.取本机ip地址

ifconfig | egrep -o '([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])\.([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])'

blob.png

blob.png

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

blob.png

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

cat /etc/init.d/functions |tr -c '[:alpha:]' '\n'|sort|uniq –c

blob.png

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

blob.png

/etc/rc.d/init.d/functions/取目录名

blob.png

5.正则表达式表示身份证号

cat identify |egrep -o "[[:digit:]]{18}|[[:digit:]]{17}X|[[:digit:]]{15}"

blob.png

6.正则表达式表示手机号

cat phone |egrep -o "[1-9][0-9]{10}"

blob.png

7.正则表达式表示邮箱

cat mail |egrep -o "[[:alnum:]_]+@[[:alnum:]]+.[[:alnum:]]+"

blob.png

8.正则表达式表示QQ

grep "[1-9][0-9]\{4,9\}$"

blob.png

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

(0)
上一篇 2016-08-07 22:05
下一篇 2016-08-07 22:06

相关推荐

  • Each time you desire when you want to buy a capstone project, distinct quantity of everything you to assist in the head

    Greatest Buy a Capstone Project When you want to buy a capstone project at https://buycapstone.com/capstone-project-writing-service, you’ll find particular factors you have t…

    Linux干货 2022-12-15
  • 用户权限以及grep简单应用

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 cp -a /etc/skel /home/tuser1 chmod -R o-rx /home/tuser1 chmod -R g-rx /home/tuser1 2、编辑/etc/group文件,添加组hadoop。 e…

    Linux干货 2018-09-09
  • bash之脚本入门及课后作业

    概述: shell是一个工具程序,在用户登录后后系统启动,它解释并运行由命令或脚本文件输入的命令,从而实现用户与内核之间的交互。bash是Linux操作系统上默认的shell,在交互和编程两方面,bash提供了许多Bourne shell没有的功能,并且还结合了C shell和Kron shell最有用的功能。 bash的语法和结构   …

    Linux干货 2016-08-15
  • LB-lvs

    Linux Cluster: Cluster:计算机集合,为解决某个特定问题组合起来形成的单个系统; Linux Cluster类型: LB:Load Balancing,负载均衡; HA:High Availiablity,高可用; A=MTBF/(MTBF+MTTR) (0,1):90%, 95%, 99%, 99.5%, 99.9%, 99.99%, …

    Linux干货 2017-06-25
  • http配置文件中文文档

    Apache中Httpd.conf详解 Apache 的 httpd.conf 详解 # # Apache服务器主配置文件. 包括服务器指令的目录设置. # 详见 <URL:http://www.apache.org/docs/>  # # 请在理解用途的基础上阅读各指令。 # # 再读取此文档后,服务器将继续搜索运行 # E:/Pro…

    Linux干货 2017-08-08
  • Linux基础-用户管理相关操作-week 4

    1.复制/etc/skel 目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其他用户均没有任何访问权限  cp /etc/skel /home/tuser1 -rf chmod og=  /home/tuser1 -R 2.编辑/etc/group文件添加组hadoop echo hadoop:x:503 …

    Linux干货 2016-11-21