How to know which Linux Distribution I'm using? [closed]
Asked Answered
D

6

25

Moved to https://superuser.com/questions/80251/how-to-know-which-linux-distribution-im-using

How to know which Linux Distribution I'm using?

uname -a gives Linux xxxxxx.net 2.6.9-42.0.3.EL.wh1smp #1 SMP Fri Aug 14 15:48:17 MDT 2009 i686 i686 i386 GNU/Linux How can I know this is Ubuntu/Debian/Fedora or Redhat?

I uses /etc/init.d/serviced restart for restarting serevices, seems it is not Redhat family

Update:

[~]$ cat /etc/issue
cat: /etc/issue: No such file or directory
[~]$ cat /etc/issue.net
cat: /etc/issue.net: No such file or directory
[~]$ lsb_release -a
-sh: lsb_release: command not found
[~]$ cat /etc/*-release
cat: /etc/*-release: No such file or directory
[~]$ cat /etc/*-version
cat: /etc/*-version: No such file or directory
[~]$ cat /etc/*release
cat: /etc/*release: No such file or directory
[~]$ cat /etc/*_release
cat: /etc/*_release: No such file or directory
[~]$ cat /etc/*version
cat: /etc/*version: No such file or directory
[~]$
Diplomatics answered 8/12, 2009 at 5:7 Comment(10)
are you connecting by terminal?Sauceda
This should be on superuser or serverfault. It's not a programming question.Volatilize
If you are looking for a reliable way to make your program behave accordingly on any given distribution, I'd suggest updating your question before its migrated.Hendel
I don't want to program anything, I just want to get disto info for installing a package.Diplomatics
underscore, not hyphen, in /etc/redhat_release. Try /etc/redhat*Prosciutto
no joy with underscore? Try rpm -qa | less, and see if there's any clues in the installed packages.Prosciutto
[itflux][~]$ cat /etc/*release cat: /etc/*release: No such file or directory [itflux][~]$ cat /etc/*_release cat: /etc/*_release: No such file or directory [itflux][~]$ cat /etc/*version cat: /etc/*version: No such file or directory [itflux][~]$Diplomatics
pm -qa | less A blank screen and at the end -sh: rpm: command not foundDiplomatics
[itflux][~]$ echo $PATH /usr/kerberos/bin:/bin:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin://bin:/sbin:/usr/sbinDiplomatics
Hmm. Your PATH looks okay. See my answer below. I think it's Red Hat.Sato
L
48

Try this:

cat /etc/*-release

You could also try /etc/*-version

Loch answered 8/12, 2009 at 5:9 Comment(3)
[itflux][~]$ cat /etc/*-release cat: /etc/*-release: No such file or directory [itflux][~]$ cat /etc/*-version cat: /etc/*-version: No such file or directoryDiplomatics
cat /etc/*[_-]release would be better: some distros use underscore, not hyphen.Prosciutto
could you please explain how does cat work in this case?Deirdredeism
S
21

If you have lsb_release command,

lsb_release -a

will tell you (or just use lsb_release -i).

lsb_release is in Linux Standard Base Core Specification.

Edit: Looks like you're on a Red Hat system. A google search on your uname output suggests so. This is not programmatic, of course!

Sato answered 8/12, 2009 at 5:11 Comment(4)
$ lsb_release -a -sh: lsb_release: command not foundDiplomatics
Judging from this and your other answers, looks like you have a really old linux system.Sato
lsb_relase was created to ease the pain of determining the distro easily from within a program. A lot of systems out in the wild and still in use lack this altogether.Hendel
You're right. If someone is using that old a distribution, the first step should probably be to upgrade to a more recent version! :-)Sato
H
11

/etc/issue or /etc/issue.net give a good clue. Newer distros provide /etc/lsb-release which make it easier to determine exact strings progmatically, i.e. distro name / major & minor release / web site, etc.

In the absence of /etc/lsb-release, its much more difficult, hence the creation of lsb-release.

As Alok said, it looks like you are on a rather ancient (or extremely sparse) system. I don't think this is a case that you can (reliably) progmatically determine with a few lines of code.

If all else fails, check to see what kind of package manager is in use (apt / rpm / others), check to see if /etc/init.d is a symlink (rpm / RH distros) or a directory (debian based distros) .. and you have a pretty good clue as to what you can expect to be present in the root file system as far as structure.

You can't please everyone :)

Hendel answered 8/12, 2009 at 5:10 Comment(4)
Debian and derivatives (Ubuntu) also have /etc/lsb-release. They also have the program lsb_release that will give you specific information (you don't have to parse the text file).Jeopardous
@MichaelM: You're reading a file either way .. either directly opening /etc/lsb-release or scraping the output of lsb_release (either way, you're still reading a file even if its stdout). If doing this progmatically, its best to just parse the file yourself (imho) .. fewer moving parts that may or may not be present :)Hendel
[itflux][~]$ cat /etc/issue cat: /etc/issue: No such file or directory [itflux][~]$ cat /etc/issue.net cat: /etc/issue.net: No such file or directory [itflux][~]$ lsb_release -a -sh: lsb_release: command not foundDiplomatics
I uses /etc/init.d/serviced restart for restarting serevices, seems it is not Redhat family But apt-get and rpm are both giving command not found messageDiplomatics
A
7

Seems like here's some info:

> cat /etc/issue
Welcome to SUSE LINUX Enterprise Server 9 (i586) - Kernel \r (\l).

> uname -a
Linux boxname 2.6.5-7.244-smp #1 SMP Mon Dec 12 18:32:25 UTC 2005 i686 athlon i386 GNU/Linux

> cat /etc/*-release
SUSE LINUX Enterprise Server 9 (i586)
VERSION = 9
PATCHLEVEL = 3
Agnes answered 8/12, 2009 at 5:13 Comment(4)
Whohooo someone does not like the answer, let's hear your opinion ... I've quite often tried to figure out what's running on a box, these are some of the things I look at, it tells you the kernel version, sometimes even the distro name ...Agnes
[itflux][~]$ cat /etc/issue cat: /etc/issue: No such file or directory [itflux][~]$ cat /etc/issue.net cat: /etc/issue.net: No such file or directory [itflux][~]$ lsb_release -a -sh: lsb_release: command not found [itflux][~]$ cat /etc/*-release cat: /etc/*-release: No such file or directory [itflux][~]$ cat /etc/*-version cat: /etc/*-version: No such file or directory [itflux][~]$Diplomatics
okay so you have not so standard linux, which is nothing new, but I assume at least uname -a give you some response ...Agnes
"Some response" yes; but a useful response? Not generally.Unsaid
S
2

A list the release filenames for the most common distros: Release files

And a function that might help you: Shell script

Sauceda answered 8/12, 2009 at 5:15 Comment(0)
P
1

EL stands for Enterprise Linux in this case, so I think RedHat or a clone (like CentOS). I don't know a good way to programatically find out what distro you're on; there's a few different clues for each one.

cat  /etc/redhat_release
cat /etc/debian_version

is a good start. (Note the Ubuntu doesn't modify /etc/debian_version when they pull changes from Debian, so my Ubuntu Karmic system has squeeze/sid in debian_version.)

Edit: forgot about lsb. Good call, Tim Post and Alok. The whole point of LSB is to give distro-independent ways to do things.

Prosciutto answered 8/12, 2009 at 5:12 Comment(7)
[itflux][~]$ cat /etc/redhat_release cat: /etc/redhat_release: No such file or directory [itflux][~]$ cat /etc/debian_version cat: /etc/debian_version: No such fileDiplomatics
EL could also be SuSE's Enterprise Linux, aka sles. It uses RPM like RedHat. Don't remember how to check for it.Prosciutto
Oh yeah, Suse has some commands on top of rpm. If you have yast2 or yum, you're on SuSE. Look in /etc/ for suse or novell.Prosciutto
There is no suse or novell folders under /etc [itflux][~]$ yum -sh: yum: command not foundDiplomatics
I googled for your kernel version, and came up with surprisingly few results. rpm.pbone.net/index.php3/stat/4/idpl/3331503/com/… does indicate that it's RHEL or CentOS. (CentOS = RHEL without the support contract. Same versions of everything. Not sure if they manage to make all their binaries identical, but they try.)Prosciutto
It should be /etc/redhat-release and /etc/debian-version (hyphens, not underscores)Interact
@Cocowalla: Ubuntu definitely still uses /etc/debian_version. If there are other Debian-derived distros that use - instead of _, maybe we need /etc/debian?versionProsciutto

© 2022 - 2024 — McMap. All rights reserved.