WEBVTT

0
00:00.120 --> 00:00.450
Now,

1
00:00.450 --> 00:05.370
in the last lesson, we saw how to get up and running with our brand new Flask

2
00:05.400 --> 00:07.590
server. In this lesson

3
00:07.650 --> 00:11.700
I want to take it back a little bit and talk briefly about some of these

4
00:11.700 --> 00:14.070
commands that we put into the terminal here,

5
00:14.970 --> 00:18.650
because the terminal is actually a really powerful tool.

6
00:19.490 --> 00:24.490
And it's something that's also referred to as the command line and its a way of

7
00:24.710 --> 00:29.660
typing in commands one line at a time in order to control our computer.

8
00:30.740 --> 00:33.350
The command line is also known as the shell.

9
00:34.040 --> 00:36.560
So what exactly is a shell?

10
00:37.310 --> 00:40.910
If you think about your operating system as a pistachio nut,

11
00:41.210 --> 00:45.080
then the kernels of the actual pistachio, the thing that you're going to eat,

12
00:45.290 --> 00:47.270
I'm really sorry about all the food analogies.

13
00:47.390 --> 00:50.840
You can clearly tell I'm pretty much hungry most of the time when I'm recording

14
00:50.870 --> 00:53.510
these videos, but let's get back to the topic.

15
00:53.570 --> 00:57.320
So if your operating system is a pistachio,

16
00:57.680 --> 01:01.190
then the actual nut is the kernel. And in computing

17
01:01.190 --> 01:06.190
the kernel refers to the actual program that interfaces with the hardware.

18
01:06.740 --> 01:10.490
So it's the core of your operating system. Now,

19
01:10.490 --> 01:15.350
the shell of your pistachio or the shell  in computing refers to

20
01:15.500 --> 01:18.650
the user interface for you as a human

21
01:18.680 --> 01:23.680
to be able to interact with the kernel and in turn with the hardware of your

22
01:24.200 --> 01:27.710
computer. And there's two variants to the shell.

23
01:28.010 --> 01:32.000
There are graphical user interface shells, so for example,

24
01:32.000 --> 01:33.380
when you open up finder

25
01:33.410 --> 01:38.410
you're using a graphical user interface to access and find your files.

26
01:38.870 --> 01:41.750
But there's also a command line interface

27
01:41.810 --> 01:44.540
which is what we're going to be talking about and what we're going to be

28
01:44.540 --> 01:46.130
learning about in this module.

29
01:46.430 --> 01:50.390
So this is an alternative way of interfacing with the kernel.

30
01:50.810 --> 01:53.210
Now it can seem intimidating at first,

31
01:53.360 --> 01:56.270
but I want to show you that it's actually super simple.

32
01:56.510 --> 01:59.480
And once you understand it, you're going to see that it's actually really,

33
01:59.480 --> 02:01.880
really useful tool at your disposal.

34
02:02.660 --> 02:06.020
A lot of the things that you can do with command line can be done using the

35
02:06.020 --> 02:08.620
graphical user interface. So why use

36
02:08.870 --> 02:11.540
the command line at all? At the end of the day,

37
02:11.540 --> 02:15.350
what it all boils down to is about greater control.

38
02:15.830 --> 02:19.280
And in your journey of becoming a better developer,

39
02:19.430 --> 02:24.430
you will need to understand and exert more power over your tools,

40
02:25.250 --> 02:29.120
that is the computer hardware. But on a more day to day basis,

41
02:29.150 --> 02:31.970
you will find that if you're a regular command-line user

42
02:32.240 --> 02:37.240
that it's actually easier and faster to do a lot of really common things.

43
02:38.480 --> 02:42.920
If you're a Mac user, you've actually got a dedicated terminal application.

44
02:43.220 --> 02:47.510
So if you go to spotlight and hit the search button and look for the terminal

45
02:47.810 --> 02:52.580
and hit enter, you can see that this is the actual terminal application.

46
02:52.910 --> 02:56.390
Now I've styled it up to look a bit more like a hacker because I like scaring

47
02:56.390 --> 02:59.920
people in Starbucks, but that's not the only you can change.

48
02:59.950 --> 03:01.930
You can change the color of your terminal,

49
03:02.410 --> 03:06.850
you can also change the type of shell you're using. Currently,

