How to get Linux distribution name and version?

后端 未结 8 1848
轻奢々
轻奢々 2021-02-04 06:28

In Windows I read the registry key SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProductName to get the full name and version of the OS.

But in Linux, th

相关标签:
8条回答
  • 2021-02-04 07:10

    What's the purpose of getting that information?

    If you're trying to detect some features or properties of the system (e.g. does it support some syscall or does it have some library), instead of relying on output of lsb_release you should either:

    • try to use given features and fail gracefully (e.g. dlopen for libraries, syscall(2) for syscalls and so on)
    • make it a part of your ./configure check if applicable (standard FOSS way of automatically recognizing system features/properties)

    Note that the first way above applies even if your software is binary-only.

    Some code examples:

      dl = dlopen(module_path, RTLD_LAZY);
      if (!dl) {
        fprintf(stderr, "Failed to open module: %s\n", module_path);
        return;
      }
    
      funcptr = dlsym(dl, module_function);
      if (!funcptr) {
        fprintf(stderr, "Failed to find symbol: %s\n", module_function);
        return;
      }
      funcptr();
    
      dlclose(dl);
    

    You can even gracefully test for CPU opcodes support, read e.g. http://neugierig.org/software/chromium/notes/2009/12/flash-lahf.html , http://code.google.com/p/chromium/issues/detail?id=29789

    0 讨论(0)
  • 2021-02-04 07:11

    /etc/os-release is available on at least both CentOS 7 and Ubuntu 16.04, which makes it more cross-platform than lsb_release (not on CentOS) or /etc/system-release (not on Ubuntu).

    $ cat /etc/os-release
    

    Example:

    NAME=Fedora
    VERSION="17 (Beefy Miracle)"
    ID=fedora
    VERSION_ID=17
    PRETTY_NAME="Fedora 17 (Beefy Miracle)"
    ANSI_COLOR="0;34"
    CPE_NAME="cpe:/o:fedoraproject:fedora:17"
    HOME_URL="https://fedoraproject.org/"
    BUG_REPORT_URL="https://bugzilla.redhat.com/"
    
    0 讨论(0)
  • 2021-02-04 07:12
    1. cat release file to display Linux distro version

      $ cat /etc/*-release
      
    2. lsb_release will return Linux distribution name and version

      $ lsb_release -a 
      
    3. hostnamectl will return Linux distribution name and version

      $ hostnamectl
      
    4. To print certain system information

      $ uname -a
      or 
        -s, --kernel-name        print the kernel name
        -n, --nodename           print the network node hostname
        -r, --kernel-release     print the kernel release
        -v, --kernel-version     print the kernel version
        -m, --machine            print the machine hardware name
        -p, --processor          print the processor type (non-portable)
        -i, --hardware-platform  print the hardware platform (non-portable)
        -o, --operating-system   print the operating system
      
    5. To find out Static hostname, Chassis, Mchine ID, Virtualization, OS, Kernel, Architecture

      $ cat /proc/version
      
    0 讨论(0)
  • 2021-02-04 07:16

    Not sure I followed exactly what you're after but I think you just want the "all" flag on uname:

    uname -a
    
    0 讨论(0)
  • 2021-02-04 07:16

    Usually:

    cat /etc/issue
    
    0 讨论(0)
  • 2021-02-04 07:21
    lsb_release -ds ; uname -mr

    on my system yields the following from the bash (terminal) prompt:

    Ubuntu 10.04.4 LTS
    2.6.32-41-generic x86_64
    
    0 讨论(0)
提交回复
热议问题