IP查看命令ifconfig: command not found相关事宜、vim编辑或者通过sed提取一行里的某个字符串插入到行的最前面-后向引用以及全国拼音相同的城市(地级市)明细列表及所属省份

一、IP查看命令ifconfig: command not found及相关事宜

    ifconfig是常用的查看本机的IP的命令 publish:January 17, 2018 -Wednesday ,用于配置GNU/Linux系统的网络接口。它显示网络接口卡的详细信息,包括IP地址,MAC地址,以及网络接口卡状态之类。但在最小化版本的RHEL 7以及它的克隆版本CentOS 7,Oracle Linux 7和Scientific Linux 7中找不到该命令了。我在某台centos5.7上遇到ifconfig: command not found

[root@test ~]$ cat /etc/issue
CentOS release 5.7 (Final)
Kernel \r on an \m
[root@test ~]$ ifconfig
-bash: ifconfig: command not found

     这说明服务器没有安装带有ifconfig命令的包,那是什么包提供了ifconfig命令呢?可以使用yum provides或者yum whatprovides来反向查找相关的安装包名称,下面的命令未找到,建立使用*/ifconfig或者*bin/ifconfig

[root@test ~]$ yum provides ifconfig    
Loaded plugins: fastestmirror, security
......
Warning: 3.0.x versions of yum would erroneously match against filenames.
 You can use "*/ifconfig" and/or "*bin/ifconfig" to get that behaviour
No Matches found
#下面试试whatprovides命令
[root@test ~]$ yum whatprovides ifconfig
Loaded plugins: fastestmirror, security
......
Warning: 3.0.x versions of yum would erroneously match against filenames.
 You can use "*/ifconfig" and/or "*bin/ifconfig" to get that behaviour
No Matches found
#这是在一台装了ifconfig上面执行的,然后试试发现能找到net-tools工具包名,未安装下好像也不能找到。。
[root@test ~]$ yum whatprovides "*/ifconfig"
Loaded plugins: fastestmirror, security
......   
net-tools-1.60-114.el6.x86_64 : Basic networking tools
Repo        : base
Matched from:
Filename    : /sbin/ifconfig

net-tools-1.60-110.el6_2.x86_64 : Basic networking tools
Repo        : installed
Matched from:
Filename    : /sbin/ifconfig

         net-tools包提供了ifconfig命令。所以需要安装net-tools包来使用ifconfig命令。执行:

yum install -y net-tools

        上面的系统都是5.7,yum也不更新了,未再处理。对于未安装ifconfig命令的情况如果要查看本机IP,可直接查看ip的配置文件,示例如下:
/etc/sysconfig/network-scripts/ifcfg-eth0       #eth0一般配置外网IP地址
/etc/sysconfig/network-scripts/ifcfg-eth1       #eth1配置内网IP地址
/etc/sysconfig/network-scripts/ifcfg-eth0:1     #还可以配置多个外网IP地址

#命令执行如下:
[root@test yum.repos.d]$ cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=118.181.168.12
NETMASK=255.255.255.0
#GATEWAY=118.181.168.1
[root@test yum.repos.d]$ cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=192.168.168.12
NETMASK=255.255.0.0
[root@test yum.repos.d]$ cat /etc/sysconfig/network-scripts/ifcfg-eth0:1
DEVICE=eth0:1
ONBOOT=yes
IPADDR=183.44.30.12
NETMASK=255.255.255.0
GATEWAY=183.44.30.1

         后期的趋势是不再推荐使用ifconfig命令。CentOS 7最小化系统,推荐使用 ip addr(ip address) 和 ip link 命令来查找网卡详情。要查看统计数据,可以使用ip -s link

 二、vim编辑或者通过sed提取一行里的某个字符串插入到行的最前面-后向引用

        有以下非常多行的代码,需要同时编辑,在经过替换后示例几行代码如下 publish:January 19, 2018 -Friday:

        有以下非常多行的代码,需要同时编辑,在经过替换后示例几行代码如下:

        while 1:
            body.get('table', None)
            body.get('switch', None)       
            body.get('uid', None) 
            body.get('ver', None)                                                                                          
            body.get('type', None)                                                                                         
            body.get('classnema', None)                                                                                    
            body.get('cid', None)
            body.get('public_time', None)
            break
        print('ok')

        现有需求需要批量将单引号里的内容提出来放至最前面最后形成一个赋值语句,最终想要实现的目标如下:

        while 1:
            table = body.get('table',None)
            switch = body.get('switch',None)
            uid = body.get('uid',None)
            ver = body.get('ver',None)
            type = body.get('type',None)
            classnema = body.get('classnema',None)
            cid = body.get('cid',None)
            public_time = body.get('public_time',None)
        print('ok')

        之前也用过vim或者sed里面的后向引用,今天正好拿这个再练练手。不过还是费了些时间,vim进入文件执行命令如下(注50,57是中间涉及body所在的行):

:50,57s/.*'\(.*\)'.*/\1=\0/

        在尝试的时候,参考awk,猜测\0代表原始行内容,测试果然如此。另外(需要使用反斜线,这样操作之后还有一个问题就是新加的内容离body.get有些远,结果如下:

table=            body.get('table', None)
switch=            body.get('switch', None)                                                                                
uid=            body.get('uid', None)                                                                                         
ver=            body.get('ver', None)                                                                                      
type=            body.get('type', None)                                                                                        
classnema=            body.get('classnema', None)                                                                                
cid=            body.get('cid', None)
public_time=            body.get('public_time', None)

         再使用如下命令替换空格并通过=号替换在前后加上一个空格,:

:50,57s/ //g
:50,57s/=/ = /g

        将空格替换,这里也没有去尝试更精进的方法,直接一步到位的。只要能实现即可。所可以直接在文件外使用sed编辑内容。 

sed -i "50,57s/.*'\(.*\)'.*/\1=\0/g" test.py

三、全国拼音相同的城市(地级市)明细列表及所属省份

        之前还在想这么一个事,publish:July 23, 2018 -Monday 单独想吧,真的很难想出来哪些城市的拼音会相同,今天在整理数据的时候处理了一下,发现全国还真有这28个城市的拼音是相同的。列表如下: 

计数省份省辖城市城市拼音
1江西省丰城fengcheng
2辽宁省凤城fengcheng
3安徽省阜阳fuyang
4浙江省富阳fuyang
5广东省鹤山heshan
6广西省合山heshan
7吉林省集安jian
8江西省吉安jian
9福建省建阳jianyang
10四川省简阳jianyang
11内蒙集宁jining
12山东省济宁jining
13河北省晋州jinzhou
14辽宁省锦州jinzhou
15辽宁省开原kaiyuan
16云南省开远kaiyuan
17广西省赁祥linxiang
18湖南省临湘linxiang
19安徽省宿州suzhou
20江苏省苏州suzhou
21江苏省泰州taizhou
22浙江省台州taizhou
23河南省舞钢wugang
24湖南省武冈wugang
25黑龙江省伊春yichun
26江西省宜春yichun
27广西省玉林yulin
28陕西省榆林yulin
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林戈的IT生涯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值