BLOG POSTS
    MangoHost Blog / How to use linux command to get basic information about the OS – uname
How to use linux command to get basic information about the OS – uname

How to use linux command to get basic information about the OS – uname

uname is a Linux command that is used to get basic information about the operating system. It stands for “Unix Name” and is commonly used to retrieve information such as the kernel version, machine hardware name, operating system name, and more. The uname command is a part of the GNU core utilities package and is available on most Linux distributions.

The uname command is primarily used for system administration purposes, as it provides important information about the system that can be used for troubleshooting, compatibility checks, and system monitoring. It can also be used by developers to determine the capabilities of the system and adjust their software accordingly.

Official page of uname: https://man7.org/linux/man-pages/man1/uname.1.html

The uname command is written in C programming language and is a part of the GNU core utilities package, which is written in C as well.

Installation on Supported Operating Systems

The uname command is typically pre-installed on most Linux distributions, so you don’t need to install it separately. However, if for some reason it is not available on your system, you can install it using the package manager specific to your distribution.

Debian/Ubuntu

sudo apt-get install coreutils

Red Hat/Fedora

sudo dnf install coreutils

CentOS

sudo yum install coreutils

Usage and Examples

The uname command can be used with various options to retrieve different information about the system. Here are some commonly used options:

Display the Kernel Version

uname -r

This command will display the kernel version of the operating system.

Display the Machine Hardware Name

uname -m

This command will display the machine hardware name of the system.

Display the Operating System Name

uname -o

This command will display the operating system name of the system.

Display All Information

uname -a

This command will display all available information about the system, including the kernel version, machine hardware name, operating system name, and more.

Similar Commands and Benefits

There are several other commands and tools available on Linux that provide similar functionality to uname. Some of them include:

lsb_release

The lsb_release command is used to display information about the Linux Standard Base (LSB) and the distribution-specific information. It provides detailed information about the distribution, release version, and more.

cat /etc/os-release

This command is used to display information about the operating system release. It reads the contents of the /etc/os-release file, which contains information such as the distribution name, version, and ID.

hostnamectl

The hostnamectl command is used to query and change the system hostname and related settings. It provides information about the operating system, kernel version, and more.

Script Examples

Here are three script examples that demonstrate the usage of the uname command in automation:

Script 1: Display Kernel Version

#!/bin/bash
kernel_version=$(uname -r)
echo "Kernel Version: $kernel_version"

Script 2: Check Operating System Name

#!/bin/bash
os_name=$(uname -o)
if [[ $os_name == "GNU/Linux" ]]; then
    echo "This is a Linux operating system."
else
    echo "This is not a Linux operating system."
fi

Script 3: Check Machine Hardware Name

#!/bin/bash
hardware_name=$(uname -m)
if [[ $hardware_name == "x86_64" ]]; then
    echo "This is a 64-bit machine."
else
    echo "This is a 32-bit machine."
fi

List of Possible Functions and Constants

Function/Constant Description
uname() Function to retrieve system information
UTS_SYSNAME Constant representing the operating system name
UTS_NODENAME Constant representing the network node hostname
UTS_RELEASE Constant representing the operating system release version
UTS_VERSION Constant representing the operating system version
UTS_MACHINE Constant representing the machine hardware name
UTS_DOMAINNAME Constant representing the network domain name

Conclusion

The uname command is a useful tool for retrieving basic information about the operating system. It is commonly used by system administrators and developers for troubleshooting, compatibility checks, and system monitoring. The command provides information such as the kernel version, machine hardware name, operating system name, and more. It can be used in automation scripts to perform various tasks based on the system information. Overall, the uname command is an essential tool for anyone working with Linux systems.



This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.

This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.

Leave a reply

Your email address will not be published. Required fields are marked