Home › Linux command line: first steps › Step 4
Lesson 4: date and hwclock - setting the hardware clock
Step 4 of 5 in Linux command line: first steps · video 7:23
What you will learn
- Showing UTC and custom formats with date -u and date +FORMAT
- Setting the system clock with date -s as root
- Where hwclock records UTC or local time: /etc/adjtime
- Syncing clocks in either direction with --systohc and --hctosys
About this lesson
The two traditional clock tools that sit alongside timedatectl. date prints the day, date, local time, time zone abbreviation and year; -u or --utc shows UTC instead, and a + format string such as +%Y-%m-%d_%H:%M produces custom output, which is why date is so common in scripts. As root, date -s (--set) changes the system clock, and setting only a date resets the time to midnight. hwclock reads and sets the hardware clock (RTC), which stores year, month, day, hour, minute and second but not whether that value is UTC or local time. That choice is recorded in /etc/adjtime, created the first time you set or synchronise the clock. The lesson shows hwclock --set --date to set the RTC directly, --systohc to copy the system time into it and --hctosys to load the system time from it, with --utc or --localtime to fix the standard. As with timedatectl, keeping the hardware clock in UTC is recommended.
Check yourself
1. Which command prints the current time in UTC rather than local time?
date -u (or date --utc). By default date shows local time, and this option switches the output to Coordinated Universal Time.
2. A backup script needs a timestamp like 2026-09-29_14:05 in the archive name. Which command produces it?
date +%Y-%m-%d_%H:%M. The + introduces a format string in which %Y, %m, %d, %H and %M stand for year, month, day, hour and minute, and anything else is printed as written.
3. What time does the system clock show after you run date -s 2026-10-01 as root?
Midnight, 00:00:00 on 1 October. When only a date is given, the time part is not kept, so it is set to the start of that day; add a time, as in date -s '2026-10-01 09:30', to avoid this.
4. You corrected the system time by hand and want the hardware clock to match it, keeping the RTC in UTC. What do you run?
hwclock --systohc --utc as root. --systohc copies the system time into the hardware clock, and --utc records in /etc/adjtime that the RTC holds UTC; --hctosys works in the other direction.
Go deeper
This lesson comes from the course below - with the full set of lessons, demonstrations and practice.