让ifconfig更清爽些

大家都知道 ,普通用户 PATH里面没有 /sbin/ 所以查询ip 都得 /sbin/ifconfig,而且这个命令会带出很多我们用不着的东西,很不清爽呀
而我的gentoo作为桌面,就是喜欢清爽,查询ip 也是为了方便从宿舍的PC ssh过来而已 (ps 因为公司是用dhcp 所以), 下面是清爽的命令
容易点的
ifconfig eth0 | grep 'inet addr'|awk '{print $2}'| awk -F[:] '{print $2}'
第一种
evan@mygentoo ~/shelltest $ /sbin/ifconfig eth0 | grep 'inet addr'
inet addr:192.168.1.103 Bcast:192.168.1.255 Mask:255.255.255.0
evan@mygentoo ~/shelltest $ /sbin/ifconfig eth0 | grep ‘inet addr’|sed ‘s/^.*addr://g’
192.168.1.103 Bcast:192.168.1.255 Mask:255.255.255.0
evan@mygentoo ~/shelltest $ /sbin/ifconfig eth0 | grep 'inet addr'|sed 's/^.*addr://g' |sed 's/Bcast.*$//g'
192.168.1.103
第二种
/sbin/ifconfig eth0 | grep 'inet addr' #这两个是一样的
[root@test_evan_vm ~]# ifconfig eth0 | awk -F: '/inet addr/'
inet addr:192.168.22.151 Bcast:192.168.23.255 Mask:255.255.252.0
#把$2,以 ” ” 为分隔放到 数组a中,并打印第2个 出来
[root@test_evan_vm ~]# ifconfig eth0 | awk -F: '/inet addr/{split($2,a," ") ; print a[1]}'
192.168.22.151
[root@test_evan_vm ~]# ifconfig eth0 | awk -F: ‘/inet addr/{split($2,a,” “) ; print a[2]}’
Bcast
第三种
ip=$(/sbin/ifconfig | grep 'inet addr' | grep -v '127.0.0.1' | awk -F':' '{print $2}' | awk '{print $1"-"}' | sed 's/-$//g')
121.10.140.198-
你喜欢那个就选择哪个,有人说这么长,烦,对 天天打这么长,当然烦啦 所以应该是 选择一个你喜欢的写入你当前家目录的 .bashrc
alias ifconfig="/sbin/ifconfig eth0 | grep 'inet addr' "
#or
alias ifconfig='/sbin/ifconfig eth0 | grep " inet addr" '

evan@mygentoo ~ $ ifconfig
inet addr:192.168.1.103 Bcast:192.168.1.255 Mask:255.255.255.0