从0开始学习Shell--小工具的综合练习
2021/4/19 7:25:35
本文主要是介绍从0开始学习Shell--小工具的综合练习,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
综合练习
截取IP地址
[root@localhost ~]# ifconfig eth0 | grep netmask | tr -d 'a-zA-Z' | tr ' ' '\n' | grep -v '^$'
192.168.209.128
255.255.255.0
192.168.209.255
[root@localhost ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.209.128 netmask 255.255.255.0 broadcast 192.168.209.255
inet6 fe80::20c:29ff:fe1d:8d4b prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:1d:8d:4b txqueuelen 1000 (Ethernet)
RX packets 11880 bytes 1013594 (989.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5972 bytes 880074 (859.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
截取MAC地址
[root@localhost ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.209.128 netmask 255.255.255.0 broadcast 192.168.209.255
inet6 fe80::20c:29ff:fe1d:8d4b prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:1d:8d:4b txqueuelen 1000 (Ethernet)
RX packets 11880 bytes 1013594 (989.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5972 bytes 880074 (859.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# ifconfig eth0 | grep ether
ether 00:0c:29:1d:8d:4b txqueuelen 1000 (Ethernet)
[root@localhost ~]# ifconfig eth0 | grep ether | cut -d ' ' -f1
[root@localhost ~]# ifconfig eth0 | grep ether | cut -d ' ' -f2
[root@localhost ~]# ifconfig eth0 | grep ether | cut -d ' ' -f10
00:0c:29:1d:8d:4b
[root@localhost ~]# ifconfig eth0 | grep ether | tr -s ' '
ether 00:0c:29:1d:8d:4b txqueuelen 1000 (Ethernet)
[root@localhost ~]# ifconfig eth0 | grep ether | tr -s ' ' | cut -d' ' -f2
ether
[root@localhost ~]# ifconfig eth0 | grep ether | tr -s ' ' | cut -d' ' -f4
txqueuelen
[root@localhost ~]# ifconfig eth0 | grep ether | tr -s ' ' | cut -d' ' -f1
[root@localhost ~]# ifconfig eth0 | grep ether | tr -s ' ' | cut -d' ' -f2
ether
[root@localhost ~]# ifconfig eth0 | grep ether | tr -s ' ' | cut -d' ' -f3
00:0c:29:1d:8d:4b
[root@localhost ~]#
要求将系统中所有普通用户的用户名,密码和默认的shell保存到一个文件中,要求用户名和密码之间使用tab分割
先过滤普通用户
[root@localhost tmp]# grep 'bash$' passwd 找到bash结尾的用户
root:x:0:0:root:/root:/bin/bash
redhat:x:1000:1000:redhat:/home/redhat:/bin/bash
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]# grep 'bash$' passwd | grep -v 'root' 去除掉root用户
redhat:x:1000:1000:redhat:/home/redhat:/bin/bash
[root@localhost tmp]#
[root@localhost tmp]# grep 'bash$' passwd | grep -v 'root' | cut -d: -f1,2,7 | tr ':' '\t' | tee passwdnew.txt
redhat x /bin/bash
这篇关于从0开始学习Shell--小工具的综合练习的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南