If you have just been hired as a sysadmin for a new company, or if you inherited a cloud server from a previous developer, the absolute first thing you must do before typing a single command is figure out exactly what operating system you are working with. Running a Debian apt package command on a Red Hat server will instantly result in a failure.
Because “Linux” is just the kernel, there are hundreds of different distributions (Ubuntu, CentOS, Alpine, Arch) layered on top of it. To identify both the specific distribution and the core kernel version, you must query the OS-release files in the terminal.
Method 1: The “os-release” File (The Modern Standard)
If the server was built within the last ten years, it will utilize systemd. Systemd centralizes all operating system identification data into a single, highly readable text file located in the /etc/ directory. This is the fastest and most reliable method to identify your distribution.
- Open your terminal or SSH into your server.
- Type this exact command:
cat /etc/os-release
- Press Enter.
The terminal will print a clean list of variables. You are looking for two specific lines:
PRETTY_NAME="Ubuntu 22.04.3 LTS"(This tells you the exact distribution and the human-readable version number).ID=ubuntu(This tells you the core family, indicating you should useaptfor package management).
Method 2: The “hostnamectl” Command
If you want a slightly more formatted output that includes the hardware architecture (e.g., verifying if the server is running on an Intel x86 chip or an ARM processor), you can use the hostname control command.
- Type this command:
hostnamectl
- Press Enter.
Look at the resulting output for the Operating System: line (which will display the distribution) and the Architecture: line (which will display x86-64 or aarch64).
Method 3: Check the Kernel Version (The Deep Dive)
Knowing you are running “Ubuntu” is helpful, but if you are trying to compile a custom hardware driver (like an NVIDIA graphics card driver), you don’t care about Ubuntu. You need to know the exact, raw version number of the Linux Kernel underneath it.
You can print the kernel version using the “Unix Name” command.
- Type this command:
uname -r
- Press Enter.
The terminal will output a string of numbers (e.g., 5.15.0-88-generic). This means you are running version 5.15 of the Linux kernel.
How to See Everything at Once
If you want to pull the kernel version, the hardware architecture, the hostname, and the build date all in a single command, you can use the -a (All) flag.
uname -a
Method 4: The Legacy Fallback (For Ancient Servers)
If you type cat /etc/os-release and the terminal screams “No such file or directory,” you are working on a very old, legacy server (like CentOS 6 or Ubuntu 12.04) that predates the modern systemd architecture.
Before systemd, every single distribution kept its version number in a differently named file. You can use a wildcard search to force the terminal to dump the contents of any file in the /etc/ directory that ends with the word “release.”
- Type this command:
cat /etc/*release
- Press Enter.
If it is an ancient Red Hat server, this command will trigger the /etc/redhat-release file and successfully print the operating system version.