美文网首页linux
Linux查询日志常用命令

Linux查询日志常用命令

作者: 鱼da王 | 来源:发表于2018-10-24 14:42 被阅读0次

常用命令:

1.cat -n tma.log | grep -C 5 '11:08:18.384' -- 查询匹配字段的上下5行 (注意C大写)
2.cat -n test.log |grep "debug" | less 

详情如下:

  1. tail

     tail -f test.log
     tail -100 test.log -- 显示尾部最后10行日志
     tail -n +10 test.log -- 查询10行之后的所有日志
    
  2. head

     head -10 test,log -- 查询头10行
     head -n -10 test.log -- 查询日志文件除了最后10行的其他所有日志;
    
  3. 搜索 grep

    grep '18016029383' sms-proxy-zt-info-2018-02-11-0.log 
    
  4. cat

    (是tac的反写,tac是倒序查看)

    cat -n test.log | grep "关键字"   -- 显示行号
    cat -n tma.log | grep -C 5 '11:08:18.384' -- 查询匹配字段的上下5行 (注意C大写)
    cat -n tma.log | grep -B 5 '11:08:18.384' -- 查询匹配字段的前5行
    cat -n tma.log | grep -A 5 '11:08:18.384' -- 查询匹配字段的后5行
    
  5. more

    command :

    more test.log
    

    operate :

    # 按空格 - 向后翻页
    # b - 向前翻页
    
  6. less

    command:

    less test.log
    

    operate:

    #搜索
         / - 使用模式进行搜索,并定位到下一个匹配的文本
         ? - 使用模式进行搜索,并定位到前一个匹配的文本
         n - 向前匹配
         N - 向后匹配
    #全屏导航
         ctrl + F - 向前一屏
         ctrl + B - 向后一屏
         ctrl + D - 向前半屏
         ctrl + U - 向前半屏
    #单行导航
         j - 向前移动一行
         k - 向后移动一行
    #其他导航
         G - 移动到最后一行
         g - 移动到第一行
         q/ZZ - 退出
    
  7. 行号查询

     cat -n test.log | grep "关键字"   -- 显示行号 拿到想要的行号
     cat -n test.log | tail -n +30 | head -n 20  
    -- 选择关键字所在的中间一行. 然后查看这个关键字前10行和后10行的日志:
       tail -n +30 表示查询30行之后的日志
       head -n 20  表示在前面的查询结果里再查前20条记录
    
  8. 根据时间查询

    sed -n '/11:11:26/,/11:12:26/p' tma.log -查询两个时间点之间日志
    前提两个时间点必须在日志中必须有
    则:先用grep '11:11:26' test.log
    
  9. more less命令查询

    more

     cat -n test.log |grep "debug" | more  - 分页打印了,通过点击空格键翻页
     cat -n test.log |grep "debug"  > debug.txt - 将其保存到文件中 
     sz debug.txt - 下拉文件
    

    less

    cat -n test.log |grep "debug" | less  - 参看第5条operation
    
  10. Linux查看物理CPU个数、核数、逻辑CPU个数

    # 总核数 = 物理CPU个数 X 每颗物理CPU的核数 
    # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数
    
    # 查看物理CPU个数
    cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
    
    # 查看每个物理CPU中core的个数(即核数)
    cat /proc/cpuinfo| grep "cpu cores"| uniq
    
    # 查看逻辑CPU的个数
    cat /proc/cpuinfo| grep "processor"| wc -l
    
    # 查看CPU信息(型号)
    cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
    
  11. 查看机器的tcp连接状态个数

    netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
    
  12. 查看打开的端口

    # 显示tcp的侦听端口
    netstat -natpl
    
    # 显示udp的侦听端口
    netstat -naupl
    
    # 显示端口 11001的信息
    lsof -i:11001
    
  13. 查看当前系统信息

    # 查看Linux内核版本命令
    cat /proc/version
    or
    uname -a
    
    # 查看Linux系统版本的命令
    lsb_release -a
    or
    cat /etc/redhat-release
    or
    cat /etc/issue
    
  14. 关机和重启

    # 关机
    shutdown -h now
    or
    halt
    or
    poweroff
    
    # 重启命令
    shutdown -r now
    or
    reboot
    
  15. 查看防火墙

    # centos7
    # 防火墙状态
    firewall-cmd --state
    
    # 启动防火墙
    systemctl start firewalld
    
    # 停止防火墙
    systemctl stop firewalld.service
    
    # 禁止firewall开机启动
    systemctl disable firewalld.service
    
    # 查看打开的端口
    firewall-cmd --zone=public --list-ports
    
    # 更新防火墙规则
    firewall-cmd --reload
    
  16. 开放/关闭 某个端口的步骤

    # 配置 - 添加端口
    firewall-cmd --zone=public --add-port=4001/tcp --permanent
    or
    # 配置 - 删除端口
    firewall-cmd --zone=public --remove-port=4001/tcp --permanent
    
    # 生效 - 更新防火墙规则
    firewall-cmd --reload
    
    # 验证 - 查看打开的端口
    firewall-cmd --zone=public --list-ports
    

相关文章

  • mysql调优及常用命令

    mysql常用命令 慢查询日志 mysqlddumpslow(查看慢查询日志) mysql5.7(虚拟列) mys...

  • Linux命令

    Linux命令 linux命令查询网站:https://explainshell.com 常用命令 cd:进入目录...

  • Linux查询日志常用命令

    常用命令: 详情如下: tail tail -f test.log tail -100 test.log -- 显...

  • Linux系统如何查看日志(常用路径)

    Linux 系统中如何查看日志 (常用命令) : tail -f 【参考】https://www.cnblogs....

  • 2019-06-11

    linux查询相关信息的日志命令cat catalina.out | grep 'xxx'

  • 其他

    Git常用命令mac常用命令Linux 常用命令汇总Linux 常用命令0Linux 常用命令1--ls命令

  • Linux —— 日志查询

    less工具是对文件或其他输出进行分页显示的工具,功能极其强大;使用less可以用[pageup]和[pagedo...

  • Linux日志查询

    1、动态获取实时生成日志信息 tail -f nohup.log 2、显示日志信息 -打印出所有日志文件中的日志信...

  • Linux 常用命令汇总

    Linux 常用命令0Linux 常用命令1--ls命令 参考 Linux 常用命令汇总

  • 取出Journal Log的方法

    由systemd启动的Linux系统,通常用命令 sudo journalctl 来读日志。有的时候,我们需要把日...

网友评论

    本文标题:Linux查询日志常用命令

    本文链接:https://www.haomeiwen.com/subject/tuxxtqtx.html