Skip to content

Instantly share code, notes, and snippets.

@xiazhibin
Last active October 14, 2018 14:46
Show Gist options
  • Save xiazhibin/5cc999c4b24e48be4e1171a520150fc4 to your computer and use it in GitHub Desktop.
Save xiazhibin/5cc999c4b24e48be4e1171a520150fc4 to your computer and use it in GitHub Desktop.
常用bash命令

检测环境变量存不存在

if [ -z ${VAR+x} ]
then
    echo "VAR not exist"
else
    echo "$VAR"
fi

获取随机变量

  • date +%N |cut -c 1-8 #随机8个数字
  • echo $RANDOM |md5sum |cut -c 1-8 #随机8个字符

查看cpu占用率

ps aux --sort=-%cpu | awk 'NR==1{print $2,$3,$11}NR>1{if($3!=0.0) print $2,$3,$11}' > some_file.txt

cpu个数

grep -c 'model name' /proc/cpuinfo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment