zoukankan      html  css  js  c++  java
  • 【常用命令】Linux相关命令

    [[TOC]]

    iostat - 查看系统I/O状况

    • -k Display statistics in kilobytes per second
    • -m Display statistics in megabytes per second.
    • -d Display the device utilization report.

    示例:

    [root@epic-phy-9-21 ~]# iostat -d -m
    Linux 3.10.0-514.26.1.el7.x86_64 (epic-phy-9-21) 	12/15/2017 	_x86_64_	(32 CPU)
    
    Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn
    sda             209.95         2.26         3.46   19564882   29937790
    sdc               0.00         0.00         0.00          3          0
    sde               0.00         0.00         0.00          3          0
    
    

    sar (网络traffic)

    说明:

    sar - Collect, report, or save system activity information
    -n { keyword [,...] | ALL }
                  Report network statistics.
    
                  Possible keywords are DEV, EDEV, NFS, NFSD, SOCK, IP, EIP, ICMP, EICMP, TCP, ETCP, UDP, SOCK6, IP6, EIP6, ICMP6, EICMP6 and UDP6.
    
                  With the DEV keyword, statistics from the network devices are reported.  The following values are displayed:
    
    

    示例:

    // 每5s抽样一次,总共抽样2次
    [root@epic-phy-9-21 ~]# sar -n DEV 5 2 | grep lo
    Average:        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
    02:34:38 PM        lo    309.60    309.60    498.68    498.68      0.00      0.00      0.00
    02:34:43 PM        lo   1241.20   1241.20    842.29    842.29      0.00      0.00      0.00
    Average:           lo    775.40    775.40    670.48    670.48      0.00      0.00      0.00
    

    top

    查看每个CPU核是使用率

    操作:按键1;

    top - 10:23:11 up 100 days, 14 min,  5 users,  load average: 9.25, 9.17, 9.38
    Tasks: 2002 total,  11 running, 1990 sleeping,   0 stopped,   1 zombie
    %Cpu0  :  7.4 us,  0.7 sy,  0.0 ni, 92.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
    %Cpu1  :  3.0 us,  1.3 sy,  0.0 ni, 87.3 id,  8.3 wa,  0.0 hi,  0.0 si,  0.0 st
    %Cpu2  : 67.3 us,  2.6 sy,  0.0 ni, 30.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
    %Cpu3  : 32.2 us,  1.3 sy,  0.0 ni, 66.4 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
    %Cpu4  : 34.3 us,  1.0 sy,  0.0 ni, 64.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
    

    线程角度来查看CPU消耗

    操作:Shift+H

    查看指定进程

    top -p pid
    

    byte转Mb、GB等

    操作:Shift+e


    awk

    打印文件制定的列,并指定分隔符

    • $1: 第一列
    • -F: 指定分隔符
    awk '{print $1}' -F "-" access.log 
    

    筛选指定行,并打印指定列

    awk '/google/{print $5,$6}' access.log 
    

    查询length大于40的行,打印第3列

    • $0: 表示当前行
    awk 'length($0)>40{print $3}' access.log
    

    对内容进行格式化输出

    awk '{line = sprintf ( "method:%s, response:%s", $3 , $7 ); print line}' access.log
    

    将处理文本放在指定文件

    awk -f testawk access.log
    

    sed

    替换文件中的item为items输出,文件内容不发生变化

    sed 's/item/items/' test.properties
    

    输出文件的12-16行

    • -n : 表示只输出指定行
    sed -n '12,14p' test.properties
    

    删除指定行输出,文件内容不发生变化

    // 删除包含pool的行
    sed '/pool/d' test.properties
    

    在每行的行首插入文本

    sed -e 'iThis is header of every line' test.properties
    
    output:
    This is header of every line
    performance.indicator.graphite.item[1].key=pm_statistic_memory_used_size
    This is header of every line
    performance.indicator.graphite.item[1].targetQuery=aliasByNode(EPIC.pm.*.memory.memory.used, 2)
    This is header of every line
    performance.indicator.graphite.item[1].metricType=Gauge
    
    

    在每行的行尾追加文本

     sed -e 'aend' test.properties
    
    output:
    performance.indicator.graphite.item[2].metricType=Gauge
    end
    performance.indicator.graphite.item[2].targetParamPattern=^(?<hostId>.*)$
    end
    performance.indicator.graphite.item[2].skipNullMax=8
    end
    

    对匹配的行进行替换

    查找/pool/匹配的行,用poolnew对匹配的行进行替换

    sed -e '/pool/cpoolnew' test.properties
    

    tcpdump抓包工具

    tcpdump -i any -A tcp port 2003 and host 192.168.46.32 -vvv 
    

    参数解释:

    • -i: 表示网卡接口,如:eth0,当设置为any时,表示任一网卡;
    • -A: 以ASCII形式显示;
    • tcp port xxxudp port xxx等;
    • host xxx.xxx.xxx.xxx
    • -vvv: 多一个v就表示输出更详细一些;
    • and:多个判断条件直接的连接符;

    nc命令

    判断某端口是否打开

    nc -zv ip host
    

    示例:

    [root@epic-phy-9-21 kubernetes]# kubectl exec epic-mgmt-4172821423-206kj -- nc -zv 172.30.29.13 8008
    
    output:
    172.30.29.13 (172.30.29.13:8008) open (当显示类似这条语句,表示该port打开)
    

    telnet命令

    判读某端口是否打开

    telnet ip port
    
    example:
    telnet 192.168.3.42 2121
    

    netstat 命令

    查看某个端口是否被占用

    netstat -anp | grep 8080
    

    curl

    • -i: 包含header
    • -I: 仅仅包含Header
    • -H: 请求包含header信息
    • --request: 指定请求方法,默认是GET,可以是POST、PUT、DELETE等,一般不需要指定
    • -d: 使用post请求发送指定数据

    Get方式请求token,包含header

    curl -H "Content-Type:application/x-www-form-urlencoded" http://10.254.9.21:30111/v1/user/oauth/token?grant_type=password&username=epic&password=epic1234
    

    POST方式请求token(多个-d将多个key-value分开)

    curl -H "Content-Type:application/x-www-form-urlencoded" -d grant_type=password -d username=epic -d password=epic1234 http://10.254.9.21:30111/v1/user/oauth/token 
    

    POST方式请求token(1个-d传递多个key-value)

    curl -H "Content-Type:application/x-www-form-urlencoded" -d "grant_type=password&username=epic&password=epic1234" http://10.254.9.21:30111/v1/user/oauth/token
    

    post方式请求(raw数据,json格式)

    curl -H "Content-Type:application/json" -H "Authorization:Bearer 1429a901-9236-40eb-a53c-e6c7ef71fff6" -d '{
        "dateformat": "NUMERIC",
        "metrics": [
            {
                "resourceType": "splitter",
                "resourceId": "f8021c6606c7494b96d256a7c8951d89", 
                "metricItem": "splitter_realtime_cpu_avg_util_percent"
            }
        ]
    }' --request POST http://192.168.29.222:8008/v2/pools/7b8f0f5e2fbb4d9aa2d5fd55466dsij2/performance/query
    
  • 相关阅读:
    BugkuCtf-pwn2-exp
    Python 基础知识(一)
    C++基本语法的部分总结
    Ububtu 14.04 安装 Hadoop 2.7.3
    leetcode-Evaluate the value of an arithmetic expression in Reverse Polish Notation
    leetcode-Given a binary tree, find its minimum depth
    Java 实现 AES 加解密
    git fork代码并修改胡提交到自己的git仓库
    git使用记录_备忘
    java awt 中文乱码 显示为 方块
  • 原文地址:https://www.cnblogs.com/ssslinppp/p/9035133.html
Copyright © 2011-2022 走看看