Linux 实用命令

  1. ping检查hosts 网络
    1. for i in `awk '{print $1}' /etc/hosts|grep -v '#'`;do ping $i -c2 -w2 -i 0.2>/dev/null&&echo $i is up||echo$i is down;done
    2. awk '{print $1}' /etc/hosts |grep -v '#'|uniq|xargs -L 1 ping -c 2 -w 2 -i 0.02
  2. 查看系统版本
    1. lsb_release -a CentOS 6.9版本需要安装lsb,CentO7.0以上直接可以使用
    2. cat /proc/version
  3. 查看公网ip
    1. curl ip.sb
  4. 查看占用swap 的进程
    1. vim swaptop10.sh
      #!/bin/bash
      ps ax -o pid,args | grep -v '^ PID'|sed -e 's,^ *,,' > /tmp/ps_ax.output
      echo -n >/tmp/results
      for swappid in $(grep -l Swap /proc/[1-9]*/smaps ); do
      swapusage=0
      for x in $( grep Swap $swappid 2>/dev/null |grep -v '\W0 kB'|awk '{print $2}' ); do
      let swapusage+=$x
      done
      pid=$(echo $swappid| cut -d' ' -f3|cut -d'/' -f3)
      if ( [ $swapusage -ne 0 ] ); then
      echo -ne "$swapusage kb\t\t" >>/tmp/results
      egrep "^$pid " /tmp/ps_ax.output |sed -e 's,^[0-9]* ,,' >>/tmp/results
      fi
      done
      echo "top swap using processes which are still running:"
      sort -nr /tmp/results | head -n 10
      # /bin/bash swaptop10.sh
    2. 释放swap 
      • 1)将物理内存缓存部分释放,执行 sync ; echo 3> /proc/sys/vm/drop_caches
        2)执行swapoff -a 将swap数据交换到物理内存
        3)swapon -a 启用;
      • cat /proc/sys/vm/swappiness
        默认值swappiness=60,表示内存使用率超过100-60=40%时开始使用交换分区
  5. 查看CPU 槽位或数量
    1. more /proc/cpuinfo | grep 'model name'
    2. mpstat 1
  6. 查看启动日志
    1. dmesg -T  
  7. 分屏工具tmux 使用
    1. tmux #进入分屏模式
    2. ctrl+b #进入命令模式
      1. % #左右分屏
      2. " #上下分屏
      3. o #切换分屏
      4. q #分屏编号
      5. x #关闭分屏
    3. ctrl +d 退出
    4. tmux new -s yjz
      tmux attach -t yjz
      tmux ls 查看当前会话列表
      tmux kill-session -t 会话名
       
posted @ 2021-12-29 18:00  杨今朝  阅读(46)  评论(0编辑  收藏  举报