zoukankan      html  css  js  c++  java
  • 命令整理

    shell命令

    • 查看物理CPU个数
      cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
    • 查看逻辑CPU的个数
      cat /proc/cpuinfo| grep "processor"| wc -l
    • 查看CPU信息
      cat /proc/cpuinfo
    • 查看网卡信息
      • ifconfig
      • ethtool eth0
    • 查看内存
      • free -h
    • 查看磁盘
      • df -h
      • du -sh *
    • 查看占用端口号的进程
      • lsof -i:22
      • 查看某个进程建立的连接信息: lsof -p 44332 -nP | grep TCP
    • 查看某端口号进程状态
      • netstat -anp | grep port
    • find使用,参考用find命令查找最近修改过的文件
      • find . -name ".cpp" -o -name ".h"
      • 删除前两天文件find . -mtime +2 -type f -name "a.*" | xargs rm -f
      • 10分钟以前 -mmin +10
    • grep使用
      • grep -E "mongo|cursor|find|find_one" `find . -name "*.cpp"`
      • cat a.log | grep -a "TIME"
      • 查找两个文件的不同行
        • grep -vFf f1 f2
      • 查找两个文件相同行
        • grep -Ff f1 f2
      • 也显示匹配行的前1行 -B1
      • 也显示匹配行的后1行 -A1
    • sudo使用
      • sudo su username
    • 更改文件/目录所属用户/用户组
      • chgrp -R groupName dir1
      • chown -R userName dir2
    • sed 设置备份文件,匹配行并完成替换
      • -i 表示操作在源文件上生效
      • 第一个//之间为匹配行
      • s为替换,之后第一个//之间为待替换字符串,第二个//之间为替换的字符串,g为全局执行
      • 替换字符串包含&需要转义
      • sed -i ".bk" '/=.*);/ {s/)//g;}' a.txt
      • sed -i ".bk" '/ set.*(.*<.*> .*) {/ {s/> /> &/g;}’ a.txt
      • 在匹配行的末尾追加内容 sed -i '/toBeMatched/ s/$/toBeAppended/' test.log
    • awk使用
      • awk '{if($1=="required"){i++; print i":", “optional”,$1, $2, $3, $4; }else{print $0}}' test
      • awk '{if($1!=“//"){i++; print i":", "optional",$1, $2, $3, $4; }else{print $0}}’ test
      • awk -F':' 'BEGIN{i=21}{print i":",$2;i++}’ test
      • awk 'BEGIN{i=1}{if($3=="list_str"){if($4!=""){print """$3, $1, i++, $4"","}else{print """$3, $1, i++"","}}}' test
    • diff 使用
      • diff -w new1.list old1.list
      • "<"表示a.txt有,但是b.txt里面不包含
      • ">"表示a.txt没有,但是b.txt包含。
      • diff -w a.txt b.txt | grep ^< 输出a.txt里面有,但是b.txt里面不包含的文件内容
    1c1
    < 10.103.18.107
    ---
    > 10.103.18.10
    16a17
    > 10.120.53.5
    18a20
    > 10.126.13.19
    22a25
    > 10.126.33.18
    24a28,29
    > 10.136.127.23
    > 10.136.128.17
    25a31,32
    > 10.136.132.22
    > 10.136.133.42
    
    • comm使用
      - 默认输出为三列,第一列为是A-B,第二列B-A,第三列为A交B
      - -1 不输出文件1 特有的行, -2 不输出文件2 特有的行, -3 不输出两个文件共有的行
    • rm使用
      • 删除某用户的所有文件find . -user username | xargs rm -rf
    • date查看时间戳
      • date -d @1557146832
    • 获取管道中执行命令的返回值
      • sh +x test.sh | tee -a test.log
      • ${PIPESTATUS[0]}
    • 合并文件
      • 按行
        • cat a b > c
      • 按列
        • paste a b > c
    • 每行按分隔符转换为多列
      • sed -i "s/ /\n/g" test.log
    • ssh远程执行命令
      • ssh user@ip "echo test"
      • ssh user@ip "sudo su other -c "echo test""
    • tcpdump 打印包
      - tcpdump -nn -i lo tcp dst port 7191 -A

    调试过程相关命令

    • addr2line

      • addr2line -e a.out 0x4007f0 根据二进制文件中的地址,定位原代码文件名和行数
    • objdump

    网络连接相关命令

    • 查看系统级最大文件限制
      - cat /proc/sys/fs/file-max
      - sysctl -a 查看结果中fs.file-max这项的配置数量

    • 查看用户级最大文件限制
      - ulimit -a

    • 查看 TCP XX_wait 状态持续时间
      - sysctl -a | grep time | grep wait
      - netstat -n | awk '/^tcp/ {++state[$NF]} END {for(key in state) print key," ",state[key]}'

    redis操作

    - redis-cli -h 127.0.0.1 -p 6379 -a username
    - redis-cli -p 7380
    - 登录后 info 命令
    - ps aux | grep redis
    - cd /etc; sudo /usr/bin/redis-server redis.conf
    - /usr/bin/redis-server 127.0.0.1:6379
    - 关闭redis:redis-cli shutdown
    - 设置密码后需带密码输入: redis-cli -a [password],进入redis命令行后执行shutdown即可关闭redis,输入exit退出
    

    mongodb操作

    - db.getCollection('cname').find({"_id":"id1"},{"field1":1})
    - db.getCollection('cname').find({"field2":{$exists:true}})
    - db.getCollection('cname').find({}).count()
    - db.createCollection('testDocument')
    - db.getCollection('testDocument').insert({_id:"testID3",start_date:NumberLong(-65535),end_date:NumberLong(-65535),low:NumberInt(0)})
    - db.getCollection('testDocument').update({"_id":"testID2"},{$set:{"low":NumberInt(1)}})
    - db.getCollection('testDocument').update({"_id":"testID2"},{$unset:{"low":""}}, false, true)
    - db.getCollection('testDocument').remove({"_id":"testID1"})
    - db.getCollection('testDocument').createIndex({"timestamp":1},{expireAfterSeconds: 3600*24*30})
    - db.getCollection('testDocument').getIndexes()
    - db.getCollection('testDocument').find({"timestamp":{"$gte":ISODate("2019-08-29T00:00:00Z"), "$lt":ISODate("2019-08-30T00:00:00Z")}}).count()
    - db.getCollection('testDocument').find({"name":"XXX","timestamp":{$regex:"2019-12-04T.*"},"status":"Running"})
    - db.getCollection('testDocument').find({"_id":{"$regex":"^V.*"}}, {"_id":1})
    

    k8s常用命令

    • kubectl label node IP res=XXX
    • kubectl label node IP res-
    • kubectl get nodes
    • kubectl get nodes -l res=XXX
    • kubectl describe node IP
    • kubectl get pods -o wide -n NNN

    参考

    robo3T 操作MongoDB数据库常用命令
    抓包工具tcpdump用法说明
    TCP连接的TIME_WAIT和CLOSE_WAIT 状态解说
    TCP的11种状态
    Kubernetes常用命令

  • 相关阅读:
    正则表达式练习,持续更新中
    Jquery使用mouseenter和mouseleave实现鼠标经过弹出层且可以点击
    SQL查找 删除重复数据只保留一条
    TreeView(C#)无限目录树代码片段
    ora-01440:要减小精度或标度,则要修改的列必须为空
    SQL查询和删除重复字段的内容
    CodeSmith(C#)简单示例及相关小知识
    MSSQL 自定义函数详解
    一些精妙的sql语句收集
    134.Gas Station
  • 原文地址:https://www.cnblogs.com/wangzhiyi/p/10122378.html
Copyright © 2011-2022 走看看