ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 用别名显示网卡IP的简便方法(ifconfig / alias / grep / cut)

用别名显示网卡IP的简便方法(ifconfig / alias / grep / cut)

原创 Linux操作系统 作者:amber_cop 时间:2013-03-26 12:23:49 0 删除 编辑
alias ipaddr="ifconfig eth1 | grep \"inet addr\" | cut -d : -f 2 | cut -c 1-15"
或者
alias ipaddr="ifconfig eth1 | grep \"inet addr\" | cut -c 21-37"
以上不完善,IP地址位数长短会有影响
alias ipaddr="ifconfig eth1 | grep \"inet addr\" | cut -d : -f 2 | cut -d'B' -f 1"
不受IP地址长度影响了,但地址后会跟两个空格,估计cut能干的就这些了
只好用tr替换一下吧
alias ipaddr="ifconfig eth1 | grep \"inet addr\" | tr ' ' ':' | cut -d : -f 13"
没空格了

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24644775/viewspace-757154/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2013-03-18

  • 博文量
    36
  • 访问量
    71135