Discover Linux System Information

ShellShellBeginner
Practice Now

Introduction

This hands-on lab will cover the basic usage of the uname, hostname, and date commands in Linux. These commands provide information about the system, hostname and current date and time respectively.

Achievements

  • uname - Display system kernel information
  • hostname - Display or set the system's host name
  • date - Display or set the system date and time

Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"]) shell(("`Shell`")) -.-> shell/BasicSyntaxandStructureGroup(["`Basic Syntax and Structure`"]) shell(("`Shell`")) -.-> shell/VariableHandlingGroup(["`Variable Handling`"]) shell(("`Shell`")) -.-> shell/AdvancedScriptingConceptsGroup(["`Advanced Scripting Concepts`"]) linux/SystemInformationandMonitoringGroup -.-> linux/date("`Date/Time Displaying`") linux/SystemInformationandMonitoringGroup -.-> linux/uname("`System Information Displaying`") linux/SystemInformationandMonitoringGroup -.-> linux/hostname("`Hostname Managing`") shell/BasicSyntaxandStructureGroup -.-> shell/comments("`Comments`") shell/BasicSyntaxandStructureGroup -.-> shell/quoting("`Quoting Mechanisms`") shell/VariableHandlingGroup -.-> shell/variables_decl("`Variable Declaration`") shell/AdvancedScriptingConceptsGroup -.-> shell/arith_ops("`Arithmetic Operations`") subgraph Lab Skills linux/date -.-> lab-36{{"`Discover Linux System Information`"}} linux/uname -.-> lab-36{{"`Discover Linux System Information`"}} linux/hostname -.-> lab-36{{"`Discover Linux System Information`"}} shell/comments -.-> lab-36{{"`Discover Linux System Information`"}} shell/quoting -.-> lab-36{{"`Discover Linux System Information`"}} shell/variables_decl -.-> lab-36{{"`Discover Linux System Information`"}} shell/arith_ops -.-> lab-36{{"`Discover Linux System Information`"}} end

Display System Information with uname

The uname command is used to display information about the current system.

## Display all information
uname -a

This will display all information such as the operating system name, kernel version and build date...

Display Hostname with hostname

The hostname command is used to display the hostname of the current system.

hostname

This will display the hostname of the current system.

Display Current Date and Time with date

The date command is used to display the current date and time.

date

This will display the current date and time.

Formatting the Date and Time

You can use the -d or --date option to specify a custom date and time to display.

date --date="2022-12-25 12:00:00"

You can also use the + option to specify a custom format for the output.

date +"%Y-%m-%d %H:%M:%S"

The date format option, +, allows you to specify a custom format for the output of the date command. There are a variety of formatting options available to use with the + option. Some common options include:

  • %Y - four-digit year (e.g. 2022)
  • %m - two-digit month (e.g. 05 for May)
  • %d - two-digit day of the month (e.g. 09)
  • %H - two-digit hour (24-hour clock) (e.g. 16 for 4pm)
  • %M - two-digit minute (e.g. 32)
  • %S - two-digit second (e.g. 45)
  • %A - weekday name (e.g. Monday)
  • %B - month name (e.g. January)

You can use any combination of these options to create a custom date format. Here are some examples of how to use the + option:

date +"%A %B %d, %Y"
date +"%H:%M:%S %Z"
## Output
Monday May 09, 2023
16:32:45 UTC

Summary

In this lab, we have learned how to use the uname, hostname, and date commands in Linux to display system information, hostname, and current date and time respectively. We also learned how to specify a custom date and time and format the output of the date command. These commands are essential tools for any Linux user and administrator.

Other Shell Tutorials you may like