2

Sometimes when I log on to a system via SSH (for example to the production server), I have such privileges that there can install some software, but to do that I need to know the system with which I am dealing.

I would be able to check how the system is installed there.

Is there a way from the CLI to determine what distribution of Unix/Linux is running?

simhumileco
  • 479
  • 5
  • 13

6 Answers6

5

Try:

uname -a

It will give you output such as:

Linux debianhost 3.16.0-4-686-pae #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) i686 GNU/Linux

You can also use:

cat /etc/*release*
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
NAME="Debian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=debian
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
maulinglawns
  • 8,426
  • 2
  • 28
  • 36
2

To get the hostname, kernel version, and other useful information about the system:

uname -a

To get the version of the Linux distribution, there is not an unique command. Every distro implements it differently. On Debian and Ubuntu:

cat /etc/debian_version

On Red Hat:

cat /etc/redhat-release 
cat /etc/lsb-release
lsb_release -a

On Fedora:

cat /etc/fedora-release
dr_
  • 28,763
  • 21
  • 89
  • 133
  • 1
    Systems using `systemd` should also have an [`/etc/os-release`](https://www.freedesktop.org/software/systemd/man/os-release.html) file. – James Sneeringer Dec 16 '16 at 17:59
1

For Linux you can try lsb_release command which provides Linux Standard Base and distro specific information. Try:

lsb_release -d

Also check for other options in man page

toshmarch
  • 79
  • 1
  • 7
1

This has been answered a couple of times over on SuperUser with the usual tricks already mentioned here. But this answer has a novel method I quite like:

python -c "import platform; print platform.dist()"

Note this only works if Python 2.3 or later is available and is no longer available in Python 3.8.

Heath Raftery
  • 1,232
  • 1
  • 15
  • 18
  • 1
    Thank you for this great answer, but notice that it is deprecated since Python 3.5 and will be removed in Python 3.8. – simhumileco Jan 08 '19 at 07:27
0

In a concise way you can do it like this (thanks to @daemontosh answer):

lsb_release -a

...show all the information.

Another concise way to get information is (thanks to @HeathRaftery and @JourneymanGeek answers):

cat /proc/version

but there are many Unixes that don't support the /proc pseudo-filesystem.

simhumileco
  • 479
  • 5
  • 13
0

Indeed this problem can also be solved using Python and the platform module (thanks to @HeathRaftery):

Using platform() function:

python -c 'import platform; print platform.platform()'
# Linux-4.9.0-8-amd64-x86_64-with-debian-9.6

Returns a single string identifying the underlying platform with as much useful information as possible.

Or using uname() function:

python -c 'import platform; print platform.uname()'
# ('Linux', 'debian', '4.9.0-8-amd64', '#1 SMP Debian 4.9.130-2 (2018-10-27)', 'x86_64', '')

Fairly portable uname interface. Returns a namedtuple() containing six attributes: system, node, release, version, machine, and processor.

simhumileco
  • 479
  • 5
  • 13