Introduction
In this lab, you will learn how to use Linux commands to display system information. Understanding your system's details is crucial for system administration, troubleshooting, and ensuring compatibility with software applications.
The uname command is a powerful utility in Linux that provides essential information about the operating system and hardware platform. By mastering this command and its various options, you will be able to retrieve specific system details efficiently.
This lab guides you through using the uname command to gather system information and create a simple shell script to display this information in a structured format.
Understanding Basic System Information with uname
The uname command in Linux provides basic information about your operating system and hardware. This information helps in identifying the system environment, which is useful for troubleshooting and administrative tasks.
In this step, you will learn how to use the basic uname command to display all system information in one go.
Exploring the uname Command
Open your terminal. You should be in the default directory
/home/labex/project.To ensure you're in the correct directory, run:
pwdThis should display:
/home/labex/projectIf you're not in the correct directory, run:
cd ~/projectNow, run the
unamecommand with the-aoption to display all system information:uname -aThe
-aoption stands for "all" and it displays all available system information at once.You should see output similar to this:
Linux ubuntu 5.15.0-86-generic #96-Ubuntu SMP Wed Sep 20 08:23:40 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Let's understand this output:
- The first part (
Linux) is the kernel name - The second part (
ubuntu) is the network node hostname - The third part (
5.15.0-86-generic) is the kernel release - The part after
#96-Ubuntuis the kernel version x86_64refers to the machine hardware architectureGNU/Linuxis the operating system
This information provides a comprehensive overview of your system's basic details.
Retrieving Specific System Information
In the previous step, you learned how to display all system information using uname -a. However, often you'll need specific pieces of information rather than the entire output. The uname command provides various options to display specific system details.
Common uname Options
Let's explore the most commonly used options for the uname command:
First, ensure you're in the project directory:
cd ~/projectTo display only the kernel name, use the
-soption:uname -sThe output should be:
LinuxTo display the kernel release, use the
-roption:uname -rThe output will look similar to:
5.15.0-86-genericTo display the machine hardware name (architecture), use the
-moption:uname -mThe output should be:
x86_64To display the operating system, use the
-ooption:uname -oThe output should be:
GNU/LinuxTo display the processor type, use the
-poption:uname -pThe output may vary depending on your system, but it could show:
x86_64
These options allow you to extract specific information which is often more useful than parsing through the entire output of uname -a. You can tailor your command to show exactly what you need to know about your system.
Creating a System Information Script
Now that you understand how to use the uname command with different options, let's create a shell script that will display system information in a more organized and readable format.
A shell script is a text file containing a series of commands that can be executed together. This is useful for automating repetitive tasks or combining multiple commands.
Creating the Script
Make sure you're in the project directory:
cd ~/projectCreate a new file named
system_info.shusing the nano text editor:nano system_info.shIn the nano editor, type or paste the following content:
#!/bin/bash ## Display system information echo "======= System Information =======" echo "Kernel Name: $(uname -s)" echo "Kernel Release: $(uname -r)" echo "Machine Hardware: $(uname -m)" echo "Operating System: $(uname -o)" echo "=================================="Save the file by pressing
Ctrl+O, thenEnter, and exit nano by pressingCtrl+X.Make the script executable by changing its permissions:
chmod +x system_info.shThe
chmod +xcommand adds execute permission to the file, allowing it to be run as a program.Run the script:
./system_info.shThe
./prefix tells the shell to run the script from the current directory.You should see output similar to this:
======= System Information ======= Kernel Name: Linux Kernel Release: 5.15.0-86-generic Machine Hardware: x86_64 Operating System: GNU/Linux ==================================
This script combines several uname commands and formats the output to be more readable. The $() syntax is called command substitution - it runs the command inside the parentheses and substitutes its output.
You now have a reusable script that can quickly display important system information in a clear format. This script can be extended with additional commands to gather more system details as needed.
Summary
In this lab, you learned how to use the uname command to display system information in Linux. The key takeaways from this lab include:
Using
uname -ato display all system information at once, including kernel name, release, version, and hardware details.Using specific options with
unameto extract particular pieces of information:-sfor kernel name-rfor kernel release-mfor machine hardware name-ofor operating system
Creating a shell script to display system information in a more organized and readable format.
These skills are fundamental for Linux system administration and will help you in tasks such as system troubleshooting, compatibility checking, and system monitoring.
The ability to quickly gather system information is an essential skill for anyone working with Linux systems. Whether you're a system administrator, developer, or IT professional, understanding your system's configuration is crucial for effective problem-solving and system management.



