/etc/*release 文件示例

/etc/*release 文件示例

/etc/*release在哪里可以找到各种 Linux/Unix/MacOS 发行版和版本的不同文件的列表?

命令输出也同样如此uname -a

答案1

并非所有系统都有/etc/*release*文件,因此如果您确实希望跨 Unix,则不能使用它们。

POSIX 认可的解决方案是uname-- 如果您只需要一个粗略的 OS ID,uname -s 那么可能就足够了。
我不知道有任何 uname 输出的规范列表,但是维基百科上有一张表格可能是一个很好的起点(并且假设您可以访问您想要检测的平台,以便您可以检查它们返回的内容)。

有时uname并不能说明全部情况(例如 Linux 发行版,其变化性很大)——如果有必要,你可以找出更具体的信息(例如“哪个Linux 发行版?”),第二次使用系统特定工具(如lsb_releaseLinux 或oslevelAIX)

答案2

大多数发行版都有一个名为lsb_release

Gentoo:

$ lsb_release -a
LSB Version:    n/a
Distributor ID: Gentoo
Description:    Gentoo Base System release 2.0.3
Release:    2.0.3
Codename:   n/a

CentOS:

$ lsb_release -a
LSB Version:    :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 5.7 (Final)
Release:    5.7
Codename:   Final

其他 *nix 发行版:http://linuxmafia.com/faq/Admin/release-files.html

答案3

下面是我正在编写的 C 库的摘录:

const char* dist = dist_from_os_release();
if (strlen(dist) != 0)
    return dist;
else if (exists("/etc/arch-release"))
    return "arch";
else if (exists("/etc/altlinux-release"))
    return "altlinux";
else if (exists("/etc/angstrom-version"))
    return "angstrom";
else if (exists("/etc/annvix-release"))
    return "annvix";
else if (exists("/etc/arklinux-release"))
    return "arklinux";
else if (exists("/etc/aurox-release"))
    return "aurox";
else if (exists("/etc/blackcat-release"))
    return "blackcat";
else if (exists("/etc/cobalt-release"))
    return "cobalt";
else if (exists("/etc/conectiva-release"))
    return "conectiva";
else if (exists("/etc/debian_version") || exists("/etc/debian_release"))
    return "debian";
else if (exists("/etc/fedora-release"))
    return "fedora";
else if (exists("/etc/eos-version"))
    return "FreeEOS";
else if (exists("/etc/frugalware-release"))
    return "frugalware";
else if (exists("/etc/gentoo-release"))
    return "gentoo";
else if (exists("/etc/hlfs-release") || exists("/etc/hlfs_release"))
    return "HLFS";
else if (exists("/etc/immunix-release"))
    return "immunix";
else if (exists("knoppix_version"))
    return "knoppix";
else if (exists("/etc/lfs-release") || exists("/etc/lfs_version"))
    return "LFS";
else if (exists("/etc/linuxppc-release"))
    return "Linux-PPC";
else if (exists("/etc/mageia-release"))
    return "mageia";
else if (exists("/etc/mandrake-release"))
    return "mandrake";
else if (exists("/etc/mandriva-release") || exists("/etc/mandakelinux-release"))
    return "mandriva";
else if (exists("/etc/meego-release"))
    return "meego";
else if (exists("/etc/mklinux-release"))
    return "MkLinux";
else if (exists("/etc/nld-release"))
    return "Novell Linux Desktop";
else if (exists("/etc/pld-release"))
    return "PLD Linux";
else if (exists("/etc/redhat-release") || exists("/etc/redhat_version"))
    return "RHEL";
else if (exists("/etc/rubix-version"))
    return "rubix";
else if (exists("/etc/slackware-version") || exists("/etc/slackware-release"))
    return "slackware";
else if (exists("/etc/e-smith-release"))
    return "SME Server";
else if (exists("/etc/release"))
    return "Solaris SPARC";
else if (exists("/etc/sun-release"))
    return "Sun JDS";
else if (exists("/etc/SuSE-release") || exists("/etc/novell-release") || exists("/etc/sles-release"))
    return "SuSE";
else if (exists("/etc/synoinfo.conf"))
    return "Synology";
else if (exists("/etc/tinysofa-release"))
    return "tinysofa";
else if (exists("/etc/trustix-release") || exists("/etc/trustix-version"))
    return "trustix";
else if (exists("/etc/turbolinux-release"))
    return "TurboLinux";
else if (exists("/etc/ultrapenguin-release"))
    return "ultrapenguin";
else if (exists("/etc/UnitedLinux-release"))
    return "UnitedLinux";
else if (exists("/etc/va-release"))
    return "VA-Linux/RH-VALE";
else if (exists("/etc/yellowdog-release"))
    return "yellowdog";
else {
    struct utsname unameD;
    uname(&unameD);
    return strlen(unameD.nodename) > 0 ? unameD.nodename : unameD.sysname;
}

https://github.com/offscale/osbuild/commit/49200888e717907bb3dc36021f725b7e668274b7#diff-cc898028570115949c889ad5b8266020R34

相关内容