1 00:00:06,780 --> 00:00:08,280 - So to manage time on Linux, 2 00:00:08,280 --> 00:00:10,140 there are three tools that matter. 3 00:00:10,140 --> 00:00:11,400 There is date. 4 00:00:11,400 --> 00:00:13,590 Date is what allows you to check time 5 00:00:13,590 --> 00:00:16,170 in time display format. 6 00:00:16,170 --> 00:00:17,400 You can even set it, 7 00:00:17,400 --> 00:00:19,740 but setting time with date is not really convenient. 8 00:00:19,740 --> 00:00:21,600 I would advise against it. 9 00:00:21,600 --> 00:00:22,770 There's hwclock, 10 00:00:22,770 --> 00:00:25,320 which allows you to manipulate the hardware time 11 00:00:25,320 --> 00:00:29,820 and synchronize the hardware time to the system time. 12 00:00:29,820 --> 00:00:31,300 And there's timedatectl. 13 00:00:31,300 --> 00:00:34,320 Timedatectl is a relatively new utility 14 00:00:34,320 --> 00:00:37,260 that allows you to manage time related properties. 15 00:00:37,260 --> 00:00:38,093 Let me show you. 16 00:00:41,400 --> 00:00:43,650 So, let me start by typing date. 17 00:00:43,650 --> 00:00:45,030 Here we go. 18 00:00:45,030 --> 00:00:46,893 Date is printing the date. 19 00:00:47,790 --> 00:00:50,190 Now you can use date with specific formats. 20 00:00:50,190 --> 00:00:55,190 So if you want date + %d-% m-%, 21 00:00:56,310 --> 00:00:57,840 uppercase Y for instance. 22 00:00:57,840 --> 00:01:02,840 Then you see day, month, year in four digit format. 23 00:01:03,150 --> 00:01:05,970 This is, by the way, convenient because I like using 24 00:01:05,970 --> 00:01:08,340 something like this in backup commands, 25 00:01:08,340 --> 00:01:12,450 as in, sudo tar cvf; 26 00:01:12,450 --> 00:01:14,130 and then we create a file, right? 27 00:01:14,130 --> 00:01:15,690 And I create the file. 28 00:01:15,690 --> 00:01:17,997 Let's call it "TMP backup-" 29 00:01:20,220 --> 00:01:22,140 and then the command substitution. 30 00:01:22,140 --> 00:01:24,630 Remember if you put it between a dollar and braces 31 00:01:24,630 --> 00:01:28,420 and you use the result of a command 32 00:01:29,280 --> 00:01:32,520 in the actual command you are running. 33 00:01:32,520 --> 00:01:35,920 And this would mean that we create a file 34 00:01:36,780 --> 00:01:39,780 with the name backup dash date 35 00:01:39,780 --> 00:01:44,780 of the date, .tar, of the etc directory or whatever. 36 00:01:45,900 --> 00:01:47,640 That's one convenient way of doing it. 37 00:01:47,640 --> 00:01:52,640 So, ls-l on /tmp/backup, whatever. 38 00:01:53,190 --> 00:01:55,440 There you can see the backup file was created. 39 00:01:55,440 --> 00:01:58,560 And just imagine that you can use this from a script. 40 00:01:58,560 --> 00:02:00,510 If you put this simple command 41 00:02:00,510 --> 00:02:04,380 in a script that you can schedule it with Chrome, 42 00:02:04,380 --> 00:02:06,330 which we will talk about shortly. 43 00:02:06,330 --> 00:02:09,270 And you make sure that every single day you create a backup 44 00:02:09,270 --> 00:02:10,230 of your system. 45 00:02:10,230 --> 00:02:11,133 Isn't that cool? 46 00:02:12,120 --> 00:02:15,130 Let's have a look at hwclock, not just hwclock. 47 00:02:15,130 --> 00:02:19,380 Well, that's showing the hardware clock. 48 00:02:19,380 --> 00:02:23,250 So sudo hwclock is doing what? 49 00:02:23,250 --> 00:02:24,083 There we go. 50 00:02:24,083 --> 00:02:26,250 We need sudo privileges. 51 00:02:26,250 --> 00:02:27,930 The hardware clock and the system clock, 52 00:02:27,930 --> 00:02:29,130 as you have seen in the video, 53 00:02:29,130 --> 00:02:31,890 are not always the same. 54 00:02:31,890 --> 00:02:35,700 And the thing is if your hardware clock is off, 55 00:02:35,700 --> 00:02:37,890 when your system boots, it takes it's time 56 00:02:37,890 --> 00:02:39,330 from the hardware clock. 57 00:02:39,330 --> 00:02:42,960 So every now and then you might have to do a synchronize. 58 00:02:42,960 --> 00:02:46,650 So, sudo hwclock --help. 59 00:02:46,650 --> 00:02:48,840 And there we can see the different options. 60 00:02:48,840 --> 00:02:53,840 If I am going to use systohhc, 61 00:02:54,120 --> 00:02:56,760 that is how we synchronize the hardware clock 62 00:02:56,760 --> 00:02:58,050 with the system time. 63 00:02:58,050 --> 00:03:02,340 And that is useful if your hardware clock is off. 64 00:03:02,340 --> 00:03:06,240 So for the rest of it don't use this command too much, 65 00:03:06,240 --> 00:03:09,960 but go and use timedatectl. 66 00:03:09,960 --> 00:03:12,420 Timedatectl is this new command. 67 00:03:12,420 --> 00:03:16,110 And in this new command, we even have tap completion. 68 00:03:16,110 --> 00:03:17,430 And what else can you do? 69 00:03:17,430 --> 00:03:18,870 Well, you can use show 70 00:03:18,870 --> 00:03:21,750 and there you can see all the different properties, 71 00:03:21,750 --> 00:03:24,570 including the time zone that we are in 72 00:03:24,570 --> 00:03:28,350 and whether or not we are using NTP. 73 00:03:28,350 --> 00:03:33,030 And the time that it is actually right now. 74 00:03:33,030 --> 00:03:34,950 So let's manipulate time zones. 75 00:03:34,950 --> 00:03:39,873 So sudo time, timedatectl set. 76 00:03:41,130 --> 00:03:44,400 Well before set let's do a list time zones. 77 00:03:44,400 --> 00:03:45,360 There you go. 78 00:03:45,360 --> 00:03:49,350 I wanna be in Africa, Banjul. 79 00:03:49,350 --> 00:03:50,370 You know where that is? 80 00:03:50,370 --> 00:03:52,110 In The Gambia, of course. 81 00:03:52,110 --> 00:03:54,900 So let's go to Africa, Banjul. 82 00:03:54,900 --> 00:03:56,490 In order to go there, 83 00:03:56,490 --> 00:04:01,490 Africa/Banjul, we make that a set time zone. 84 00:04:03,180 --> 00:04:04,013 And 85 00:04:05,130 --> 00:04:05,963 there we go. 86 00:04:05,963 --> 00:04:07,410 And what is the result? 87 00:04:07,410 --> 00:04:09,390 Well, the result is what we are going to see 88 00:04:09,390 --> 00:04:11,700 with timedatectl show. 89 00:04:11,700 --> 00:04:14,160 As you can see, I'm an Africa, Banjul 90 00:04:14,160 --> 00:04:17,130 and in Africa, Banjul it's 22:51. 91 00:04:17,130 --> 00:04:19,770 I don't like it to be 22:51. 92 00:04:19,770 --> 00:04:24,770 So let's get back to America, Los Angeles. 93 00:04:28,950 --> 00:04:32,160 But before doing that, we do need to check the format. 94 00:04:32,160 --> 00:04:37,160 So list time zones, and there we go, America. 95 00:04:37,260 --> 00:04:38,550 And where is it? 96 00:04:38,550 --> 00:04:42,630 This is what I wanted to know: Los_Angeles. 97 00:04:42,630 --> 00:04:45,543 So, set timezone, America, 98 00:04:47,220 --> 00:04:49,630 Los Angeles 99 00:04:51,630 --> 00:04:52,710 and there we go. 100 00:04:52,710 --> 00:04:55,770 And even date is reflecting. 101 00:04:55,770 --> 00:04:57,090 Date is reflecting what? 102 00:04:57,090 --> 00:05:00,180 2:52 PM PST. 103 00:05:00,180 --> 00:05:03,330 That's a standard format in the date command. 104 00:05:03,330 --> 00:05:05,400 I think this is about what you need to know 105 00:05:05,400 --> 00:05:08,730 about date and hwclock and timedatectl. 106 00:05:08,730 --> 00:05:10,709 There are many more things that you can do with it 107 00:05:10,709 --> 00:05:14,670 but these are not the most common thing. 108 00:05:14,670 --> 00:05:17,700 So I wouldn't focus on that too much. 109 00:05:17,700 --> 00:05:19,380 This is what you need to know 110 00:05:19,380 --> 00:05:22,833 to make sure that your system is showing the right time.