确定 Linux 发行版

Bil*_*oon 11 linux shell

我正在尝试确定正在运行的 linux 服务器的风格。我不是要确定内核版本 - 而是要评估分销商。

gcc 已安装,在版本输出中显示 RedHat

# gcc --version
gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-11)
Run Code Online (Sandbox Code Playgroud)

这是否意味着我可以安全地假设我的服务器是 RedHat 服务器。有没有更好的 - 100% 防弹方法来解决这个问题?也适用于其他 linux 风格 - 不仅仅是这台服务器?

编辑:内容/etc/以防万一 - 但我想要一个也适用于其他版本的 linux 的解决方案。

# ls /etc/
./              backupmxhosts  domainusers     host.conf     localdomains  mailips        pam.d/      relayhosts               shadow              trustedmailhosts
../             bashrc*        exim.conf       inputrc       localtime     man.config     passwd      resolv.conf              skipsmtpcheckhosts  userdomains
DIR_COLORS      cron.deny      exim.pl         ld.so.cache   lynx.cfg      mtab           profile     secondarymx              spammeripblocks     vimrc
aliases         demodomains    exim.pl.local*  ld.so.conf    mail/         my.cnf         profile.d/  senderverifybypasshosts  sudoers
antivirus.exim  demouids       group           localaliases  mailhelo      nsswitch.conf  protocols   services                 termcap
Run Code Online (Sandbox Code Playgroud)

我没有*release*version文件在/etc/

# ls /etc*release; ls /etc/*version
/bin/ls: /etc/*release: No such file or directory
/bin/ls: /etc/*version: No such file or directory
Run Code Online (Sandbox Code Playgroud)

我试过 LSB

# lsb_release -a
LSB Version:
Distributor ID: n/a
Description:    (none)
Release:        n/a
Codename:       n/a
Run Code Online (Sandbox Code Playgroud)

另外 - 我想我在一个chroot jail(不太确定那是什么)里面,这可能是导致这个问题的原因。


更新:

我认为这对我有用。我想我可以放心地假设我正在使用 cent-os。

# cat /proc/version
Linux version 2.6.9-103.plus.c4smp (mockbuild@builder10.centos.org) (gcc version 3.4.6 20060404 (Red Hat 3.4.6-11)) #1 SMP Wed Dec 21 16:17:23 EST 2011
Run Code Online (Sandbox Code Playgroud)

小智 13

在大多数现代 Linux 发行版上,以下命令将为您提供其信息:

lsb_release -a
Run Code Online (Sandbox Code Playgroud)


小智 9

/etc/issue 可能是一个很好的起点。

通过检查不同发行版的信息文件可以找到更多信息:

Novell SuSE    /etc/SuSE-release
OpenSuSE       /etc/SuSE-release, /etc/os-release
Red Hat,CentOS /etc/redhat-release, /etc/redhat_version
Fedora         /etc/fedora-release, /etc/redhat-release, /etc/os-release
Slackware      /etc/slackware-release, /etc/slackware-version
Debian         /etc/debian_release, /etc/debian_version
Mandrake       /etc/mandrake-release
Yellow dog     /etc/yellowdog-release
Sun JDS        /etc/sun-release 
Solaris/Sparc  /etc/release 
Gentoo         /etc/gentoo-release
Amazon Linux   /etc/system-release
PLD Linux      /etc/pld-release, /etc/os-release
ArchLinux      /etc/arch-release, /etc/os-release
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅Unix 论坛


vit*_*aut 4

cat /proc/version
Run Code Online (Sandbox Code Playgroud)

例子:

  1. 乌班图:

    $ cat /proc/version
    Linux version 3.11.0-13-generic (buildd@roseapple) (gcc version 4.8.1 \
    (Ubuntu/Linaro 4.8.1-10ubuntu8) ) #20-Ubuntu SMP Wed Oct 23 07:38:26 UTC 2013
    
    Run Code Online (Sandbox Code Playgroud)
  2. 红帽/CentOS:

    $ cat /proc/version
    Linux version 2.6.32-220.13.1.el6.x86_64 (mockbuild@c6b6.bsys.dev.centos.org) \
    (gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) ) #1 SMP Tue Apr 17 23:56:34 BST 2012
    
    Run Code Online (Sandbox Code Playgroud)

另请参阅如何知道您正在使用哪个 Linux 发行版?