从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-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?