50
03:06.850 --> 03:11.020
if you are running macOS Catalina or above, so Big Sur

51
03:11.050 --> 03:15.250
or any of the future operating systems, you're going to be using zsh

52
03:15.550 --> 03:17.830
which has now the default Mac shell.

53
03:18.960 --> 03:19.793
<v 1>All right,</v>

54
03:21.480 --> 03:25.770
<v 0>Now, if you're on Windows however, the default shell is the command prompt.</v>

55
03:25.920 --> 03:30.450
So if you type in to search for the command prompt, you can see

56
03:30.450 --> 03:34.440
this is the app you need to launch and this is your command prompt.

57
03:35.490 --> 03:39.180
For the most part, you can type in the same commands on Windows and on Mac

58
03:39.540 --> 03:41.040
and it will work on both.

59
03:41.700 --> 03:46.140
I want to show you some common things we can do in the terminal. Here

60
03:46.170 --> 03:51.170
I've got my terminal and the address of the terminal is determined by the part

61
03:52.290 --> 03:57.180
that's just before the prompt. So at the moment, it's a ~ on my Mac.

62
03:57.900 --> 04:01.380
There's a couple of things I want to show you that you can do with the terminal.

63
04:01.920 --> 04:06.920
The first thing that's really useful to know is where am I in my file path?

64
04:07.710 --> 04:12.450
And to do this, we have to write pwd, print working directory.

65
04:12.930 --> 04:17.100
And this tells me where I am. Once you open up your finder

66
04:17.160 --> 04:21.660
as you can see up here, go to view and then go to show path bar.

67
04:22.170 --> 04:27.170
And this is showing us the path from our hard drive/ users/angela,

68
04:28.470 --> 04:33.470
which is exactly the same location as what I've got now in my terminal.

69
04:34.260 --> 04:38.970
So the print working directory is really useful for you to locate where you are.

70
04:40.140 --> 04:43.920
Similarly, on Windows, you can see when I do print working directory,

71
04:44.220 --> 04:48.570
it tells me that I'm in the C:\users\username.

72
04:48.900 --> 04:53.700
So C drive, users, username... right here.

73
04:56.670 --> 05:00.150
The next command that is really useful is ls,

74
05:00.210 --> 05:02.340
which stands for list.

75
05:03.210 --> 05:08.210
And what this does is it will list all of the files and folders at your current

76
05:08.940 --> 05:10.020
working directory.

77
05:10.290 --> 05:14.430
So it's going to list everything that's in this current location where I am at

78
05:14.700 --> 05:17.550
basically this. So if I go ahead and hit enter,

79
05:17.610 --> 05:21.450
you can see all of the same folders showing up as it does

80
05:21.450 --> 05:26.450
in finder. Pwd and ls are really useful for finding things out, for displaying

81
05:28.080 --> 05:28.860
things.

82
05:28.860 --> 05:33.510
But we can also use the terminal to move around in our computer.

83
05:34.080 --> 05:37.950
And we do that using the CD command, which is changed directory.

84
05:38.520 --> 05:43.170
So if at the moment, my working directory is users/Angela

85
05:43.530 --> 05:45.900
and I want to get into my desktop folder

86
05:46.290 --> 05:50.670
which is clearly one of the folders that I can access, then I can simply say

87
05:50.700 --> 05:55.050
change directory to desktop. Now,

88
05:55.080 --> 05:59.150
one of the things you can do to prevent yourself from getting repetitive strain injury and

89
05:59.150 --> 06:04.070
typing a lot is you can type the start of the folder, so for example desktop-

90
06:04.100 --> 06:06.200
De and then hit tab,

91
06:06.590 --> 06:11.090
and it will narrow down on the possibility that you can go to so there's

92
06:11.090 --> 06:12.830
development or there's desktop.

93
06:13.250 --> 06:16.400
So if I add one extra S and I hit tab,

94
06:16.610 --> 06:20.720
it's now going to automatically insert the folder that I'm looking for,

95
06:20.780 --> 06:23.570
which is desktop. So now if I hit enter,

96
06:23.720 --> 06:28.550
you can see that this part before my flashing prompt has changed and it's

97
06:28.550 --> 06:32.990
changed to the desktop. So now, if I do pwd,

