1、取本机ip地址
[root@centos6 ~]# ifconfig eth1 Link encap:Ethernet HWaddr 00:0C:29:35:DD:AB inet addr:10.1.253.95 Bcast:10.1.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:fe35:ddab/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:378023 errors:0 dropped:0 overruns:0 frame:0 TX packets:12444 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:46926222 (44.7 MiB) TX bytes:1240063 (1.1 MiB) eth2 Link encap:Ethernet HWaddr 00:0C:29:35:DD:B5 inet addr:192.168.226.135 Bcast:192.168.226.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe35:ddb5/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2539 errors:0 dropped:0 overruns:0 frame:0 TX packets:225 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:281133 (274.5 KiB) TX bytes:39650 (38.7 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) [root@centos6 ~]# ifconfig |awk -F '[: ]+' 'NR==2{print $4}' 10.1.253.95 [root@centos6 ~]# ifconfig eth1 Link encap:Ethernet HWaddr 00:0C:29:35:DD:AB inet addr:10.1.253.95 Bcast:10.1.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:fe35:ddab/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:379965 errors:0 dropped:0 overruns:0 frame:0 TX packets:12615 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:47097014 (44.9 MiB) TX bytes:1264173 (1.2 MiB) eth2 Link encap:Ethernet HWaddr 00:0C:29:35:DD:B5 inet addr:192.168.226.135 Bcast:192.168.226.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe35:ddb5/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2541 errors:0 dropped:0 overruns:0 frame:0 TX packets:227 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:281535 (274.9 KiB) TX bytes:40052 (39.1 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) [root@centos6 ~]# ifconfig |head -2 eth1 Link encap:Ethernet HWaddr 00:0C:29:35:DD:AB inet addr:10.1.253.95 Bcast:10.1.255.255 Mask:255.255.0.0 [root@centos6 ~]# ifconfig |head -2 |sed -r 's/^.*addr:(.*) Bca.*$/\1/g' eth1 Link encap:Ethernet HWaddr 00:0C:29:35:DD:AB 10.1.253.95 [root@centos6 ~]# ifconfig |head -2|tail -1 |tr -s ' ' ':' |cut -d: -f4 10.1.253.95 [root@centos6 ~]#
1.1、取出本机所有的IP地址
[root@centos6 ~]# ifconfig |tr -cs '[:digit:].' '\n'|sort -t. -k4|tail -8 255.0.0.0 255.255.0.0 255.255.255.0 127.0.0.1 192.168.226.135 10.1.255.255 192.168.226.255 10.1.253.95 [root@centos6 ~]#
2、取各分区利用率的数值
[root@centos6 ~]# df |grep "sd.*" /dev/sda3 121455724 3990720 111288700 4% / /dev/sda1 194241 34082 149919 19% /boot /dev/sdb 20511356 44992 19417788 1% /mnt [root@centos6 ~]# df |grep "sd.*"|tr -s ' ' ':' /dev/sda3:121455724:3990720:111288700:4%:/ /dev/sda1:194241:34082:149919:19%:/boot /dev/sdb:20511356:44992:19417788:1%:/mnt [root@centos6 ~]# df |grep "sd.*"|tr -s ' ' ':'|cut -d: -f1,5 /dev/sda3:4% /dev/sda1:19% /dev/sdb:1% [root@centos6 ~]# df |grep "sd.*"|tr -s ' ' ':'|cut -d: -f1,5|sort -nr /dev/sdb:1% /dev/sda3:4% /dev/sda1:19% [root@centos6 ~]#
3、统计/etc/init.d/functions 文件中每个单词出现的次数,并按频率从高到低显示
[root@centos6 ~]# cat /etc/init.d/functions |tr -cs '[:alpha:]' '\n'|sort|uniq -c |sort-nr 83 if 77 then 75 pid 73 echo 72 fi 61 return 57 dev 54 file 50 n 46 local
4、/etc/rc.d/init.d/functions或/etc/rc.d/init.d/functions/" 取目录名
[root@centos6 ~]# echo "/etc/init.d/functions"|sed -r 's#^(/.*/)[^/]+/?#\1#g' /etc/init.d/ [root@centos6 ~]#
4.1、/etc/rc.d/init.d/functions或/etc/rc.d/init.d/functions/" 取基名
[root@centos6 ~]# echo "/etc/init.d/functions/"|sed -r 's#/.*/([^/]+)#\1#g' functions/ [root@centos6 ~]#
5、正则表达式表示身份证号
egrep "\<((1[1-5])|(2[1-3])|(3[1-7])|(4[1-6])|(5[0-4])|(6[1-5])|(71|81|82))([0-9]){4}(19|20)([0-9]){2}((0[1-9])|(1[0-2]))(0[1-9]|([0-9])|(2[0-9])|(3[0-1]))([0-9]){3}([0-9]|X)\>" filename
6、正则表达式表示手机号
grep -E -o "(\+86)?1[38][0-9]{9}|14[57][0-9]{8}|15[0-35-9][0-9]{8}|17[0678][0-9]{8}" phonenumber
7、正则表达式表示邮箱
egrep "\<([[:alnum:]]+(-|_)*[[:alnum:]]*)\>@([[:alnum:]]+\.)+[[:alnum:]]+" mail grep -E -o '[a-zA-Z0-9]+[[:alnum:]\.\_-]*@[a-zA-Z0-9]+[[:alnum:]\.\_-]*' phonenumber
8、正则表达式表示QQ号
grep -E -o '\b[1-9][0-9]{4,12}\b' phonenumber
原创文章,作者:alren,如若转载,请注明出处:http://www.178linux.com/31460