Instructor: Hey boys and girls,
in this video we are going
to cover the new system utility command
and that is timedatectl, all one word.
Or you could be pronounced as time date control command.
The command is a new utility for RHEL,
which is Red Hat Enterprise Level
and CentOS7 or 8 based distributions
which comes as a part of systemd system or service manager.
It is a replacement of old traditional date command,
which we learn earlier.
So, date command and the timedatectl command
both exist right now in the systems
but eventually, in the later version,
it will be completely replaced with timedatectl command.
So, it's better that we start learning from today.
The timedatectl command will query or show/change your date,
time, and time zones of your system clock.
It synchronizes the time with NTP server as well.
So, you could either use chronyd,
which is a daemon that you need
to have your clock synchronize,
or the older daemon which is for the ntpd.
You could use either of the service
and then in the timedatectl with the different options,
you could set to as yes so it will look it up
to these two daemons.
Or you can use a newer daemon
which is systemd-timesyncd daemon to synchronize time
which is a replacement of ntpd and chronyd.
So, you have to, of course, have to have that new daemon.
This new daemon is a very lightweight.
It doesn't offer a lot of different features
that chronyd or ntpd had to offer.
But it does the work.
So, one thing you need to keep in mind
and please note, please remember, the CentOS and Redhat,
neither one of them does not provide this daemon
in a standard repo.
Meaning if you download it
or install CentOS or Redhat with GUI,
you will not see that systemd-timesyncd daemon
in your packages.
You will have to download it separately.
So, in this video we are not gonna go
and download the systemd-timesyncd daemon.
We will just cover the timedatectl command
and we will see how we could use that command
to synchronize with our chronyd.
All right, so let's do some lab exercise
and run this command in our Linux environment.
So, the very first thing we have to do
is to check the time status.
We have to run the command timedatectl.
You could run just by itself
or the command followed by status.
So, I have my Linux machine open.
By the way, I have both machines, Red Hat 8 and CentOS7.
So, I have both versions.
So, this one is CentOS7.
So, I could run the command timedatectl
and it will give you that information.
Local time, universal time, RTC time, time zone.
Is NTP enabled?
Yes.
Is NTP synchronized?
No.
So, DST active time, next DST.
It gives you all bunch of information.
If you do the same thing with our version eight,
datetimectl, sorry, timedatectl.
Okay, it gives you a local time, universal time, time zone.
System clock synchronized, no.
NTP service active.
No, it's inactive.
So, why it is inactive, we'll figure it out as we move on.
So, right now, let's move on.
And then the next command
to view all available time zones
that you have in the system.
You could just simply do timedatectl list-timezones
and it will give you all the time zone.
You just have to hit the space bar and it will keep going.
And if you wanted to get out, just simply hit Q.
Same thing with our version eight.
Timedatectl list-timezones
and it give you all the time zones.
Then next thing is if you wanted
to set the time zone a differently.
So, right now my time zone is set to,
let's check again, is set to America and New York.
That's where I am, that's where I live.
So, my time zone is set perfectly.
If you wanted to change it
or if you see you have a wrong time zone,
you could set it by simply running this command,
timedatectl set-timezone
and then put double quote America/New_York.
If you do not know the right spelling
or exact spelling of your time zone,
again you could run the command timedatectl list-timezones.
Our next one is if you wanted to set the time
or change the time,
you could just simply run timedatectl set-time
and then year, month, and date.
And this is for if you only wanted to set the date.
If you remember in the previous command,
in the date you will use the command date
where the -s option which is to set the time or the date.
To set the date and the time together,
you have to run the command, the same command set-time
and give it the entire parameters
which is the year, month, day.
And then if you are using, if you're doing 24-hour format,
then you have to specify the 24-hours format hour
then the minute and then the second.
Then to start automatic time synchronizing
with a remote NTP server, you have to set the NTP true
and then you have to check the status.
So, let's go right now and see if you have NTP set.
So, right here it says NTP enabled, yes,
but NTP is not synchronized.
It means maybe our chronyd is not running.
But first we need to find out
whether we have chronyd or ntpd running.
So, for that we have to do systemctl status ntpd.
And you run it and it says ntpd.service could not be found.
Okay, it means it's not installed and not running.
Now let's try chronyd
and we'll see yes it is installed,
however it, okay, it is installed
and it is active and it is running.
So, what we have to do is let's restart it
so it gets synchronized with our timedate command.
And it says NTP synchronized.
It says yes, sorry, no.
So, how do we have to make it synchronized?
We could try timedatectl set-ntp true.
Okay, now let's run the timedatectl command
without status or with status, doesn't matter.
And there it is.
You see NTP is now synchronized
because we have enabled it and set it to true.
So, now it's looking for that time with chronyd.
Similarly, if you go to our version eight,
timedatectl, this command or status,
both same commands, it doesn't really matter.
Let's clear the screen to, okay,
now you see system clock synchronized, no.
So, we will do is before we synchronize,
we have to make sure chronyd or ntpd service,
either one is running.
So, we'll check systemctl status, first, ntpd.
Okay, the service is not, they are not even installed.
Okay, let's check chronyd.
Okay, it is inactive, okay, it is installed,
however it is inactive.
So, first of all what we will do is we will enable it
so it could start at boot time
and then we could start that chronyd.
Okay, now it is started.
Let's run timedate command to see
if it automatically synchronized to it.
Okay, it says system clock synchronized.
However, the NTP service status is, oh, it is active.
Beautiful.
If you don't see this active,
then what do you have to do?
Simply run that command timedatectl set-ntp to true
and then you do timedatectl
and it should show here.
Yes and active.
I'll see you in the next lecture.