Skip to content

How to find Ubuntu Version, Codename and OS Architecture in Shell Script

How to find Ubuntu Version Codename and OS Architecture in a Shell Script. How to get and store ubuntu version, codename in variable in a shell script

Covers
Ubuntu
Versions & support
About Ubuntu →
On this page

While working with the bash shell scripting, Many times you may require to get your system version or codename or operating system architecture. In this article, you will learn, how to find Ubuntu Version, Codename, and OS Architecture in a shell script.

1. Get Ubuntu Version

To get ubuntu version details, Use -r with lsb_release command.

$ lsb_release -r

Release:	14.04

Also use -s or --short to get details in short format

$ lsb_release -r --short

14.04

2. Get Ubuntu Codename

To get ubuntu version details, Use -c with lsb_release command.

$ lsb_release -c

Codename:	trusty

Also use -s or --short to get details in short format

$ lsb_release -c --short

trusty

3. Get OS Architecture Details

To find the operating system architecture details using uname command with -m parameter.

$ uname -m

x86_64

4. Shell Script – Store Values in Variable

Now if we need to use these values in a shell script, store these values in variables. Below example, the shell script will help you to store the output of commands in variables and use them

#!/bin/bash

Version=$(lsb_release -r --short)
Codename=$(lsb_release -c --short)
OSArch=$(uname -m)

echo "Version = $Version"
echo "Codename = $Codename"
echo "OS Architecture = $OSArch"

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

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


Back to top