How to get Ubuntu distribution's full code name?
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
My variant on what's already offered:
. /etc/os-release; echo ${VERSION/*, /}
The shortest, Bashiest answer to date.
If you don't care to load /etc/os-release
's contents into your current environment, you can fake bash into thinking it's loading a script fairly easily:
bash <(cat /etc/os-release; echo 'echo ${VERSION/*, /}')
Grep:
$ grep $(lsb_release -rs) /usr/share/python-apt/templates/Ubuntu.info | grep -m 1 "Description: Ubuntu " | cut -d "'" -f2
Trusty Tahr
Explanation:
lsb_release -rs
-> Prints your installed Ubuntu version.grep $(lsb_release -rs) /usr/share/python-apt/templates/Ubuntu.info
-> Grab all the lines which contains your release version, in my case it's 14.04.grep -m 1 "Description: Ubuntu "
-> Again grabs only the matched first line(because of-m
flag) which contains the stringDescription: Ubuntu
.cut -d "'" -f2
-> prints the field number 2 according to the delimiter single quote'
Awk:
$ awk -v var=$(lsb_release -rs) '$3~var {print $4" "$5;exit;}' /usr/share/python-apt/templates/Ubuntu.info | cut -d"'" -f2
Trusty Tahr
Explanation:
Declaring and assigning Variable in awk is done through -v
parameter.So the value of lsb_release -rs
command is assigned to the variable var
which inturn helps to print field 4 ,field 5 from the lines contain the string 14.04
and exists if its found an one.Finally the cut
command helps to remove the single quotes.