文本处理练习

1、找出ifconfig “网卡名” 命令结果中本机的IPv4地址

[root@rocky-8 ~]# ifconfig |head -n+2 |tail -1 | cut -d ' ' -f 10
192.168.44.18

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

[root@rocky-8 ~]# df |cut -b 48-50 | tail -n +2 |sort -n -r |head -n 1
 22
[root@rocky-8 ~]# 

3、查出用户UID最大值的用户名、UID及shell类型
root: x: 0: 0: root: /root: /bin/bash
用户名:口令:用户标识号:组标识号:注释性描述:主目录:登录Shell

[root@rocky-8 ~]# cat /etc/passwd |cut -d : -f 1,3,7 |sort -t: -nk2 -r |head -n 1
nobody:65534:/sbin/nologin

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

root@ubuntu2004:~# stat /tmp |head -n +4|tail -1 |cut -d' ' -f2
(1777/drwxrwxrwt)
root@ubuntu2004:~# stat /tmp |head -n +4|tail -1 |cut -d' ' -f2|cut -b 2-5
1777
root@ubuntu2004:~# 

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

[root@rocky-8 ~]# ss -nut 
Netid    State    Recv-Q    Send-Q       Local Address:Port          Peer Address:Port     Process    
tcp      ESTAB    0         0            192.168.44.18:22            192.168.44.1:61269               
tcp      ESTAB    0         0            192.168.44.18:22           192.168.44.28:60844               
tcp      ESTAB    0         0            192.168.44.18:22            192.168.44.1:61021               
tcp      ESTAB    0         36           192.168.44.18:22            192.168.44.1:56595               
[root@rocky-8 ~]# ss -nut | tr -s ' '
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
tcp ESTAB 0 0 192.168.44.18:22 192.168.44.1:61269 
tcp ESTAB 0 0 192.168.44.18:22 192.168.44.28:60844 
tcp ESTAB 0 0 192.168.44.18:22 192.168.44.1:61021 
tcp ESTAB 0 36 192.168.44.18:22 192.168.44.1:56595 
[root@rocky-8 ~]#
[root@rocky-8 ~]# ss -nut | tr -s ' ' |cut -d ' ' -f6| cut -d : -f1 | tail -n +2 |sort -r 
192.168.44.28
192.168.44.1
192.168.44.1
192.168.44.1

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值