Linux windows type version

Determine the OS version, Linux and Windows from Powershell

How can I determine the OS type, (Linux, Windows) using Powershell from within a script? The ResponseUri isn’t recognised when this part of my script is ran on a Linux host.

$UrlAuthority = $Request.BaseResponse | Select-Object -ExpandProperty ResponseUri | Select-Object -ExpandProperty Authority 
If ($OsType -eq "Linux") < $UrlAuthority = ($Request.BaseResponse).RequestMessage | Select-Object -ExpandProperty RequestUri | Select-Object -ExpandProperty host >Else $UrlAuthority = $Request.BaseResponse | Select-Object -ExpandProperty ResponseUri | Select-Object -ExpandProperty Authority 

10 Answers 10

Aren’t there environment variables you can view on the other platforms for the OS?

Particularly, on Windows at least, there’s an OS environment variable, so you should be able to accomplish this by using $Env:OS .

Since some time has passed and the PowerShell Core (v6) product is GA now (the Core branding has been dropped as of v7), you can more accurately determine your platform based on the following automatic boolean variables:

$IsMacOS $IsLinux $IsWindows 

@gms0ulman It looks like it reports Windows_NT on any Windows box. I think OP is looking for one versus the other since he wasn’t asking something along the lines of «Am I on Windows 10 or Ubuntu?»

@boomcubist I thought of an even simpler check (and was unable to edit my other comment): If ($env:OS) since it only has two states

Use [System.Environment]::OSVersion.Platform . It is documented on MSDN for and appears to be present in all .NET versions (1.1, 2.0, 3.0, 3.5, and the current version). $PSVersionTable.Platform returns that value in PowerShell 6 Core. It will be Win32NT on Windows or Unix on Linux and macOS.

@DaveF Since PSv6 has gone GA, there are now $IsMacOS and $IsLinux automatic variables where you can determine your OS.

Also, it’s worth mentioning that $IsWindows can be used to determine if the OS is Windows. However, this variable will evaluate to false on older versions of PowerShell so it should only be used if scripts are intended to be used with newer releases.

For PowerShell Core (Powershell Version 6.0+), you can use Automatic Variables: $IsLinux , $IsMacOS and $IsWindows .

if ($IsLinux) < Write-Host "Linux" >elseif ($IsMacOS) < Write-Host "macOS" >elseif ($IsWindows)

Since the PowerShell versions 6.1 on Windows/Linux/OSX went to GA you can use the new properties of $PSVersionTable , OS , Platform and GitCommitId

Update In v6.0.0-beta.3 there are some breaking changes :

Platform Win32NT OS Microsoft Windows 10.0.15063

PS C:\Users\LotPings> $PSVersionTable Name Value ---- ----- PSVersion 6.1.0 PSEdition Core GitCommitId 6.1.0 OS Microsoft Windows 10.0.17134 Platform Win32NT PSCompatibleVersions PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0 

Platform Unix OS Linux (ubuntu)

PS /home/LotPings> $PSVersionTable Name Value ---- ----- PSVersion 6.1.0 PSEdition Core GitCommitId 6.1.0 OS Linux 4.15.0-34-generic #37-Ubuntu SMP Mon Aug 27 15:21:48 UTC 2018 Platform Unix PSCompatibleVersions PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0 
PS /Users/LotPings> $PSVersionTable Name Value ---- ----- PSVersion 6.1.0 PSEdition Core GitCommitId 6.1.0 OS Darwin 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RE. Platform Unix PSCompatibleVersions PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0 

Источник

Читайте также:  Файловая система linux ssd

5 Command Line Ways to Find Out Linux System is 32-bit or 64-bit

This tutorial describes how to find out whether your Linux system’s OS is 32-bit or 64-bit. This will be helpful if you wanted to download or install an application in your Linux system. As we all know, we can’t install 64-bit applications into a 32-bit OS type. That’s why knowing your Linux system’s OS type is important.

Check Linux System is 32-bit or 64-bit

Here are the five easy and simple methods to verify your Linux system’s OS type. It doesn’t matter whether you’re using a GUI or CLI type systems, the following commands will work on almost all Linux operating systems such as RHEL, CentOS, Fedora, Scientific Linux, Debian, Ubuntu, Linux Mint, openSUSE etc.

1. uname Command

uname -a command will display your Linux system’s OS type. This is the universal command and it will work on almost all Linux/Unix operating systems.

To find out the system’s OS type, run:

$ uname -a Linux tecmint.com 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

2. dpkg Command

dpkg command will also display whether your Debian/Ubuntu operating system is 32-bit or 64-bit. This command will work only on Debian and Ubuntu based distributions and it’s derivatives.

Open your Terminal, and run:

$ dpkg --print-architecture 

If your OS is 64-bit, you’ll get the following output:

If your OS is 32-bit, then the output will be:

3. getconf Command

getconf command will also display the system configuration variables. Now, let me show you how to find out the Linux system arch using getconf command.

$ getconf LONG_BIT 64

For more details refer the man pages.

4. arch Command

arch command will display your OS type. This command is similar to uname -m command. If its output is x86_64 then it’s 64-bit OS. If the output is i686 or i386, then it’s 32-bit OS.

5. file Command

