To check the OS version in Linux, you can use a variety of commands depending on your needs. Below are the most commonly used methods:
1. Using cat
Command (OS Release Files)
Most Linux distributions store their version information in files like /etc/os-release
or /etc/*-release
.
Command:
cat /etc/os-release
Output Example:
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
VERSION_ID="20.04"
2. Using lsb_release
Command
If your Linux distribution supports the lsb_release
tool, it provides detailed information about the OS.
Command:
lsb_release -a
Output Example:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
3. Using hostnamectl
Command
This command works on systems using systemd
and gives basic information about the system, including the OS version.
Command:
hostnamectl
Output Example:
Static hostname: linux-server
Icon name: computer-vm
Chassis: vm
Machine ID: 1234567890abcdef
Boot ID: abcdef1234567890
Operating System: Ubuntu 20.04.6 LTS
Kernel: Linux 5.4.0-132-generic
Architecture: x86-64
4. Using uname
Command
The uname
command shows kernel and system information, but it doesn’t provide the full OS version.
Command:
uname -a
Output Example:
Linux linux-server 5.4.0-132-generic #148-Ubuntu SMP Fri Dec 9 06:49:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
For Kernel-Only Information:
uname -r
5. Using /etc/issue
File
The /etc/issue
file often contains a simple description of the OS.
Command:
cat /etc/issue
Output Example:
Ubuntu 20.04.6 LTS \n \l
6. Graphical Interface (GUI) Method
If you are using a Linux desktop environment, follow these steps:
- Open Settings or System Information.
- Look for the “About” or “Details” section.
- The OS version should be listed there.
Summary of Commands:
Command | Purpose |
---|---|
cat /etc/os-release |
Displays detailed OS version info. |
lsb_release -a |
Provides Linux Standard Base info. |
hostnamectl |
Shows OS, kernel, and architecture. |
uname -a |
Shows kernel and system info. |
cat /etc/issue |
Displays basic OS info. |
Use Case-Specific Recommendation:
- For detailed OS info, use:
cat /etc/os-release
. - For kernel-related info, use:
uname -r
.
Let me know if you need further assistance!