- So to manage time on Linux,
there are three tools that matter.
There is date.
Date is what allows you to check time
in time display format.
You can even set it,
but setting time with date is not really convenient.
I would advise against it.
There's hwclock,
which allows you to manipulate the hardware time
and synchronize the hardware time to the system time.
And there's timedatectl.
Timedatectl is a relatively new utility
that allows you to manage time related properties.
Let me show you.
So, let me start by typing date.
Here we go.
Date is printing the date.
Now you can use date with specific formats.
So if you want date + %d-% m-%,
uppercase Y for instance.
Then you see day, month, year in four digit format.
This is, by the way, convenient because I like using
something like this in backup commands,
as in, sudo tar cvf;
and then we create a file, right?
And I create the file.
Let's call it "TMP backup-"
and then the command substitution.
Remember if you put it between a dollar and braces
and you use the result of a command
in the actual command you are running.
And this would mean that we create a file
with the name backup dash date
of the date, .tar, of the etc directory or whatever.
That's one convenient way of doing it.
So, ls-l on /tmp/backup, whatever.
There you can see the backup file was created.
And just imagine that you can use this from a script.
If you put this simple command
in a script that you can schedule it with Chrome,
which we will talk about shortly.
And you make sure that every single day you create a backup
of your system.
Isn't that cool?
Let's have a look at hwclock, not just hwclock.
Well, that's showing the hardware clock.
So sudo hwclock is doing what?
There we go.
We need sudo privileges.
The hardware clock and the system clock,
as you have seen in the video,
are not always the same.
And the thing is if your hardware clock is off,
when your system boots, it takes it's time
from the hardware clock.
So every now and then you might have to do a synchronize.
So, sudo hwclock --help.
And there we can see the different options.
If I am going to use systohhc,
that is how we synchronize the hardware clock
with the system time.
And that is useful if your hardware clock is off.
So for the rest of it don't use this command too much,
but go and use timedatectl.
Timedatectl is this new command.
And in this new command, we even have tap completion.
And what else can you do?
Well, you can use show
and there you can see all the different properties,
including the time zone that we are in
and whether or not we are using NTP.
And the time that it is actually right now.
So let's manipulate time zones.
So sudo time, timedatectl set.
Well before set let's do a list time zones.
There you go.
I wanna be in Africa, Banjul.
You know where that is?
In The Gambia, of course.
So let's go to Africa, Banjul.
In order to go there,
Africa/Banjul, we make that a set time zone.
And
there we go.
And what is the result?
Well, the result is what we are going to see
with timedatectl show.
As you can see, I'm an Africa, Banjul
and in Africa, Banjul it's 22:51.
I don't like it to be 22:51.
So let's get back to America, Los Angeles.
But before doing that, we do need to check the format.
So list time zones, and there we go, America.
And where is it?
This is what I wanted to know: Los_Angeles.
So, set timezone, America,
Los Angeles
and there we go.
And even date is reflecting.
Date is reflecting what?
2:52 PM PST.
That's a standard format in the date command.
I think this is about what you need to know
about date and hwclock and timedatectl.
There are many more things that you can do with it
but these are not the most common thing.
So I wouldn't focus on that too much.
This is what you need to know
to make sure that your system is showing the right time.