98
06:32.990 --> 06:36.410
you can see I'm now in users/angela/Desktop,

99
06:36.740 --> 06:39.740
which is the equivalent of double-clicking on this basically.

100
06:39.880 --> 06:40.713
<v 1>Okay.</v>

101
06:46.870 --> 06:51.610
<v 0>On my desktop what if I wanted to create a new folder? Well,</v>

102
06:51.610 --> 06:56.610
we can do that using the make dir or make directory command.

103
06:57.250 --> 07:01.630
So we're saying make directory and then we give it a name. So let's say

104
07:01.630 --> 07:04.510
I want to call this Test then I'll just say mk

105
07:04.510 --> 07:07.780
dir Test. And notice the location while you are at.

106
07:07.780 --> 07:11.770
So I'm going to be making this test directory on my desktop.

107
07:12.250 --> 07:14.890
And as soon as they hit enter, there you see it.

108
07:15.040 --> 07:17.740
It's created that folder from scratch.

109
07:19.420 --> 07:24.420
So now here's a question. If you wanted to navigate into Test so that when you

110
07:24.490 --> 07:25.900
print the working directory,

111
07:25.930 --> 07:30.930
it's going to output users/yourusername/desktop/test.

112
07:31.600 --> 07:34.570
What would you do? What would be your command? Pause the video and

113
07:34.570 --> 07:38.800
have a think about that. Alright,

114
07:39.070 --> 07:42.970
of course, we have to change directory coz at the moment we're in the desktop

115
07:43.270 --> 07:46.510
which is this, and if we want to go inside this test folder,

116
07:46.780 --> 07:49.960
then we have to cd into it. So cd into test,

117
07:50.380 --> 07:54.700
and now we're inside the test folder. And if I hit pwed, you can see

118
07:54.760 --> 07:57.070
this is where I'm at. Now,

119
07:57.100 --> 08:00.190
once I've cded into this new directory,

120
08:00.460 --> 08:05.320
I'm going to create a new file in this directory. To create a new file

121
08:05.350 --> 08:08.410
the command is a little bit different from creating a new directory.

122
08:08.800 --> 08:13.480
The key word is touch. And after the key word, there's a space

123
08:13.960 --> 08:16.390
and then we can provide the name of our file.

124
08:16.840 --> 08:19.840
So let's say that we want to create a new Python file

125
08:19.870 --> 08:22.960
which we'll call main.py. Now,

126
08:22.960 --> 08:26.350
what it's going to do is create this file code in main

127
08:26.740 --> 08:31.060
which is a Python file and it's going to do that inside the Test folder.

128
08:31.330 --> 08:34.150
So let's hit enter and there you see it.

129
08:34.210 --> 08:39.210
There's our Python file created without any clicking or dragging completely done

130
08:39.490 --> 08:44.440
with our command line. So we've seen how we can create folders,

131
08:44.470 --> 08:47.200
how we can create files. And by the way,

132
08:47.200 --> 08:49.780
if you want to create a different type of file that you just change the

133
08:49.780 --> 08:51.760
extension. So it could be .text,

134
08:51.760 --> 08:56.760
or it could be .docx or whatever file format you want to create. Now,

135
08:56.910 --> 08:59.970
what if we wanted delete our file? Well,

136
09:00.060 --> 09:04.470
all we have to do is make sure we're in the correct directory to be able to

137
09:04.470 --> 09:06.570
access that file. So when we hit ls,

138
09:06.600 --> 09:08.760
we should be able to see the file we want to delete.

139
09:09.150 --> 09:12.960
And then all we have to do is type rm which stands for remove

140
09:13.410 --> 09:17.100
and then we could put our main.py. So there it is, it's gone.

141
09:17.630 --> 09:18.463
<v 1>Okay.</v>

142
09:22.190 --> 09:26.780
<v 0>Now, what if I want to delete the Test folder? Firstly,</v>

143
09:26.840 --> 09:31.580
I have to navigate one step up. Instead of being inside the Test folder,

144
09:31.880 --> 09:35.330
I can't delete the Test folder while I'm inside the Test folder.

145
09:35.690 --> 09:38.840
I have to go one step up, which is the desktop folder.

146
09:39.740 --> 09:42.920
Now of course I could say cd into the full path

