shell获取操作系统基本信息


Check OS Type

uname -o

Check OS Release Version and Name

rsb_release -r | cut -f 2 #version
rsb_release -i | cut -f 2 #name

Check Architecture

uname -m

Check Kernel Release

uname -r

Check hostname

hostname
uname -n
cat /etc/hostname
echo $HOSTNAME

Check Internal IP

hostname -i

Check External IP

curl ifconfig.me
curl http://ipecho.net/plain

Check DNS

cat /etc/reslov.conf | grep "nameserver" | cut -d " " -f 2

Check if connected to Internet or not

ping baidu.com -c 4 > /dev/null 2>&1 && echo "yes" || echo "no"
ping baidu.com -c 4 > /dev/null 2>&1 && echo "yes" || echo "no" &

Check Logged In Users

who

知识拾遗

  • cut 命令 -f 参数按域分割字符串默认使用制表符(tab),数字代表被分割的第几个域。-d 参数自定义分割符号
  • shell命令执行的结果包括正常和错误,输出有stdout和stderr之分。shell命令执行正常返回成功或者失败,使用&&接下一条命令可以在成功之后执行,使用||接下一条命令可以在失败之后执行。
  • stdout 重定向可以表示为 1>或者>,stderr重定向可以表示为2>。2>&1表示stderr当作stdout。
  • 命令最后使用&表示后台执行。

你可能感兴趣的:(shell获取操作系统基本信息)