Thursday, December 1, 2016

command line - How to get Ubuntu distribution's full code name?



$ lsb_release -c
Codename: trusty

$ cat /etc/issue
Ubuntu 14.04 LTS \n \l

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu

DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"


Output's of the above commands shows only the partial code name (ie, trusty). How do I get the full codename (trusty tahr) of my installed Ubuntu system?



Using no external tools:



You can just source (the source command is a dot .) the /etc/os-release and you'll have access to all the variables defined there:




$ . /etc/os-release
$ echo "$VERSION"
14.04, Trusty Tahr





Edit. If you want to remove the 14.04, part (as asked by terdon), you could:




$ . /etc/os-release
$ read _ UBUNTU_VERSION_NAME <<< "$VERSION"
$ echo "$UBUNTU_VERSION_NAME"
Trusty Tahr


Note that this is a bit clunky, since on other distributions, the VERSION field can have different format. E.g., on my debian,



$ . /etc/os-release
$ read _ UBUNTU_VERSION_NAME <<< "$VERSION"

$ echo "$UBUNTU_VERSION_NAME"
(wheezy)


Then, you could imagine something like this (in a script):



#!/bin/bash

if [[ -r /etc/os-release ]]; then
. /etc/os-release

if [[ $ID = ubuntu ]]; then
read _ UBUNTU_VERSION_NAME <<< "$VERSION"
echo "Running Ubuntu $UBUNTU_VERSION_NAME"
else
echo "Not running an Ubuntu distribution. ID=$ID, VERSION=$VERSION"
fi
else
echo "Not running a distribution with /etc/os-release available"
fi


No comments:

Post a Comment

11.10 - Can&#39;t boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...