Linux下有时需要根据系统类型是centos,或ubuntu,从而进行选择不同的命令执行,
有下面几种命令可以确定系统类型
- lsb_release -a
- cat /etc/redhat-release
- cat /etc/issue
- cat /proc/version
下图是在centos系统几种命令的输出
[root@localhost]# lsb_release -a
bash: lsb_release: command not found...
[root@localhost]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
[root@localhost]# cat /etc/issue
\S
Kernel \r on an \m
[root@localhost]# cat /proc/version
Linux version 3.10.0-1127.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Tue Mar 31 23:36:51 UTC 2020
下图是在ubuntu系统几种命令的输出
root@ubuntu:/home# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
root@ubuntu:/home# cat /etc/redhat-release
cat: /etc/redhat-release: No such file or directory
root@ubuntu:/home# cat /etc/issue
Ubuntu 18.04.2 LTS \n \l
root@ubuntu:/home# cat /proc/version
Linux version 4.15.0-176-generic (buildd@lcy02-amd64-020) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #185-Ubuntu SMP Tue Mar 29 17:40:04 UTC 2022