Better way to check linux version?
From the Linux Standard Base article at wikipedia:
The Linux Standard Base (LSB) is a joint project by several Linux distributions under the organizational structure of the Linux Foundation to standardize the software system structure, including the filesystem hierarchy, used with Linux operating system. The LSB is based on the POSIX specification, the Single UNIX Specification, and several other open standards, but extends them in certain areas.
According to the LSB:
The goal of the LSB is to develop and promote a set of open standards that will increase compatibility among Linux distributions and enable software applications to run on any compliant system even in binary form. In addition, the LSB will help coordinate efforts to recruit software vendors to port and write products for Linux Operating System.
If you are using some LSB compliant distribution (and you should), just man lsb_release
:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 8.04.4 LTS
Release: 8.04
Codename: hardy
$ lsb_release -a
LSB Version: :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: CentOS
Description: CentOS release 5.5 (Final)
Release: 5.5
Codename: Final
Linux version check Linux command or a Java code
Have you tried with?
cat /etc/*-release
cat /etc/redhat-release
or
cat /etc/issue
or
cat /proc/version
or even with
uname -a
Looking at Java documentation I see you can get few basic information about the operating system via System.getProperty(), I suppose you use Java Standard Edition 6.0. But very likely also other versions should return same infos.
- os.name Operating system name
- os.arch Operating system architecture
- os.version Operating system version
See version of Operating System in shell unix
If you are using Linux you can see
cat /etc/fedora-release
This way you just can know the version if you known the distribution in this case Fedora.
but you can always try for a file *-release in the folder /etc
How to get linux version set in shell script?
In shell script:
VERSION=$(lsb_release -sr)
or VERSION=$(/usr/bin/lsb_release -sr)
with full path.
will store the release value in $VERSION. What error are you getting ??
How to get Linux distribution name and version?
Try:
cat /etc/lsb-release
You can also try
lsb_release -a
Or:
cat /proc/version
How do I identify the particular Linux flavor via command line?
Try the below command....
It worked for me...
cat /proc/version
Once you know that you are running Red Hat for example, you can get to the point with:
cat /etc/redhat-release
Or on Debian:
cat /etc/debian_version
or in general :
cat /etc/*-release
Also you could use the following command
cat /etc/issue
Determine Redhat Linux Version
If "anybody" has root access to your machine to either change /etc/redhat-release or install an alternate kernel you're most probably in bigger trouble than determining the redhat version of your system.
Just use the value pointed out by /etc/redhat-release or even better in terms of portability use the output of lsb_release as this is exactly the purpose they were made for.
With "anybody" being able to do anything with your system there is no other chance at all.
How to check the OS version at runtime, e.g. on Windows or Linux, without using a conditional compilation statement
[Editor's Note: This answer was applicable before .NET 4.7.1, or before the Windows Compatibility Pack for .NET Core was released. The current best answer is Alex Sanséau's to Stack Overflow question How to check the OS version at runtime, e.g. on Windows or Linux, without using a conditional compilation statement.]
You can detect the execution platform using System.Environment.OSVersion.Platform
:
public static bool IsLinux
{
get
{
int p = (int) Environment.OSVersion.Platform;
return (p == 4) || (p == 6) || (p == 128);
}
}
From the Mono FAQ:
How to detect the execution platform
The execution platform can be detected by using the
System.Environment.OSVersion.Platform
value. However correctly detecting Unix platforms, in every cases, requires a little more work. The first versions of the framework (1.0 and 1.1) didn't include anyPlatformID
value for Unix, so Mono used the value 128. The newer framework 2.0 added Unix to the PlatformID enum but, sadly, with a different value: 4 and newer versions of .NET distinguished between Unix and macOS, introducing yet another value 6 for macOS.This means that in order to detect properly code running on Unix platforms you must check the three values (4, 6 and 128). This ensure that the detection code will work as expected when executed on Mono CLR 1.x runtime and with both Mono and Microsoft CLR 2.x runtimes.
Related Topics
Creating an Alias in Ubuntu, in .Profile
Sending Snmp2 Trap Message from Linux Command Lne
Git Clone Using Ssh Failed in Windows Due to Permission Issue
.Net Core 3.1 Deploy on Centos 7
Having Trouble Wrapping Functions in The Linux Kernel
Gunicorn Does Not Start After Boot
Compare Two Different Urls Using Linux
Generating a Comprehensive Callgraph Using Gcc & Egypt
How to Set Environment Variable in Linux Permanently
Correct Way to Export Multiple Ld_Library_Paths
Dreaming of Making My Own Os- What Should I Use? (Suggestions)
Authenticating Gtk App to Run with Root Permissions
Linux Directory Starting with Dot