SHELL第七天

1、获取根分区剩余大小

[root@localhost day4]# df -h | awk '/\/$/{print $4}'

在这里插入图片描述

2、获取当前机器ip地址

[root@localhost day4]# ifconfig eno16777736 | awk '/inet /{print $2}'

在这里插入图片描述

3、统计出apache的access.log中访问量最多的5个IP

[root@localhost day4]# awk '{addr[$1]++} END{for (a in addr) {print addr[a],a}}' access.log| sort -nr | head -5

在这里插入图片描述

4、打印/etc/passwd中UID大于500的用户名和uid

[root@localhost day4]# awk -F: '$3>500{print $1,$3}' /etc/passwd

在这里插入图片描述

5、/etc/passwd 中匹配包含root或net或ucp的任意行

[root@localhost day4]# awk '/root|net|ucp/{print $0}' /etc/passwd

在这里插入图片描述

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 第一个域,并且在第一个域所有的内容前面加上“用户帐号:”

[root@localhost day4]# awk -F: '{print "用户账号:" $1}' /etc/passwd

在这里插入图片描述

8、请打印出/etc/passwd 第三个域和第四个域

[root@localhost day4]# awk -F: '{print $3,$4}' /etc/passwd

在这里插入图片描述

9、请打印第一域,并且打印头部信息为:这个是系统用户,打印尾部信息为:"================"

[root@localhost day4]# awk -F: 'BEGIN {print "这个是系统用户"} {print $1} END{print "================"}' /etc/passwd

在这里插入图片描述

10、请打印出第一域匹配daemon的信息.

[root@localhost day4]# awk -F: '{if ($1=="daemon") print}' /etc/passwd

在这里插入图片描述

11、请将/etc/passwd 中的root替换成gongda,记住是临时替换输出屏幕看到效果即可.

[root@localhost day4]# sed -n 's/root/gongda/g p' /etc/passwd

在这里插入图片描述

12、请匹配passwd最后一段域bash结尾的信息,有多少条

[root@localhost day4]# awk -F: '{arr[$NF]++} END{for (v in arr) {print arr[v],v}}' /etc/passwd | grep bash

在这里插入图片描述

13、请同时匹配passwd文件中,带mail或bash的关键字的信息

[root@localhost day4]# awk '/mail|bash/{print}' /etc/passwd

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值