第六次作业

shell编程之awk
1、获取根分区剩余大小
2、获取当前机器ip地址
3、统计出apache的access.log中访问量最多的5个IP
4、打印/etc/passwd中UID大于500的用户名和uid
5、/etc/passwd 中匹配包含root或net或ucp的任意行
6、处理以下文件内容,将域名取出并根据域名进行计数排序处理(百度搜狐面试题)
test.txt
http://www.baidu.com/index.html
http://www.baidu.com/1.html
http://post.baidu.com/index.html
http://mp3.baidu.com/index.html
http://www.baidu.com/3.html
http://post.baidu.com/2.html
7、请打印出/etc/passwd 第一个域,并且在第一个域所有的内容前面加上“用户帐号:”
8、请打印出/etc/passwd 第三个域和第四个域
9、请打印第一域,并且打印头部信息为:这个是系统用户,打印尾部信息为:"================"
10、请打印出第一域匹配daemon的信息.
11、请将/etc/passwd 中的root替换成gongda,记住是临时替换输出屏幕看到效果即可.
12、请匹配passwd最后一段域bash结尾的信息,有多少条
13、请同时匹配passwd文件中,带mail或bash的关键字的信息

1) df -h / | tail -1 | awk ‘{print $4}’
6.4G
2)ifconfig eno16777736 | grep “inet " | awk ‘{print $2}’
192.168.150.140
4)awk -F: ‘$3>500 {printf “%-25s%-s\n”,$1,$3}’ /etc/passwd
5)
awk ‘/(root|net|ucp)/ {print $0}’ /etc/passwd
root❌0:0:root:/root:/bin/bash
operator❌11:0:operator:/root:/sbin/nologin
systemd-network❌998:996:systemd Network Management:/:/sbin/nologin
6) cat baidu_test.txt
http://www.baidu.com/more/
http://www.baidu.com/guding/more.html
http://www.baidu.com/events/20060105/photomore.html
http://hi.baidu.com/browse/
http://www.sina.com.cn/head/www20021123am.shtml
http://www.sina.com.cn/head/www20041223am.shtml
awk -F ‘/’ ‘{print $3}’ baidu_test.txt | sort | uniq -c | sort -nr
3 www.baidu.com
2 www.sina.com.cn
1 hi.baidu.com
7)awk -F: ‘{print “用户账号:” $1}’ /etc/passwd
8)awk -F: '{printf”%-10s%-d\n",$3,$4}’ /etc/passwd

9)awk -F: ‘BEGIN {print “这个是系统用户”}{print $1} END {print"================"}’ /etc/passwd
10)awk -F: ‘KaTeX parse error: Expected '}', got 'EOF' at end of input: …n 12)awk -F: '{NF~/bash/}{print NR}’ /etc/passwd | wc -l
46

13)awk -F: ‘{$NF~/bash/}{print NR}’ /etc/passwd | wc -l
46awk -F: ‘$0~/root|mail/’ /etc/passwd
root❌0:0:root:/root:/bin/bash
mail❌8:12:mail:/var/spool/mail:/sbin/nologin
operator❌11:0:operator:/root:/sbin/nologin

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值