How to find Ubuntu version and codename in a shell script

Question: I am writing a shell script where I need to obtain the release version and codename of Ubuntu system. How can I find Ubuntu version/codename inside a shell script?

To find the version/codename of Ubuntu distribution from the command line, you can use lsb_release command which displays distribution-specific information.

The following shell script snippet demonstrate how to store the version and codename of Ubuntu in two different variables.


version=`lsb_release --release | cut -f2`
codename=`lsb_release --codename | cut -f2`

echo $version
echo $codename

lsb_release command also works on other Linux distros, including Debian, CentOS, Fedora and OpenSUSE.

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.

Leave a comment

Your email address will not be published. Required fields are marked *