我发现百度搜出来的结果多多少少只有一种,就是cat /etc/issue
。但是因为最近在做docker,所以发现部分容器的镜像可能采用的是比较简易的轻量级Linux环境(有mini, kit之类的)。这些环境可能没有etc/issue,所以记录一下其他的方法。
1. lsb_release command(2种)
$ lsb_release -a
Output:
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 9.5 (stretch)
Release: 9.5
Codename: stretch
$ lsb_release -d
Output:
Description: Debian GNU/Linux 9.5 (stretch)
2. /etc/os-release file
$ cat /etc/os-release
Output:
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
$ cat /etc/issue
Output:
Debian GNU/Linux 9 \n \l
3. hostnamectl command
$ hostnamectl
Output:
Static hostname: debian9.localdomain
Icon name: computer-vm
Chassis: vm
Machine ID: a92099e30f704d559adb18ebc12ddac4
Boot ID: 7607cbe605d44f638d6542d4c7b3878e
Virtualization: qemu
Operating System: Debian GNU/Linux 9 (stretch)
Kernel: Linux 4.9.0-8-amd64
Architecture: x86-64
4. uname command
我是其他几个都用不了,但是这个可以用,然后获取版本去linux开源找,发现是kit。然后我在container里面连按两次tab(Linux环境下,这个操作可以查看所有可以使用的command) 发现,虽然是alpine,但是很多指令都用不了。本来打算用curl,但是他不提供任何安装方法。所以选择用wget,download文件下来用里面的md5sum加密,然后用下面的命令切割出md5部分
md5sum filename|cut -d" " -f1
$ uname -srm
Output:
Linux 4.9.0-8-amd64 x86_64
5. /etc/*release
$ cat /etc/*release
英文网址:https://linuxize.com/post/how-to-check-linux-version/