SDB:Find openSUSE version
Understanding the os-release fields
The os-release file is the file which contains all openSUSE version details. Please refer to the upstream documentation for details.
Important fields include
- NAME= The human-friendly name of the distribution, without version number. eg "openSUSE Leap" or "openSUSE Tumbleweed". Automatically parsing this field should be avoided.
- PRETTY_NAME= The human-friendly name of the distribution, including version number when relevant. eg "openSUSE Leap 15.0" or "openSUSE Tumbleweed". Automatically parsing this field should be avoided.
- VERSION= The human-friendly version of the distribution. Only used in Leap eg. "15.0". Automatically parsing this field should be avoided.
- ID= The computer-friendly name of the distribution, without version number. eg "opensuse-leap" or "opensuse-tumbleweed". This field should be safe for parsing in scripts.
- ID_LIKE= A space separated list of IDs for related operating systems with common behaviour to ID=. eg "opensuse suse". This is so scripts don't need to micro-manage every possible option of ID=. The entry of "suse" represents all openSUSE, SUSE, SUSE Linux Enterprise distributions and derivatives. "opensuse" repesents only openSUSE distributions and derivatives. This field should be safe for parsing in scripts.
- VERSION_ID= The computer-friendly version of the distribution. eg. "15.0" or "20180530". This field should be safe for parsing in scripts.
/usr/lib/os-release should be used unless /etc/os-release exists, which should be given precedence.
On openSUSE distributions /etc/os-release is normally a symlink to /usr/lib/os-release by default
The GUI way
Open /usr/lib/os-release or /etc/os-release in your favorite text editor.
The CLI way
Open a terminal, run
This should show something similar to:
NAME="openSUSE Leap"
VERSION="15.0"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.0"
PRETTY_NAME="openSUSE Leap 15.0"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.0"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"
More examples what this file looks like on the various openSUSE and SUSE Linux distributions can be found on SDB:SUSE_and_openSUSE_Products_Version_Outputs.
In Shell Scripts
It's easiest to simply source the file and check the variables it sets, for example
if [ -e /etc/os-release ]; then
. /etc/os-release
else
. /usr/lib/os-release
fi
if [ "$ID" = "opensuse-leap" ]; then
echo "Do something Leap specific"
...
elif [ "$ID" = "opensuse-tumbleweed" ]; then
echo "Do something Tumbleweed specific"
...
fi
However this is not suitable for scripts which need to do things for the broader openSUSE family of distros (ie. Leap, Tumbleweed and variants like Kubic), nor the entire *SUSE family of distros (ie. Leap, Tumbleweed, variants, AND SLE)
For this you need to start using the ID_LIKE field, depending on the scope you are interested in.
if [ -e /etc/os-release ]; then
. /etc/os-release
else
. /usr/lib/os-release
fi
if [[ "$ID_LIKE" = *"suse"* ]]; then
echo "Do something for any SUSE/openSUSE distro"
...
elif [[ "$ID_LIKE" = *"opensuse"* ]]; then
echo "Do something for any openSUSE distro, but not other SUSE distros"
...
fi
The os-release file is designed to source quickly. Starting grep or sed to extract information manually will usually be slower. However, if you prefer not to source the file, e.g. for POSIX compliance, potentially conflicting names or control over what happens, here is some code to extract the distribution ID:
osrel=$(sed -n '/^ID=/s/^.*=//p' /usr/lib/os-release);
if [ "$osrel" = "opensuse-leap" ]; then
...
fi
32 vs 64 Bit
The pretty name used to include whether the distribution is 32 or 64 bit with i586 or x86-64 in brackets. Newer versions do not include this information here, also as they usually only come in 64 bit anyway. Stackoverflow suggests to use uname -m or getconf LONG_BIT. The former states the hardware capability, the latter what is running, i.e. for a 32-bit Linux running on a platform that can run both 32 and 64 bit uname -m will say x86_64 and getconf LONG_BIT outputs 32.