147
09:42.920 --> 09:47.840
which is /Users/angela/Desktop.

148
09:48.140 --> 09:51.620
Now this would work, but this is really wordy.

149
09:52.130 --> 09:54.470
A really simple shortcut for navigating

150
09:54.470 --> 09:59.330
just one step up is writing cd and then two dots.

151
09:59.540 --> 10:04.100
This is going to take us to the parent folder, which is now Desktop.

152
10:06.740 --> 10:07.573
<v 1>Right.</v>

153
10:11.330 --> 10:15.800
<v 0>From here I'm going to delete this folder. Now to delete a folder</v>

154
10:15.800 --> 10:19.070
we can't just put rm. We also have to put a flag.

155
10:19.190 --> 10:24.190
So a - and then rf. So this is going to recursively, forcibly, remove this

156
10:27.710 --> 10:31.550
folder that we're going to add here, which is the Test folder.

157
10:32.060 --> 10:37.060
Now the thing you have to be really careful about rm -rf is it does things

158
10:37.880 --> 10:41.660
recursively. So if there were lots of folders inside this Test folder,

159
10:41.990 --> 10:44.180
then it's going to delete everything in there.

160
10:44.750 --> 10:49.750
And if, God forbid, you actually have this and you put it onto your whole computer,

161
10:50.840 --> 10:53.210
well then that's going to be a real disaster.

162
10:53.690 --> 10:57.890
Because the thing you have to know about the terminal is that it's a very

163
10:57.890 --> 11:02.890
powerful. And what did Spider-Man's uncle say? With great power comes great

164
11:02.990 --> 11:03.980
responsibility.

165
11:05.390 --> 11:09.080
There's some pretty funny stories about people who accidentally deleted

166
11:09.110 --> 11:12.890
everything on their computer just by messing with rm -rf.

167
11:13.340 --> 11:18.340
So be really careful that you are in the correct location to delete the folder

168
11:19.520 --> 11:22.190
and to double check that it's the right folder.

169
11:23.060 --> 11:24.980
Because when I hit enter,

170
11:25.040 --> 11:28.430
you can see it's not going to ask me for a confirmation

171
11:29.030 --> 11:34.030
and it's also not going to put that folder or the containing files into the bin.

172
11:34.940 --> 11:38.120
So be really careful when you're using the terminal.

173
11:40.790 --> 11:41.623
There you have it.

174
11:41.930 --> 11:46.930
There's an introduction to the command line using zsh on a Mac and using the

175
11:49.970 --> 11:53.380
command prompt on Windows. Now,

176
11:53.410 --> 11:57.460
when you open up PyCharm and you go to this emulator terminal,

177
11:57.460 --> 12:01.330
so it's a sort of application within an application,

178
12:01.630 --> 12:04.540
you can see that it looks pretty much the same.

179
12:04.870 --> 12:09.370
Basically, all that PyCharm's done is just bundled the command

180
12:09.370 --> 12:14.370
prompt into the PyCharm on windows and the zsh terminal into the PyCharm 

181
12:16.150 --> 12:20.710
on Mac. So you can do everything that you can do in the terminal

182
12:21.310 --> 12:22.870
inside PyCharm as well

183
12:23.260 --> 12:28.260
which makes it really easy to pip install modules or to run our Flask server.

184
12:30.040 --> 12:30.430
Now,

185
12:30.430 --> 12:34.630
if you want to know about other things that you could do in the Windows command

186
12:34.630 --> 12:38.710
prompt or the Mac terminal, you can simply just search for command prompt

187
12:38.710 --> 12:41.200
cheatsheet or terminal cheatsheet.

188
12:42.700 --> 12:46.000
And what it will take you to are lots of addresses

189
12:46.000 --> 12:50.980
which contain basically a lot more things that you could do with your command

190
12:50.980 --> 12:53.470
line. But the ones that we've talked about today

191
12:53.500 --> 12:57.430
are some of the most common ones and 99% of the time,

192
12:57.460 --> 13:00.100
those are going to be the commands that you're going to be sticking to.

193
13:00.610 --> 13:04.120
So write them down if you need to review them regularly.

194
13:04.390 --> 13:07.150
And if you just use them on a regular basis,

195
13:07.450 --> 13:09.280
you won't have any trouble remembering them.