- Linux Command: Show Linux Version
- How to check linux kernel version number?
- /proc/version file
- Find Distribution Version
- Related media
- How to check os version in Linux command line
- Check os version in Linux
- The /etc/os-release file
- Checking OS version on Linux using the lsb_release command
- hostnamectl command
- uname command
- /etc/issue file
- Getting help
- Related media
- Conclusion
- How to Check OS Version in Linux
- Check Linux Version
- 1. From /etc/os-release
- 2. Using lsb_release command
- 3. Using Hostnamectl command
- 4. From /etc/issue file
- 5. From /etc/*release or /etc/*version
- Conclusion
- Configure Linux distributions
- Ways to run WSL
- List installed distributions
- Unregister and reinstall a distribution
- Run as a specific user
- Change the default user for a distribution
- Run a specific distribution
- Configure settings with .wslconfig and wsl.conf
- Per distribution configuration options with wsl.conf
- Options for wsl.conf
- automount
- Mount options
- network
- interop
- User preview options
- Global configuration options with .wslconfig
- Options for .wslconfig
- WSL 2 setting preview options
Linux Command: Show Linux Version
[a] uname – Print kernel and system information.
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | No |
Requirements | None |
Est. reading time | 1m |
[b] lsb_release – Print distribution-specific information. [c] /proc/version file – Print running kernel information.
How to check linux kernel version number?
Open a shell prompt (or a terminal) and type the following command to see your current Linux kernel version:
$ uname -r
Sample outputs:
Or type the following command:
$ uname -mrs
Sample outputs:
To print all information, enter:
$ uname -a
Sample outputs:
- 2.6.32-23 – Linux kernel version number
- pae – pae kernel type indicate that I’m accssing more than 4GB ram using 32 bit kernel.
- SMP – Kernel that supports multi core and multiple cpus.
/proc/version file
Type the following command to see Linux version info:
$ cat /proc/version
Sample outputs:
The above output identifies the kernel version that is currently running. It includes the contents of /proc/sys/kernel/ostype , /proc/sys/kernel/osrelease , and /proc/sys/kernel/version files. For example:
$ cat /proc/sys/kernel/
Sample outputs:
Find Distribution Version
Type the following command:
$ cat /etc/*release
OR
$ lsb_release -a
Sample outputs:
Here is another output from my Debian based server:
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Related media
This tutorial is also available in a quick video format:
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
How to check os version in Linux command line
Check os version in Linux
The procedure to find os name and version on Linux:
- Open the terminal application (bash shell)
- For remote server login using the ssh: ssh user@server-name
- Type any one of the following command to find os name and version in Linux:
cat /etc/os-release
lsb_release -a
hostnamectl - Type the following command to find Linux kernel version:
uname -r
Let us see all examples in details for common Linux distros.
The /etc/os-release file
Type the following cat command:
$ cat /etc/os-release
Sample outputs:
We can filter out information such as OS version and name using the grep command/egrep command as follows:
$ grep ‘^VERSION’ /etc/os-release
$ egrep ‘^(VERSION|NAME)=’ /etc/os-release
Here is what we see:
Even tiny Linux distro such as Alpine Linux provide the required OS (Operating system) information, including version:
Checking OS version on Linux using the lsb_release command
The lsb_release command gives LSB (Linux Standard Base) and distribution-specific information on the CLI. The syntax is:
$ lsb_release -a
Sample outputs:
hostnamectl command
Use hostnamectl command to query and change the system hostname and related settings. Just type the following command to check OS name and Linux kernel version:
$ hostnamectl
And it will give info as follows. Look out for “ Operating System ” and “ Kernel “:
Another outputs from my OpenSUSE Linux 15.2 server:
uname command
/etc/issue file
Use more command/less command as follows:
$ cat /etc/issue
$ more /etc/issue
$ less /etc/issue
Getting help
You can also view the manual page on uname using the following command:
$ man hostnamectl
$ man uname
$ man cat
Related media
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Conclusion
We explained how to find and display the OS version on Linux. The safest option is to query /etc/os-release file using grep or cat command. Systemd based Linux distro users can use the hostnamectl command.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
How to Check OS Version in Linux
Linux version can be checked using inbuilt commands or can read from specific files. It is important to determine the distribution name and version on many occasion like when doing package updates or OS update.
There are a lot of Linux distributions available like Debian, Ubuntu, CentOS, Mint, Arch, Fedora, RHEL, and more.
In this tutorial, I will show how to check the Linux version from the command line.
Check Linux Version
There are mainly 5 ways we can get Linux distribution name and its version.
1. From /etc/os-release
Use cat command to read the content of the file /etc/os-release , run the following command:
Output from CentOS
Output from Ubuntu
2. Using lsb_release command
The lsb_release -a displays the Linux version information from the command line. The output will display distribution ID, description, release and codename. To display only the description you can use lsb_release -d .
If you get «command not found» and then you need to install ‘lsb-core’ package.
Output of lsb_release -a
To display only the description, run:
3. Using Hostnamectl command
In modern Linux distributions which use systemd init systems, you can use hostnamectl command to display operating system version.
4. From /etc/issue file
You can get version information from /etc/issue file, to read file content use cat or less command:
5. From /etc/*release or /etc/*version
Some distribution use release and version file and those files are specific to that distro.
$ echo /etc/*version /etc/*release
/etc/debian_version /etc/ec2_version /etc/lsb-release /etc/os-release
To read the content from /etc/*release or /etc/*version, run the following command:
If you are interested to know the Linux kernel version and architecture then use uname command or you can read the content from /proc/version file.
Conclusion
In this tutorial, we learned different ways to find Linux OS name and version from I hope you enjoyed reading and please leave your suggestion in the below comment section.
Источник
Configure Linux distributions
Windows Subsystem for Linux (WSL) supports running as many different Linux distributions as you would like to install. This can include choosing distributions from the Microsoft Store, importing a custom distribution, or building your own custom distribution.
Ways to run WSL
There are several ways to run a Linux distribution with WSL once it’s installed:
- The number one way that we recommend you run Linux distributions is by installing Windows Terminal. Using Windows Terminal enables you to open multiple tabs or window panes to display and quickly switch between multiple Linux distributions or other command lines (PowerShell, Command Prompt, PowerShell, Azure CLI, etc). You can fully customize your terminal with unique color schemes, font styles, sizes, background images, and custom keyboard shortcuts. Learn more.
- You can directly open your Linux distribution by visiting the Windows Start menu and typing the name of your installed distributions. For example: «Ubuntu». This will open Ubuntu in it’s own console window.
- From Windows Command Prompt or PowerShell, you can enter the name of your installed distribution. For example: ubuntu
- From Windows Command Prompt or PowerShell, you can open your default Linux distribution inside your current command line, by entering: wsl.exe .
- From Windows Command Prompt or PowerShell, you can use your default Linux distribution inside your current command line, without entering a new one, by entering: wsl [command] . Replacing [command] with a WSL command, such as: wsl -l -v to list installed distributions or wsl pwd to see where the current directory path is mounted in wsl. From PowerShell, the command get-date will provide the date from the Windows file system and wsl date will provide the date from the Linux file system.
The method you select should depend on what you’re doing. If you’ve opened a WSL command line within a Windows Prompt or PowerShell window and want to exit, enter the command: exit .
List installed distributions
To see a list of the Linux distributions you have installed, enter: wsl —list or wsl -l -v for a verbose list. To set an installed Linux distribution as the default that is used with the wsl command, enter: wsl -s or wsl —setdefault , replacing with the name of the Linux distribution you would like to use. For example, from Powershell, enter: wsl -s Debian to set the default distribution to Debian. Now running wsl npm init from Powershell will run the npm init command in Debian.
Unregister and reinstall a distribution
While Linux distributions can be installed through the Microsoft Store, they can’t be uninstalled through the store.
To unregister and uninstall a WSL distribution:
wsl —unregister
Unregisters the distribution from WSL so it can be reinstalled or cleaned up. Caution: Once unregistered, all data, settings, and software associated with that distribution will be permanently lost. Reinstalling from the store will install a clean copy of the distribution.
For example: wsl —unregister Ubuntu would remove Ubuntu from the distributions available in WSL. Running wsl —list will reveal that it is no longer listed. To reinstall, find the distribution in the Microsoft Store and select «Launch».
Run as a specific user
wsl -u , wsl —user
Run WSL as the specified user. Please note that user must exist inside of the WSL distribution.
Change the default user for a distribution
Change the default user that for your distribution log-in. The user has to already exist inside the distribution in order to become the default user.
For example: ubuntu config —default-user johndoe would change the default user for the Ubuntu distribution to the «johndoe» user.
If you are having trouble figuring out the name of your distribution, use the command wsl -l .
Run a specific distribution
wsl -d , wsl —distribution
Run a specified distribution of WSL, can be used to send commands to a specific distribution without having to change your default.
Configure settings with .wslconfig and wsl.conf
You can configure options for your installed Linux distributions, such as automount options and network configuration, that will automatically be applied every time you launch WSL in two ways:
- Globally for all installed distributions running in WSL 2 mode with a .wslconfig file stored in your %UserProfile% directory
- On a per-distribution basis with a wsl.conf file stored in the /etc directory of the distribution
To get to your %UserProfile% directory, in PowerShell, use cd
to access your home directory (which is typically your user profile, C:\Users\ ) or you can open Windows File Explorer and enter %UserProfile% in the address bar. The directory path for globally configuring WSL options will be C:\Users\ \.wslconfig .
To get to the /etc directory for an installed distribution, use the distribution’s command line with cd / to access the root directory, then ls to list files or explorer.exe . to view in Windows File Explorer. The directory path for configuring WSL options on a per-distribution basis will be /etc/wsl.conf .
WSL will detect the existence of these files and read the contents. If the file is missing or malformed (that is, improper markup formatting), WSL will continue to launch as normal.
Adjusting per-distribution settings with the .wsl.conf file is only available in Windows Build 17093 and later.
Per distribution configuration options with wsl.conf
The wsl.conf sample file below demonstrates some of the configuration options available to add into your distributions:
When launching multiple Linux shells for the same distribution, you must wait until the Linux subsystem stops running, this can take approximately 8 seconds after closing the last instance of the distribution shell. If you launch a distribution (ie. Ubuntu), modify the wsl.conf file, close the distribution, and then re-launch it. You might assume that your changes to the wsl.conf file have immediately gone into effect. This is not currently the case as the subsystem could still be running. You must wait
8 seconds for the subsystem to stop before relaunching in order to give enough time for your changes to be picked up. You can check to see whether your Linux distribution (shell) is still running after closing it by using PowerShell with the command: wsl —list —running . If no distributions are running, you will receive the response: «There are no running distributions.» You can now restart the distribution to see your wsl.conf updates applied.
wsl —shutdown is a fast path to restarting WSL 2 distributions, but it will shut down all running distributions, so use wisely.
Options for wsl.conf
In keeping with .ini conventions, keys are declared under a section.
WSL supports four sections: automount , network , interop , and user .
automount
key | value | default | notes |
---|---|---|---|
enabled | boolean | true | true causes fixed drives (i.e C:/ or D:/ ) to be automatically mounted with DrvFs under /mnt . false means drives won’t be mounted automatically, but you could still mount them manually or via fstab . |
mountFsTab | boolean | true | true sets /etc/fstab to be processed on WSL start. /etc/fstab is a file where you can declare other filesystems, like an SMB share. Thus, you can mount these filesystems automatically in WSL on start up. |
root | String | /mnt/ | Sets the directory where fixed drives will be automatically mounted. For example, if you have a directory in WSL at /windir/ and you specify that as the root, you would expect to see your fixed drives mounted at /windir/c |
options | comma-separated list of values | empty string | This value is appended to the default DrvFs mount options string. Only DrvFs-specific options can be specified. Options that the mount binary would normally parse into a flag are not supported. If you want to explicitly specify those options, you must include every drive for which you want to do so in /etc/fstab. |
By default, WSL sets the uid and gid to the value of the default user (in Ubuntu distro, the default user is created with uid=1000,gid=1000). If the user specifies a gid or uid option explicitly via this key, the associated value will be overwritten. Otherwise, the default value will always be appended.
Note: These options are applied as the mount options for all automatically mounted drives. To change the options for a specific drive only, use /etc/fstab instead.
Mount options
Setting different mount options for Windows drives (DrvFs) can control how file permissions are calculated for Windows files. The following options are available:
Key | Description | Default |
---|---|---|
uid | The User ID used for the owner of all files | The default User ID of your WSL distro (On first installation this defaults to 1000) |
gid | The Group ID used for the owner of all files | The default group ID of your WSL distro (On first installation this defaults to 1000) |
umask | An octal mask of permissions to exclude for all files and directories | 000 |
fmask | An octal mask of permissions to exclude for all files | 000 |
dmask | An octal mask of permissions to exclude for all directories | 000 |
metadata | Whether metadata is added to Windows files to support Linux system permissions | disabled |
case | Determines directories treated as case sensitive and whether new directories created with WSL will have the flag set. See case sensitivity for a detailed explanation of the options. | off |
The permission masks are put through a logical OR operation before being applied to files or directories.
network
Section label: [network]
key | value | default | notes |
---|---|---|---|
generateHosts | boolean | true | true sets WSL to generate /etc/hosts . The hosts file contains a static map of hostnames corresponding IP address. |
generateResolvConf | boolean | true | true set WSL to generate /etc/resolv.conf . The resolv.conf contains a DNS list that are capable of resolving a given hostname to its IP address. |
interop
Section label: [interop]
These options are available in Insider Build 17713 and later.
key | value | default | notes |
---|---|---|---|
enabled | boolean | true | Setting this key will determine whether WSL will support launching Windows processes. |
appendWindowsPath | boolean | true | Setting this key will determine whether WSL will add Windows path elements to the $PATH environment variable. |
Section label: [user]
These options are available in Build 18980 and later.
key | value | default | notes |
---|---|---|---|
default | string | The initial username created on first run | Setting this key specifies which user to run as when first starting a WSL session. |
User preview options
These options are only available in the latest preview builds if you are on the latest builds of the Windows Insiders program.
Section label: [boot]
key | value | default | notes |
---|---|---|---|
command | string | «» | A string of the command that you would like to run when the WSL instance starts. This command is run as the root user. e.g: service docker start |
Global configuration options with .wslconfig
You can add a file named .wslconfig to your Windows home directory (e.g: C:\Users\crloewen\.wslconfig ) to control global WSL options across Linux distributions. Please see the sample file below as an example.
Global configuration options with .wslconfig in only available for distributions running as WSL 2 in Windows Build 19041 and later. Keep in mind you may need to run wsl —shutdown to shut down the WSL 2 VM and then restart your WSL instance for these changes to take affect.
This file can contain the following options:
Options for .wslconfig
Section label: [wsl2]
These settings affect the VM that powers any WSL 2 distribution.
key | value | default | notes |
---|---|---|---|
kernel | string | The Microsoft built kernel provided inbox | An absolute Windows path to a custom Linux kernel. |
memory | size | 50% of total memory on Windows or 8GB, whichever is less; on builds before 20175: 80% of your total memory on Windows | How much memory to assign to the WSL 2 VM. |
processors | number | The same number of processors on Windows | How many processors to assign to the WSL 2 VM. |
localhostForwarding | boolean | true | Boolean specifying if ports bound to wildcard or localhost in the WSL 2 VM should be connectable from the host via localhost:port . |
kernelCommandLine | string | Blank | Additional kernel command line arguments. |
swap | size | 25% of memory size on Windows rounded up to the nearest GB | How much swap space to add to the WSL 2 VM, 0 for no swap file. |
swapFile | string | %USERPROFILE%\AppData\Local\Temp\swap.vhdx | An absolute Windows path to the swap virtual hard disk. |
Entries with the path value must be Windows paths with escaped backslashes, e.g: C:\\Temp\\myCustomKernel
Entries with the size value must be a size followed by a unit, for example 8GB or 512MB .
WSL 2 setting preview options
These options are only available in the latest preview builds if you are on the latest builds of the Windows Insiders program.
Источник