Linux-Ubuntu/C2/Date-and-Time-Commands/English

From Script | Spoken-Tutorial
Jump to: navigation, search

Title of the script: Date and Time commands

Authors: EduPyramids Team

Keywords: date, cal, ncal, Linux, time, calendar, sudo, man, video tutorial.

Prerequisite Tutorial: Basic Commands in Linux


Visual Cue Narration
Slide 1

Title Slide

Welcome to the Spoken tutorial on Date and Time Commands in Linux.
Slide 2

Learning Objectives

In this tutorial we will learn to,
  • Use Linux commands to display the system date and time
  • Use date command options
  • Install ncal package
  • View calendars using cal command
Slide 3

System Requirements

To record this tutorial, I am using

Ubuntu OS version 24.04 and

A working internet connection.

Slide 4

Pre-requisites

https://EduPyramids.org

To follow this tutorial,

Learners should know the basics of using the Linux terminal.

For the prerequisite Linux tutorials please visit this website.

Slide 5

Code files

The following code file is required to practice this tutorial

1. dc-commands.txt

This file is provided in the Code Files link of this tutorial page

The following code file is required to practice this tutorial.

This file is provided in the Code Files link of this tutorial page.

Let us get started.
Screencast:

Press Ctrl, Alt and T keys on your keyboard

Open the terminal by pressing Ctrl, Alt, and T keys.
Let us check the current system date and time.

For this, we use the date command with arguments.

Type date press Enter To view the current system date and time,

type date command and press Enter.

It will display the day, date, month, year, time and time zone.

Point to the output. The date command is very versatile and offers many options.
Type at the prompt

date +%T

Type at the prompt

date space plus percent capital T press Enter.

Point to the output.

hh:mm:ss format.

Time in hours, minutes and seconds format is displayed.
Let us see a few more examples using the date command.
Type at the prompt

date +%h press Enter.

Point to the output.

Type date space plus percent h and press Enter.

The name of the month is displayed.

Type at the prompt

date +%m

Similarly, type

date space plus percent m

It shows month of the current year.

Type at the prompt

date +%y

Now type date space plus percent y it shows the last two digits of the current year.
Type at the prompt

date +%h%y

We can combine these options as well.

Type date space plus percent h percent y and press Enter.

The output shows Jan twenty six.

Type man date Press Enter.

Scroll up to see the commands.

Press q

Let us learn more about the date command and its options.

Type man space date and press Enter.

This opens the manual page for the date command.

Press q to exit the manual.

Type at the prompt

cal

Another related command is the cal command.

Though less commonly used, it displays the calendar of the current month.

Type cal and press Enter.

Command 'cal' not found, but can be installed with: sudo apt install ncal In some Ubuntu systems, the cal' command is part of the ncal package'Bold text.

If the cal command is not found, we need to install ncal.

The ncal package is used to display calendars on the terminal in Linux systems.

Type: sudo apt install ncal Let us install ncal.

Type the command sudo apt install ncal

and press Enter.

If prompted enter the system password and press Enter.

Installation may take some time.

Type: cal press Enter Now type cal and press Enter.

Here it displays the calendar for the current month and year.

Type at the prompt

cal 12 2070

Similarly if we want the calendar for a specific month, say for December 2070.

Then we will type cal 12 2070.

Show the output. This gives the calendar of December 2070.
Only Narration

man date

Users can explore the options in the date command using the man date command.
Slide 6

Summary

In this tutorial we have learnt to:

  • Use Linux commands to display the system date and time
  • Use date command options
  • Install ncal package
  • View calendars using cal command
With this we come to the end of this tutorial.

Let us summarise.

Slide 7

Assignment

As an assignment,

Open the terminal: Ctrl+Alt+T keys.

  • Type date +%R, press Enter.
  • Type date +%U, press Enter.
  • Type date +%j, press Enter.
  • Type date +%q, press Enter.
  • Type cal 06 2035, press Enter.
As an assignment, please do the following.
Slide 8

Thank you

This Spoken Tutorial is brought to you by EduPyramids Educational Services Private Limited, SINE, IIT Bombay.

Thank you.

Contributors and Content Editors

Ketkinaina, Madhurig