How to use the command 'uname' (with examples)

How to use the command 'uname' (with examples)

The ‘uname’ command is used to display information about the current machine and the operating system running on it. It can provide details such as the kernel name, system architecture, processor information, kernel release, kernel version, system hostname, and much more.

Use case 1: Print kernel name

Code:

uname

Motivation: This use case is useful when you simply want to know the name of the kernel running on your system.

Explanation: By running the command ‘uname’ without any arguments, it prints the kernel name.

Example output:

Linux

Use case 2: Print system architecture and processor information

Code:

uname --machine --processor

Motivation: This use case is helpful when you need to determine the architecture and processor information of your system.

Explanation: The ‘–machine’ option displays the system architecture, while the ‘–processor’ option shows the processor information.

Example output:

x86_64 x86_64

Use case 3: Print kernel name, kernel release, and kernel version

Code:

uname --kernel-name --kernel-release --kernel-version

Motivation: This use case is handy when you want to obtain more detailed information about the kernel, such as its name, release, and version.

Explanation: The ‘–kernel-name’ option prints the kernel name, the ‘–kernel-release’ option displays the kernel release, and the ‘–kernel-version’ option shows the kernel version.

Example output:

Linux 4.19.0-14-amd64 #1 SMP Debian 4.19.171-2 (2021-01-30)

Use case 4: Print system hostname

Code:

uname --nodename

Motivation: This use case is useful if you want to find out the hostname of your system.

Explanation: The ‘–nodename’ option prints the system hostname.

Example output:

my-machine

Use case 5: Print all available system information

Code:

uname --all

Motivation: This use case provides comprehensive information about the system and can be helpful when you need to gather detailed system information.

Explanation: The ‘–all’ option fetches and prints all the available system information.

Example output:

Linux my-machine 4.19.0-14-amd64 #1 SMP Debian 4.19.171-2 (2021-01-30) x86_64 GNU/Linux

Conclusion:

The ‘uname’ command is a versatile tool that provides essential information about the current machine and operating system. It can be used for various purposes, from determining the kernel name to obtaining comprehensive system information. By utilizing the different options available, you can extract specific details that are relevant to your needs.

Related Posts

How to use the command '[' (with examples)

How to use the command '[' (with examples)

The command ‘[’ is used for testing conditions in shell scripts.

Read More
How to use the command 'mosquitto' (with examples)

How to use the command 'mosquitto' (with examples)

Mosquitto is an MQTT (Message Queuing Telemetry Transport) broker that enables the communication between devices using the MQTT protocol.

Read More
Shell Command "read" (with examples)

Shell Command "read" (with examples)

The read command is a shell builtin that allows you to retrieve data from stdin, which is usually input from the keyboard.

Read More