实用Linux命令记录
ss统计网络连接情况
[root@Dev-8.8.8.8 ~]# ss -tan |awk 'NR>1 {++sum[$1]} END{for(i in sum) print i"\t"sum[i]}'
ESTAB 33
TIME-WAIT 876
CLOSE-WAIT 4
LISTEN 9
[root@Dev-8.8.8.8 ~]#
split切割大文件
[root@Dev-8.8.8.8 logs]# split -l 100000 error.log -d -a 3 err_ [root@Dev-8.8.8.8 logs]# [root@Dev-8.8.8.8 logs]# ll err_* -rw-r--r-- 1 root root 13032896 Apr 26 10:00 err_000 -rw-r--r-- 1 root root 14881719 Apr 26 10:00 err_001 -rw-r--r-- 1 root root 34141600 Apr 26 10:00 err_002 -rw-r--r-- 1 root root 13040097 Apr 26 10:00 err_003 -rw-r--r-- 1 root root 13029133 Apr 26 10:00 err_004 -rw-r--r-- 1 root root 13029906 Apr 26 10:00 err_005 -rw-r--r-- 1 root root 21787781 Apr 26 10:00 err_006 -rw-r--r-- 1 root root 13024913 Apr 26 10:00 err_007 -rw-r--r-- 1 root root 14810882 Apr 26 10:00 err_008 -rw-r--r-- 1 root root 22828835 Apr 26 10:00 err_009 -rw-r--r-- 1 root root 10308780 Apr 26 10:00 err_010 [root@Dev-8.8.8.8 logs]#
# 补充:按指定文件大小分割 split -b 100m access.log -d -a 4 acc_
文件去重
涉及 awk程序指令模型
补充 awk知识
# 参考:http://www.letuknowit.com/topics/20120401/use-awk-remove-duplicate-lines.html/
root@standby[16:34:30]$ cat 2.txt
hello world
awk
coding ants
hello world
awk
hello world
awk
coding ants
coding ants
root@standby[16:34:31]$ awk '!sum[$0]++' 2.txt
hello world
awk
coding ants
root@standby[16:34:38]$ awk '!sum[$0]++ {print $0}' 2.txt
hello world
awk
coding ants
root@standby[16:34:42]$ awk '!sum[$0]++ {print sum[$0]"\t"$0}' 2.txt
1 hello world
1 awk
1 coding ants
root@standby[16:34:55]$ awk '!sum[$0] {sum[$0]++; print sum[$0]"\t"$0}' 2.txt
1 hello world
1 awk
1 coding ants
root@Prism.Dev-10.49.134.67[16:35:04]$
文件去重并统计重复的行数,最后按行数排序
root@standby[16:57:35]$ cat 1.txt
hello world
awk
coding ants
hello world
awk
hello world
awk language is cool!
coding ants
coding Python
root@standby[16:57:36]$ sort 1.txt
awk
awk
awk language is cool!
coding ants
coding ants
coding Python
hello world
hello world
hello world
root@standby[16:57:44]$ sort 1.txt |uniq
awk
awk language is cool!
coding ants
coding Python
hello world
root@standby[16:57:46]$
# 显示重复次数
root@standby[16:57:46]$ sort 1.txt |uniq -c
2 awk
1 awk language is cool!
2 coding ants
1 coding Python
3 hello world
root@standby[16:57:49]$ sort 1.txt |uniq -c |sort -k1 -n
1 awk language is cool!
1 coding Python
2 awk
2 coding ants
3 hello world
root@standby[16:58:04]$
# 只显示重复的行
root@standby[16:58:10]$ sort 1.txt |uniq -d
awk
coding ants
hello world
root@standby[16:58:10]$
# 只显示唯一的行
root@standby[16:58:16]$ sort 1.txt |uniq -u
awk language is cool!
coding Python
root@standby[16:58:18]$
获取ip地址
root@standby[17:08:25]$ ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.130.8.100 netmask 255.255.224.0 broadcast 10.130.31.255
ether fa:16:3e:c3:d5:2d txqueuelen 1000 (Ethernet)
RX packets 619942009 bytes 626016909706 (583.0 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5486035 bytes 2419266407 (2.2 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
root@standby[17:08:28]$ ifconfig eth0 | grep "inet " | sed -e "s/^.*inet \(.*\) netmask.*$/\1/"
10.130.8.100
root@standby[17:08:32]$
# 可用在Linux命令行提示符 export PS1="\[\033[01;31m\]\u\[\033[00m\]@\[\033[01;32m\]standby-`/sbin/ifconfig eth0 | grep "inet " | sed -e "s/^.*inet \(.*\) netmask.*$/\1/"`\[\033[00m\][\[\033[01;33m\]\t\[\033[00m\]]$ "
作者:Standby — 一生热爱名山大川、草原沙漠,还有我们小郭宝贝!
出处:http://www.cnblogs.com/standby/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://www.cnblogs.com/standby/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

浙公网安备 33010602011771号