file command with with a special argument /sbin/init will display the OS type.

$ file /sbin/init /sbin/init: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=7a4c688d009fc1f06ffc692f5f42ab09e68582b2, stripped

Conclusion

You now know the ways to find out your Linux operating system’s type. Of course, there are few other ways to find out the OS type, but these are the often and pragmatic methods so far. If you know any other commands or methods to display the OS type, feel free to let us know in the comments section below.

A Linux Consultant, living in India. He loves very much to write about Linux, Open Source, Computers and Internet. Apart from that, He’d like to review Internet tools and web services.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Parted Command in Linux

TLDR Man Pages for Linux Commands

apt-get Command Examples

Ubuntu apt-cache Commands

apt Command Examples

Funny Linux Commands

11 thoughts on “5 Command Line Ways to Find Out Linux System is 32-bit or 64-bit”

I’d just like to interject for a moment. What you’re referring to as Linux, is in fact, GNU/Linux, or as I’ve recently taken to calling it, GNU plus Linux. Linux is not an operating system unto itself, but rather another free component of a fully functioning GNU system made useful by the GNU corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX. Many computer users run a modified version of the GNU system every day, without realizing it. Through a peculiar turn of events, the version of GNU which is widely used today is often called “Linux”, and many of its users are not aware that it is basically the GNU system, developed by the GNU Project. There really is a Linux, and these people are using it, but it is just a part of the system they use. Linux is the kernel: the program in the system that allocates the machine’s resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. Linux is normally used in combination with the GNU operating system: the whole system is basically GNU with Linux added, or GNU/Linux. All the so-called “Linux” distributions are really distributions of GNU/Linux. Reply

Читайте также:  Проверить скорость интернета через терминал линукс

Great post! You can also check using a environment variable: echo $HOSTTYPE Result: i386 -> 32 bits
x86_64 -> 64 bits Reply

Источник

WSL: Am I running version 1 or version 2?

I have Windows Subsystem for Linux, but I don’t know which version I have, and many things won’t work in version 1. How do I check my version?

From that thread, it looks like the following bash command works: uname -r | grep Microsoft > /dev/null && echo «WSL1» . — It’s a pretty adhoc way to detect it, but it will print «WSL1» if that’s what you’re running.

@BrainSlugs83 Extremely fragile but works for me! In WSL1, uname -r ends with -Microsoft , in WSL2, it ends -microsoft-standard . lower case «m»!

@Rinzwind If the question is on-topic, then so are the answers to that question. If someone asks how to create a bootable Ubuntu USB stick on Windows, then that question is on-topic, and so are all the answers to it, even if the answers mention unetbootin.exe . Same thing with WSL.

5 Answers 5

Version 16299

  1. At a Windows 10 command prompt, run ver . Is the next-to-last numeric group version 18917 or higher? If so, it is possible you have WSL 2 but not yet verified. Go on to step A or B.
    If you do not see Windows version 18917 or higher, you have version 1.
    This illustrates the result when the OS is Build 16299: A. Open Windows PowerShell or cmd and enter the command wsl -l -v . If version 2 is installed properly, you will see the version number. If you don’t see a version number, or if you see an error message (Thank you, Cornea Valentin) you have version 1 (you may also see a version number ‘1’ which could indicate that you’re running v1 — see here). Uninstall it then reinstall it as per https://scotch.io/bar-talk/trying-the-new-wsl-2-its-fast-windows-subsystem-for-linux B. From the WSL shell prompt, run uname or uname -r . If the kernel version >= 4.19, it’s WSL Version 2.
Читайте также:  Настройка proxy kali linux

WSL 1 was based on Microsoft’s Linux-compatible kernel interface, a compatibility translation layer with no Linux kernel code.

WSL 2 was redesigned with a Linux kernel running in a lightweight VM environment, and innovators have found many more things they can do with WSL 2.

I needed to use uname -r to see the kernel version, but the kernel version ended up being 4.4.0, which I’m pretty sure means WSL 1.

For me, wsl -l -v prints the usage info (i.e. doesn’t work), but wsl -l —verbose prints the verbose list as intended. systeminfo.exe gives me OS Version: 10.0.19041 N/A Build 19041 .

Источник

How to check the OS version at runtime, e.g. on Windows or Linux, without using a conditional compilation statement

How do I determine what platform my C# code is running on? for example whether it is running on Linux or windows so that I can execute different code at runtime. I have a C# Windows application that I want to build to target Windows and Linux platforms. So far I have created two project files pointing to the same set of source code files. I then use a conditional compilation statement one of the projects called LINUX. Where there are difference in the actual code I use conditional statements using the conditional compilation statement, for example,

#if (LINUX) ' Do something #endif 

11 Answers 11

I found this recommendation on one of Microsoft’s blogs:

We recommend you to use RuntimeInformation.IsOSPlatform() for platform checks.

IsOSPlatform() takes an argument of types OSPlatform which has three values by default: Windows , Linux and OSX . It can be used as follow:

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) < // Do something >

The API is part of .NET Standard 2.0, and therefore available in .NET Core 2.0 and .NET Framework 4.7.1.

[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); >> 

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 any PlatformID 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.

Источник

Оцените статью
Adblock
detector