Linux System Information Displaying

LinuxLinuxBeginner
Practice Now

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.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux(("Linux")) -.-> linux/FileandDirectoryManagementGroup(["File and Directory Management"]) linux(("Linux")) -.-> linux/SystemInformationandMonitoringGroup(["System Information and Monitoring"]) linux(("Linux")) -.-> linux/VersionControlandTextEditorsGroup(["Version Control and Text Editors"]) linux/BasicFileOperationsGroup -.-> linux/chmod("Permission Modifying") linux/FileandDirectoryManagementGroup -.-> linux/cd("Directory Changing") linux/FileandDirectoryManagementGroup -.-> linux/pwd("Directory Displaying") linux/SystemInformationandMonitoringGroup -.-> linux/uname("System Information Displaying") linux/VersionControlandTextEditorsGroup -.-> linux/nano("Simple Text Editing") subgraph Lab Skills linux/chmod -.-> lab-271415{{"Linux System Information Displaying"}} linux/cd -.-> lab-271415{{"Linux System Information Displaying"}} linux/pwd -.-> lab-271415{{"Linux System Information Displaying"}} linux/uname -.-> lab-271415{{"Linux System Information Displaying"}} linux/nano -.-> lab-271415{{"Linux System Information Displaying"}} end

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

  1. Open your terminal. You should be in the default directory /home/labex/project.

  2. To ensure you're in the correct directory, run:

    pwd

    This should display:

    /home/labex/project
  3. If you're not in the correct directory, run:

    cd ~/project
  4. Now, run the uname command with the -a option to display all system information:

    uname -a

    The -a option stands for "all" and it displays all available system information at once.

  5. 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-Ubuntu is the kernel version
  • x86_64 refers to the machine hardware architecture
  • GNU/Linux is 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:

  1. First, ensure you're in the project directory:

    cd ~/project
  2. To display only the kernel name, use the -s option:

    uname -s

    The output should be:

    Linux
  3. To display the kernel release, use the -r option:

    uname -r

    The output will look similar to:

    5.15.0-86-generic
  4. To display the machine hardware name (architecture), use the -m option:

    uname -m

    The output should be:

    x86_64
  5. To display the operating system, use the -o option:

    uname -o

    The output should be:

    GNU/Linux
  6. To display the processor type, use the -p option:

    uname -p

    The 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

  1. Make sure you're in the project directory:

    cd ~/project
  2. Create a new file named system_info.sh using the nano text editor:

    nano system_info.sh
  3. In 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 "=================================="
  4. Save the file by pressing Ctrl+O, then Enter, and exit nano by pressing Ctrl+X.

  5. Make the script executable by changing its permissions:

    chmod +x system_info.sh

    The chmod +x command adds execute permission to the file, allowing it to be run as a program.

  6. Run the script:

    ./system_info.sh

    The ./ prefix tells the shell to run the script from the current directory.

  7. 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:

  1. Using uname -a to display all system information at once, including kernel name, release, version, and hardware details.

  2. Using specific options with uname to extract particular pieces of information:

    • -s for kernel name
    • -r for kernel release
    • -m for machine hardware name
    • -o for operating system
  3. 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.