Introduction
Given a minimal version of a Linux system, how can you know which distribution and which version of the distribution you are working on? This is a vital question. First, you may think about typing in uname -a, but this does not provide all of the information you may need. Luckily, there is a file that almost all distributions have that keeps this valuable data.
1. Using neofetch tool
Install neofetch
tool.
# CentOS / Rocky / AlmaLinux
sudo yum -y install epel-release
sudo yum -y install neofetch
# Debian / Ubuntu
sudo apt update
sudo apt install neofetch
With the package installed run the neofetch
command to use it.
$ neofetch
Ubuntu output sample:
CentOS output sample:
2. Checking /etc/os-release contents
This is the /etc/os-release file. You might guess how it can be viewed because we covered the use of cat command previously. So, you simply do the following and you will happily have what you are looking for.
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
3. Using uname command
uname
, on the other hand, provides the following system information:
- -a, –all print all information, in the following order, except omit -p and -i if unknown:
- -s, –kernel-name print the kernel name
- -n, –nodename print the network node hostname
- -r, –kernel-release print the kernel release
- -v, –kernel-version print the kernel version
- -m, –machine print the machine hardware name
- -p, –processor print the processor type (non-portable)
- -i, –hardware-platform print the hardware platform (non-portable)
- –version output uname version information and exit
- -o, –operating-system (mostly outputs GNU/Linux)
Examples of uname usage to get information about your OS release.
$ uname -o
GNU/Linux
$ uname -m
x86_64
$ uname -r
5.15.0-58-generic
$ uname -s
Linux
$ uname -a
Linux jammy 5.15.0-58-generic #64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
As you can see above, the distribution and version of the distribution cannot be found using the uname command.
4. Using lsb_release command
On Debian based Linux distributions, you can use the lsb_release command to print distribution-specific information.
Available options:
-v, --version: Show the version of the LSB against which your current installation is compliant.
-i, --id: Display the distributor's ID.
-d, --description: Display a description of the currently installed distribution.
-r, --release: Display the release number of the currently installed distribution.
-c, --codename: Display the code name of the currently installed distribution.
-a, --all: Display all of the above information.
-s, --short: Use the short output format for any information displayed. This format omits the leading header(s).
-h, --help: Show summary of options.
See examples on usage below.
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy
$ lsb_release -c
Codename: jammy
$ lsb_release -d
Description: Ubuntu 22.04.1 LTS
$ lsb_release -i
Distributor ID: Ubuntu
Using hostnamectl command
For Linux systems with Systemd init, you can get some system information from hostnamectl command output, like the Operating System, Kernel version and CPU architecture.
Run the hostnamectl
command as shown below.
root@jammy:~# hostnamectl
Static hostname: jammy
Icon name: computer-vm
Chassis: vm
Machine ID: c7e6502e86e14649a2d8e0bc52a1645c
Boot ID: ea250abf24cb4081ac0d6d3c4e34e261
Virtualization: kvm
Operating System: Ubuntu 22.04.1 LTS
Kernel: Linux 5.15.0-58-generic
Architecture: x86-64
Hardware Vendor: Hetzner
Hardware Model: vServer
See the complete list of available options with:
$ hostnamectl --help
hostnamectl [OPTIONS...] COMMAND ...
Query or change system hostname.
-h --help Show this help
--version Show package version
--no-ask-password Do not prompt for password
-H --host=[USER@]HOST Operate on remote host
-M --machine=CONTAINER Operate on local container
--transient Only set transient hostname
--static Only set static hostname
--pretty Only set pretty hostname
Commands:
status Show current hostname settings
set-hostname NAME Set system hostname
set-icon-name NAME Set icon name for host
set-chassis NAME Set chassis type for host
set-deployment NAME Set deployment environment for host
set-location NAME Set location for host
See the hostnamectl(1) man page for details.
Check /etc/issue Content
View content on /etc/issue
which also has OS release short information.
$ cat /etc/issue
Ubuntu 22.04.1 LTS \n \l
Conclusion
Finding the distribution and version of the distribution is as easy as you have found out. We hope it was beneficial and informative.
Recommended Linux Books to read:
- Best Linux Books for Beginners & Experts
- Best Linux Kernel Programming Books
- Best Linux Bash Scripting Books
- Top RHCSA / RHCE Certification Study Books
- Best Top Rated CompTIA A+ Certification Books
- Best LPIC-1 and LPIC-2 certification study books
Also Read: