When you first log into an unfamiliar server, determining which Linux distribution is running helps you choose the right commands and tools. Knowing how to check os on linux is a fundamental skill for any system administrator or developer. This guide covers every reliable method, from simple commands to reading system files, so you can quickly identify your operating system.
Linux comes in many flavors—Ubuntu, CentOS, Debian, Fedora, and more. Each has its own package manager, default paths, and quirks. Without knowing what you’re working with, you might run the wrong update command or install software incorrectly. Let’s fix that right now.
How To Check Os On Linux
The fastest way to identify your Linux OS is using the command line. Most distributions include built-in tools that display system information. Below are the most common and reliable methods, ordered from simplest to most detailed.
Using The Lsb_Release Command
The lsb_release command is specifically designed to show Linux Standard Base (LSB) information. It works on most modern distributions like Ubuntu, Debian, and Fedora.
- Open a terminal window.
- Type:
lsb_release -a - Press Enter. You’ll see output similar to:
Distributor ID: Ubuntu Description: Ubuntu 22.04.3 LTS Release: 22.04 Codename: jammy
If the command isn’t found, install it first. On Debian-based systems, run sudo apt install lsb-release. On Red Hat-based systems, use sudo yum install redhat-lsb.
Reading The Os-Release File
Nearly every Linux distribution includes a file at /etc/os-release. This file contains standardized variables that describe the OS. It’s part of the systemd suite and is highly reliable.
Run this command to view its contents:
cat /etc/os-release
You’ll see output like:
NAME="Ubuntu" VERSION="22.04.3 LTS (Jammy Jellyfish)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 22.04.3 LTS" VERSION_ID="22.04"
This method works even if lsb_release is not installed. It’s my go-to for minimal installations or containers.
Checking The Hostnamectl Command
On systems using systemd (which is most modern Linux distros), the hostnamectl command provides operating system details along with hostname and kernel information.
Simply type:
hostnamectl
The output includes lines like:
Static hostname: myserver Icon name: computer-vm Chassis: vm Machine ID: abc123... Boot ID: def456... Operating System: Ubuntu 22.04.3 LTS Kernel: Linux 5.15.0-91-generic Architecture: x86-64
This is one of the cleanest ways to get a summary. It shows the OS name, version, and architecture in one glance.
Using The Uname Command
The uname command displays kernel information, not the distribution name. However, it’s still useful for understanding your environment, especially if you need to check if you’re on a 32-bit or 64-bit system.
Common variations:
uname -a— Shows all system informationuname -r— Shows kernel releaseuname -m— Shows machine hardware name (e.g., x86_64)
Example output for uname -a:
Linux myserver 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
While this doesn’t tell you “Ubuntu” directly, you can often infer the distribution from the kernel version string. For instance, the presence of “Ubuntu” in the output is a dead giveaway.
Examining The Issue Or Redhat-Release Files
Older distributions or specialized ones may use different files. Check these locations:
/etc/issue— Contains a short identification string/etc/redhat-release— Found on Red Hat, CentOS, Fedora/etc/debian_version— Found on Debian-based systems/etc/SuSE-release— Found on openSUSE
For example, on a CentOS server:
cat /etc/redhat-release
Output:
CentOS Linux release 7.9.2009 (Core)
On Debian:
cat /etc/debian_version
Output:
11.6
These files are legacy but still present on many systems. They provide a quick, reliable check without extra commands.
Using The Dmidecode Command (For Hardware)
If you need to check the OS from a hardware perspective, dmidecode reads the DMI (Desktop Management Interface) table. This is more about the system’s BIOS or firmware, but it can reveal the installed OS.
Run with sudo:
sudo dmidecode -t system
Look for the “Product Name” or “Version” fields. This is less common for OS checking but useful in virtualized environments.
Checking With The Neofetch Or Screenfetch Tools
For a more visual and detailed output, tools like neofetch and screenfetch display system information in a colorful ASCII art format. They are not installed by default but are easy to add.
Install on Ubuntu/Debian:
sudo apt install neofetch
Then run:
neofetch
The output includes the OS logo, distribution name, kernel, uptime, and more. It’s great for quick visual identification, especially when sharing screenshots.
Using The /Etc/*release Wildcard
If you’re unsure which specific file exists, use a wildcard to list all release files:
cat /etc/*release
This will concatenate the contents of /etc/os-release, /etc/redhat-release, /etc/debian_version, and any other similar files. You’ll see multiple lines, but the relevant distribution info will be there.
Checking With The Apt Or Yum Package Manager
Sometimes the package manager itself reveals the OS. For example, on Debian-based systems, the apt sources list often contains the distribution codename.
Check the sources list:
cat /etc/apt/sources.list
Look for lines like deb http://archive.ubuntu.com/ubuntu jammy main. The word “jammy” indicates Ubuntu 22.04.
On Red Hat-based systems, check the yum repository configuration:
cat /etc/yum.repos.d/*.repo
You’ll often see references to “centos” or “rhel” in the URLs.
Using The Python Platform Module
If Python is installed, you can use the platform module to get OS information. This is handy for scripting.
Run:
python3 -c "import platform; print(platform.platform())"
Output example:
Linux-5.15.0-91-generic-x86_64-with-glibc2.35
To get the distribution name specifically, use:
python3 -c "import platform; print(platform.linux_distribution())"
Note: linux_distribution() is deprecated in newer Python versions but still works on many systems. For a more modern approach, use the distro library (install with pip install distro).
Checking The Docker Container OS
If you’re inside a Docker container, the methods above still work, but you might see the base image’s OS rather than the host. To check the host OS from inside a container, you often need to mount the host’s /etc/os-release file.
Alternatively, run cat /etc/hostname or check environment variables like $HOSTNAME. For the container itself, use the same commands as above.
Using The Getconf Command
The getconf command shows system configuration variables. While not directly showing the OS name, it can reveal the GNU C library version, which correlates with certain distributions.
Run:
getconf GNU_LIBC_VERSION
Output:
glibc 2.35
This is less specific but can help narrow down possibilities.
Checking The Kernel Boot Parameters
If you have access to the boot loader (GRUB), you can check kernel boot parameters. From the command line, view /proc/cmdline:
cat /proc/cmdline
Look for parameters like root= or BOOT_IMAGE=. These sometimes include distribution-specific paths.
Using The Dmesg Command
The dmesg command shows kernel ring buffer messages. Early boot messages often include the OS name. Run:
dmesg | grep -i "linux version"
Output example:
[ 0.000000] Linux version 5.15.0-91-generic (buildd@lcy02-amd64-081) (gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023
The presence of “Ubuntu” in the compiler information confirms the distribution.
Creating A Simple Script For Quick Checks
If you frequently need to check the OS, create a small script. Save this as checkos.sh:
#!/bin/bash echo "OS Information:" cat /etc/os-release 2>/dev/null || cat /etc/redhat-release 2>/dev/null || cat /etc/debian_version 2>/dev/null || echo "Unknown OS" echo "" echo "Kernel: $(uname -r)" echo "Architecture: $(uname -m)"
Make it executable with chmod +x checkos.sh and run it anytime.
Common Pitfalls And Tips
Here are some things to watch out for when checking your Linux OS:
- Virtual machines: The OS inside a VM may differ from the host. Always check inside the VM.
- Containers: Minimal containers might not have
/etc/os-release. Useunameor check the base image. - WSL (Windows Subsystem for Linux): WSL uses a custom kernel but shows the distribution from the installed image.
- Live USBs: The OS shown is the live environment, not the installed system.
- Embedded systems: Some embedded Linux builds omit standard files. Use
uname -aas a fallback.
Why Knowing Your OS Matters
Understanding your Linux distribution affects almost every administrative task:
- Package management: Ubuntu uses
apt, CentOS usesyumordnf, Arch usespacman. - Security updates: Each distribution has its own update cycle and repository.
- Software compatibility: Some software only supports specific distributions or versions.
- Troubleshooting: Community forums and documentation are distribution-specific.
For example, if you try to run apt update on a CentOS system, you’ll get a “command not found” error. Knowing the OS upfront saves time and prevents mistakes.
Automating OS Detection In Scripts
When writing scripts that need to work across multiple distributions, you can automate OS detection. Here’s a simple Bash example:
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
elif [ -f /etc/redhat-release ]; then
OS=$(cat /etc/redhat-release)
VER=""
else
OS=$(uname -s)
VER=$(uname -r)
fi
echo "Detected OS: $OS $VER"
This script checks for common files and falls back to uname if none are found. You can extend it to handle more cases.
Using Ansible Or Other Configuration Management
If you manage multiple servers, tools like Ansible can gather OS facts automatically. Run:
ansible all -m setup -a "filter=ansible_distribution*"
This returns the distribution name, version, and other details for all hosts in your inventory. It’s efficient for large environments.
Graphical Methods (If Available)
If you have a desktop environment, you can check the OS graphically:
- Ubuntu/GNOME: Go to Settings > About
- KDE Plasma: System Settings > About This System
- XFCE: Settings Manager > About
These interfaces show the distribution name and version in a user-friendly way.
Mobile And Embedded Linux
On devices like Raspberry Pi running Raspberry Pi OS, the same commands work. For Android (which uses a Linux kernel), you need to use the getprop command or check /system/build.prop.
Final Thoughts On Checking Your Linux OS
Mastering how to check os on linux is a small but essential skill. With the methods above, you can identify any Linux system quickly, whether it’s a server, desktop, container, or embedded device. Start with cat /etc/os-release for the most reliable result, and use lsb_release -a or hostnamectl for more detail.
Remember that no single method works 100% of the time across all distributions. Having multiple approaches in your toolkit ensures you’re never stuck wondering what OS you’re on. Practice these commands on different systems, and you’ll soon be able to identify any Linux environment at a glance.
Frequently Asked Questions
What Is The Easiest Way To Check The OS On Linux?
The easiest method is running cat /etc/os-release. It works on almost all modern distributions and requires no additional tools.
How Do I Check The Linux Kernel Version?
Use uname -r to see the kernel release. For full details, run uname -a.
Can I Check The OS Without Using The Terminal?
Yes, if you have a desktop environment, check the system settings under “About” or “System Information”. On servers, the terminal is usually the only option.
Why Does lsb_release Sometimes Fail?
The lsb_release command may not be installed by default on minimal or older systems. Install the lsb-release package or use /etc/os-release instead.
How Do I Check The OS On A Remote Server?
SSH into the server and run any of the commands above. For automation, use tools like Ansible or a simple script that runs cat /etc