• 实用Linux命令记录


    ss统计网络连接情况

    [root@Dev-8.8.8.8 ~]# ss -tan |awk 'NR>1 {++sum[$1]} END{for(i in sum) print i"	"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]"	"$0}' 2.txt 
    1	hello world
    1	awk
    1	coding ants
    root@standby[16:34:55]$ awk '!sum[$0] {sum[$0]++; print sum[$0]"	"$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="[33[01;31m]u[33[00m]@[33[01;32m]standby-`/sbin/ifconfig eth0 | grep "inet " | sed -e "s/^.*inet (.*)  netmask.*$/1/"`[33[00m][[33[01;33m]	[33[00m]]$ "
    

      

    作者:Standby一生热爱名山大川、草原沙漠,还有妹子
    出处:http://www.cnblogs.com/standby/

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    2016第13周四
    2016第13周周三
    2016第13周二
    2016第13周一
    2016第12周日
    2016第11周五
    2016第11周四
    前端的自我成长
    Java单例模式和volatile关键字
    大约 Apple Metal API 一些想法
  • 原文地址:https://www.cnblogs.com/standby/p/10768348.html
Copyright © 2020-2023  润新知