Linux · Lesson

Linux · Lesson

Date and Time Commands in Linux

Add the YouTube embed URL for this lesson in components/linux/linuxLessons.js.

Why date and time management matters

Correct system date and time settings are extremely important in Linux environments. Logs, scheduled jobs, authentication and distributed applications all depend on accurate time settings.

Linux provides several utilities such as date, cal and timedatectl for managing system time and timezone configuration.

Core date and time concepts

System time

Linux maintains system time used by applications, logs, scheduled tasks and services.

Calendar utilities

Commands like cal help administrators quickly view monthly and yearly calendars.

Timezones

Linux supports multiple global timezones and allows administrators to switch between them.

Step-by-step Linux date and time commands

Practice the following commands in your Linux lab to understand how date, time and timezone management works.

1. Check current date and time

The date command displays the current system date, time and timezone.

terminal — bash
linux-lab
[root@localhost ~]# date
Thu Dec 19 04:51:11 PM IST 2024
[root@localhost ~]#

2. Print current month's calendar

The cal command shows the calendar for the current month.

terminal — bash
linux-lab
[root@localhost ~]# cal
December 2024
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
 
[root@localhost ~]#

3. Display calendar for a specific year

You can print the full calendar for any year using cal <year>.

terminal — bash
linux-lab
[root@localhost ~]# cal 2026
 
2026
 
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 6 7
 
[root@localhost ~]#

4. Display calendar for a specific month

Use cal with a month name to display that month’s calendar.

terminal — bash
linux-lab
[root@localhost ~]# cal March
 
March 2024
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
 
[root@localhost ~]#

5. Display current time only

Use formatting options with date to print only the time.

terminal — bash
linux-lab
[root@localhost ~]# date +%H:%M:%S
16:58:30
[root@localhost ~]#

6. Display current month name

The +%B format option prints the full month name.

terminal — bash
linux-lab
[root@localhost ~]# date +%B
December
[root@localhost ~]#

7. Display current day name

The +%A format option prints the current weekday name.

terminal — bash
linux-lab
[root@localhost ~]# date +%A
Thursday
[root@localhost ~]#

8. Display timezone offset

The +%z option shows the current timezone offset from UTC.

terminal — bash
linux-lab
[root@localhost ~]# date +%z
+0530
[root@localhost ~]#

9. Set system date and time

Root users can manually update the system date and time.

terminal — bash
linux-lab
[root@localhost ~]# date -s "2024-12-19 17:20:00"
Thu Dec 19 05:20:00 PM IST 2024
[root@localhost ~]#

10. Check detailed time configuration

timedatectl provides detailed information about system time and timezone settings.

terminal — bash
linux-lab
[root@localhost ~]# timedatectl
 
Local time: Thu 2024-12-19 17:20:59 IST
Universal time: Thu 2024-12-19 11:50:59 UTC
RTC time: Thu 2024-12-19 11:51:04
Time zone: Asia/Kolkata (IST, +0530)
System clock synchronized: no
NTP service: active
RTC in local TZ: no
 
[root@localhost ~]#

11. Set a new timezone

Use timedatectl set-timezone to configure a different system timezone.

terminal — bash
linux-lab
[root@localhost ~]# timedatectl set-timezone Asia/Kolkata
 
[root@localhost ~]# timedatectl
 
Local time: Thu 2024-12-19 17:35:45 IST
Time zone: Asia/Kolkata (IST, +0530)
 
[root@localhost ~]#

Important command categories

Date and calendar commands

  • date → display or modify system date and time
  • cal → display monthly calendar
  • cal <year> → display yearly calendar
  • date +FORMAT → customize output formatting

Timezone management

  • timedatectl → display detailed time settings
  • timedatectl list-timezones → list all available timezones
  • timedatectl set-timezone → configure timezone
  • timedatectl status → verify synchronization status

Good administration practices

Time synchronization

  • Enable NTP synchronization on production systems.
  • Verify timezone settings after installing Linux.
  • Keep system clocks synchronized across servers.

Operational safety

  • Avoid changing system time unnecessarily on active servers.
  • Incorrect time settings can break logs and authentication.
  • Use timedatectl instead of manually editing configuration files.

Practice tasks for your Linux lab

  • Run date and verify your current timezone.
  • Display the calendar for your birth year using cal YEAR.
  • Print only the current month name using date +%B.
  • List all available timezones using timedatectl list-timezones.
  • Change the timezone temporarily and verify the update using timedatectl.

In upcoming lessons, you will continue learning important Linux administration commands and system-management tools.