系统命令

进程相关命令

  • 获得有关进程、虚存、页面交换空间及 CPU活动的信息
    • vmstat

环境变量相关

  • 用户环境变量配置
    • vim ~/.bashrc
    • source ~/.bashrc

远程链接相关命令

创建公钥私钥 ssh-keygen
公钥在另外一台机器授权 ssh-copy-id -i ~/.ssh/id_rsa.pub root@node1
链接测试 ssh root@node1
远程复制 scp root@192.168.112.111:/etc/hosts hosts
配置本地端口代理到远程服务器 ssh -N -D localhost:10800 quaint-server

防火墙相关

关闭防火墙 systemctl stop firewalld.service
关闭防火墙的开机启动 systemctl disable firewalld.service
查看状态 firewall-cmd —state

VIM命令

非编辑模式下命令

跳至行尾 $
删除光标后的一个单词 dw
寻找某个单词 / + key + enter
保存退出 : + wq
使用管理员权限保存 :w !sudo tee %

编辑模式下命令

搜索log常用命令

  • find
    • find 路径 -name fileName
    • eg:
      • find ./ -name ‘promocore’ 2>/dev/null
  • tail
    • tail -n100 文件路径
    • tail -f 文件路径
  • head
    • head -n100 文件路径
  • cd
    • cd - 回到上一次的目录
    • cd .. 回到上级目录
  • fgrep
  • awk
  • control + a: 回到开头
  • control + e: 回到结尾

命令实战

  • find
    • find ./disk-soft -name “mvn”
      • ./disk-soft/maven/apache-maven-3.6.0/bin/mvn
  • tail
    • tail -f xxx.log
    • tail -n100 jmeter.log | grep “SampleResult” | awk ‘{print $5}’ | awk -F ‘.’ ‘{print $1}’ | uniq -c | sort -rn
    • tail -n100000 xxx.log | fgrep “ERROR” | awk ‘{print $8}’ | awk -F ‘,’ ‘{print $1}’ | sort | uniq -c | sort -rn
    • tail -n100000 xxx.log_PE.log | fgrep “ERROR” | fgrep -v “超时” | awk ‘{print $8}’ | awk -F ‘,’ ‘{print $1}’ | sort | uniq -c | sort -rn
  • fgrep
    • fgrep “ERROR” -m10000 xxx.log | fgrep -v “超时” | awk ‘{print $8}’ | awk -F ‘:|,’ ‘{print $1}’ | sort | uniq -c | sort -rn
    • fgrep “ERROR” -m10000 xxx.log | fgrep -v “超时” | awk ‘{print $8}’ | awk -F ‘:|USER_ID’ ‘{print $1}’ | sort | uniq -c | sort -rn
  • Cat
    • cat words.txt | tr -s ‘ ‘ ‘\n’ | sort | uniq -c | sort -rn | awk ‘{print $2,$1}’

1、首先cat命令查看words.txt
2、tr -s ‘ ‘ ‘\n’将空格都替换为换行 实现分词
3、sort排序 将分好的词按照顺序排序
4、uniq -c 统计重复次数(此步骤与上一步息息相关,-c原理是字符串相同则加一,如果不进行先排序的话将无法统计数目)
5、sort -r 将数目倒序排列
6、awk ‘{print $2,$1}’ 将词频和词语调换位置打印出来

  • leetcode shell 练习

https://mp.weixin.qq.com/s/EI63RZZcPzJT4c0zl8XQSA

  • awk

https://mp.weixin.qq.com/s?__biz=MzA4NDE4MzY2MA==&mid=2647520143&idx=1&sn=57dac34308c59e40ea37ef66c9fdba07&chksm=87d24c8cb0a5c59a6caff4ff62a119021f80f8d00ef012059a4786e9b44d43a1ad321aae65d3&scene=21#wechat_redirect