Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find Linux Distribution name using shell script?

I am writing a shell script in which I need the current operating system name to make it generic. Like:

if [ $Operating_System == "CentOS" ]
then
    echo "CentOS";
    # Do this
elif [ $Operating_System == "Ubuntu" ]
then
    echo "Ubuntu";
    # Do that
else
    echo "Unsupported Operating System";
fi

How will it be possible? Applying regular expression on lsb_release -a command or something else?

Thanks..

like image 397
Pratik Patil Avatar asked Apr 11 '15 18:04

Pratik Patil


People also ask

How do I find my distro?

Open a terminal program (get to a command prompt) and type uname -a. This will give you your kernel version, but might not mention the distribution your running. To find out what distribution of linux your running (Ex. Ubuntu) try lsb_release -a or cat /etc/*release or cat /etc/issue* or cat /proc/version.

How do I find my Ubuntu distribution name?

Open the terminal using “Show Applications” or with the keyboard shortcut [Ctrl] + [Alt] + [T]. Type the command “cat /etc/lsb-release” into the command line and press enter. The terminal shows the Ubuntu version you're running under “DISTRIB_RELEASE” and “DISTRIB_DESCRIPTION”.

What Linux distribution I have used?

The best way to determine a Linux distribution name and release version information is using cat /etc/os-release command, which works on almost all Linux system.


2 Answers

$ lsb_release -i
Distributor ID: Fedora
$ lsb_release -i | cut -f 2-
Fedora
like image 92
Ignacio Vazquez-Abrams Avatar answered Nov 05 '22 00:11

Ignacio Vazquez-Abrams


You can get the info from lsb_release:

echo "$(lsb_release -is)"

i stands for distributor id.

s stands for short.

For ex. It shows Ubuntu instead of Distributor Id: Ubuntu

There are other options:

-r : release

-d : description

-c : codename

-a : all

You can get this information by running lsb_release --help or man lsb_release

like image 41
Jahid Avatar answered Nov 04 '22 22:11

Jahid