C++ get linux distribution name\version

后端 未结 6 1628
悲哀的现实
悲哀的现实 2021-01-12 06:10

According to the question \" How to get Linux distribution name and version? \", to get the linux distro name and version, this works:

lsb_release -a
         


        
6条回答
  •  無奈伤痛
    2021-01-12 07:08

    For recent linux distros you can use following to get the OS info. The output is pretty standard and can be parsed using following spec:

    https://www.freedesktop.org/software/systemd/man/os-release.html

    cat /etc/os-release
    

    Sample outputs:

    NAME=Fedora
    VERSION="27 (Twenty Seven)"
    ID=fedora
    VERSION_ID=27
    PRETTY_NAME="Fedora 27 (Twenty Seven)"
    
    NAME="Ubuntu"
    VERSION="16.04.4 LTS (Xenial Xerus)"
    ID=ubuntu
    ID_LIKE=debian
    PRETTY_NAME="Ubuntu 16.04.4 LTS"
    VERSION_ID="16.04"
    
    NAME="Arch Linux"
    PRETTY_NAME="Arch Linux"
    ID=arch
    ID_LIKE=archlinux
    ANSI_COLOR="0;36"
    

提交回复
热议问题