1
00:00:00,120 --> 00:00:00,450
Now,

2
00:00:00,450 --> 00:00:05,370
in the last lesson, we saw how to get up and running with our brand new Flask

3
00:00:05,400 --> 00:00:07,590
server. In this lesson

4
00:00:07,650 --> 00:00:11,700
I want to take it back a little bit and talk briefly about some of these

5
00:00:11,700 --> 00:00:14,070
commands that we put into the terminal here,

6
00:00:14,970 --> 00:00:18,650
because the terminal is actually a really powerful tool.

7
00:00:19,490 --> 00:00:24,490
And it's something that's also referred to as the command line and its a way of

8
00:00:24,710 --> 00:00:29,660
typing in commands one line at a time in order to control our computer.

9
00:00:30,740 --> 00:00:33,350
The command line is also known as the shell.

10
00:00:34,040 --> 00:00:36,560
So what exactly is a shell?

11
00:00:37,310 --> 00:00:40,910
If you think about your operating system as a pistachio nut,

12
00:00:41,210 --> 00:00:45,080
then the kernels of the actual pistachio, the thing that you're going to eat,

13
00:00:45,290 --> 00:00:47,270
I'm really sorry about all the food analogies.

14
00:00:47,390 --> 00:00:50,840
You can clearly tell I'm pretty much hungry most of the time when I'm recording

15
00:00:50,870 --> 00:00:53,510
these videos, but let's get back to the topic.

16
00:00:53,570 --> 00:00:57,320
So if your operating system is a pistachio,

17
00:00:57,680 --> 00:01:01,190
then the actual nut is the kernel. And in computing

18
00:01:01,190 --> 00:01:06,190
the kernel refers to the actual program that interfaces with the hardware.

19
00:01:06,740 --> 00:01:10,490
So it's the core of your operating system. Now,

20
00:01:10,490 --> 00:01:15,350
the shell of your pistachio or the shell  in computing refers to

21
00:01:15,500 --> 00:01:18,650
the user interface for you as a human

22
00:01:18,680 --> 00:01:23,680
to be able to interact with the kernel and in turn with the hardware of your

23
00:01:24,200 --> 00:01:27,710
computer. And there's two variants to the shell.

24
00:01:28,010 --> 00:01:32,000
There are graphical user interface shells, so for example,

25
00:01:32,000 --> 00:01:33,380
when you open up finder

26
00:01:33,410 --> 00:01:38,410
you're using a graphical user interface to access and find your files.

27
00:01:38,870 --> 00:01:41,750
But there's also a command line interface

28
00:01:41,810 --> 00:01:44,540
which is what we're going to be talking about and what we're going to be

29
00:01:44,540 --> 00:01:46,130
learning about in this module.

30
00:01:46,430 --> 00:01:50,390
So this is an alternative way of interfacing with the kernel.

31
00:01:50,810 --> 00:01:53,210
Now it can seem intimidating at first,

32
00:01:53,360 --> 00:01:56,270
but I want to show you that it's actually super simple.

33
00:01:56,510 --> 00:01:59,480
And once you understand it, you're going to see that it's actually really,

34
00:01:59,480 --> 00:02:01,880
really useful tool at your disposal.

35
00:02:02,660 --> 00:02:06,020
A lot of the things that you can do with command line can be done using the

36
00:02:06,020 --> 00:02:08,620
graphical user interface. So why use

37
00:02:08,870 --> 00:02:11,540
the command line at all? At the end of the day,

38
00:02:11,540 --> 00:02:15,350
what it all boils down to is about greater control.

39
00:02:15,830 --> 00:02:19,280
And in your journey of becoming a better developer,

40
00:02:19,430 --> 00:02:24,430
you will need to understand and exert more power over your tools,

41
00:02:25,250 --> 00:02:29,120
that is the computer hardware. But on a more day to day basis,

42
00:02:29,150 --> 00:02:31,970
you will find that if you're a regular command-line user

43
00:02:32,240 --> 00:02:37,240
that it's actually easier and faster to do a lot of really common things.

44
00:02:38,480 --> 00:02:42,920
If you're a Mac user, you've actually got a dedicated terminal application.

45
00:02:43,220 --> 00:02:47,510
So if you go to spotlight and hit the search button and look for the terminal

46
00:02:47,810 --> 00:02:52,580
and hit enter, you can see that this is the actual terminal application.

47
00:02:52,910 --> 00:02:56,390
Now I've styled it up to look a bit more like a hacker because I like scaring

48
00:02:56,390 --> 00:02:59,920
people in Starbucks, but that's not the only you can change.

49
00:02:59,950 --> 00:03:01,930
You can change the color of your terminal,

50
00:03:02,410 --> 00:03:06,850
you can also change the type of shell you're using. Currently,

51
00:03:06,850 --> 00:03:11,020
if you are running macOS Catalina or above, so Big Sur

52
00:03:11,050 --> 00:03:15,250
or any of the future operating systems, you're going to be using zsh

53
00:03:15,550 --> 00:03:17,830
which has now the default Mac shell.

54
00:03:18,960 --> 00:03:19,793
All right,

55
00:03:21,480 --> 00:03:25,770
Now, if you're on Windows however, the default shell is the command prompt.

56
00:03:25,920 --> 00:03:30,450
So if you type in to search for the command prompt, you can see

57
00:03:30,450 --> 00:03:34,440
this is the app you need to launch and this is your command prompt.

58
00:03:35,490 --> 00:03:39,180
For the most part, you can type in the same commands on Windows and on Mac

59
00:03:39,540 --> 00:03:41,040
and it will work on both.

60
00:03:41,700 --> 00:03:46,140
I want to show you some common things we can do in the terminal. Here

61
00:03:46,170 --> 00:03:51,170
I've got my terminal and the address of the terminal is determined by the part

62
00:03:52,290 --> 00:03:57,180
that's just before the prompt. So at the moment, it's a ~ on my Mac.

63
00:03:57,900 --> 00:04:01,380
There's a couple of things I want to show you that you can do with the terminal.

64
00:04:01,920 --> 00:04:06,920
The first thing that's really useful to know is where am I in my file path?

65
00:04:07,710 --> 00:04:12,450
And to do this, we have to write pwd, print working directory.

66
00:04:12,930 --> 00:04:17,100
And this tells me where I am. Once you open up your finder

67
00:04:17,160 --> 00:04:21,660
as you can see up here, go to view and then go to show path bar.

68
00:04:22,170 --> 00:04:27,170
And this is showing us the path from our hard drive/ users/angela,

69
00:04:28,470 --> 00:04:33,470
which is exactly the same location as what I've got now in my terminal.

70
00:04:34,260 --> 00:04:38,970
So the print working directory is really useful for you to locate where you are.

71
00:04:40,140 --> 00:04:43,920
Similarly, on Windows, you can see when I do print working directory,

72
00:04:44,220 --> 00:04:48,570
it tells me that I'm in the C:\users\username.

73
00:04:48,900 --> 00:04:53,700
So C drive, users, username... right here.

74
00:04:56,670 --> 00:05:00,150
The next command that is really useful is ls,

75
00:05:00,210 --> 00:05:02,340
which stands for list.

76
00:05:03,210 --> 00:05:08,210
And what this does is it will list all of the files and folders at your current

77
00:05:08,940 --> 00:05:10,020
working directory.

78
00:05:10,290 --> 00:05:14,430
So it's going to list everything that's in this current location where I am at

79
00:05:14,700 --> 00:05:17,550
basically this. So if I go ahead and hit enter,

80
00:05:17,610 --> 00:05:21,450
you can see all of the same folders showing up as it does

81
00:05:21,450 --> 00:05:26,450
in finder. Pwd and ls are really useful for finding things out, for displaying

82
00:05:28,080 --> 00:05:28,860
things.

83
00:05:28,860 --> 00:05:33,510
But we can also use the terminal to move around in our computer.

84
00:05:34,080 --> 00:05:37,950
And we do that using the CD command, which is changed directory.

85
00:05:38,520 --> 00:05:43,170
So if at the moment, my working directory is users/Angela

86
00:05:43,530 --> 00:05:45,900
and I want to get into my desktop folder

87
00:05:46,290 --> 00:05:50,670
which is clearly one of the folders that I can access, then I can simply say

88
00:05:50,700 --> 00:05:55,050
change directory to desktop. Now,

89
00:05:55,080 --> 00:05:59,150
one of the things you can do to prevent yourself from getting repetitive strain injury and

90
00:05:59,150 --> 00:06:04,070
typing a lot is you can type the start of the folder, so for example desktop-

91
00:06:04,100 --> 00:06:06,200
De and then hit tab,

92
00:06:06,590 --> 00:06:11,090
and it will narrow down on the possibility that you can go to so there's

93
00:06:11,090 --> 00:06:12,830
development or there's desktop.

94
00:06:13,250 --> 00:06:16,400
So if I add one extra S and I hit tab,

95
00:06:16,610 --> 00:06:20,720
it's now going to automatically insert the folder that I'm looking for,

96
00:06:20,780 --> 00:06:23,570
which is desktop. So now if I hit enter,

97
00:06:23,720 --> 00:06:28,550
you can see that this part before my flashing prompt has changed and it's

98
00:06:28,550 --> 00:06:32,990
changed to the desktop. So now, if I do pwd,

99
00:06:32,990 --> 00:06:36,410
you can see I'm now in users/angela/Desktop,

100
00:06:36,740 --> 00:06:39,740
which is the equivalent of double-clicking on this basically.

101
00:06:39,880 --> 00:06:40,713
Okay.

102
00:06:46,870 --> 00:06:51,610
On my desktop what if I wanted to create a new folder? Well,

103
00:06:51,610 --> 00:06:56,610
we can do that using the make dir or make directory command.

104
00:06:57,250 --> 00:07:01,630
So we're saying make directory and then we give it a name. So let's say

105
00:07:01,630 --> 00:07:04,510
I want to call this Test then I'll just say mk

106
00:07:04,510 --> 00:07:07,780
dir Test. And notice the location while you are at.

107
00:07:07,780 --> 00:07:11,770
So I'm going to be making this test directory on my desktop.

108
00:07:12,250 --> 00:07:14,890
And as soon as they hit enter, there you see it.

109
00:07:15,040 --> 00:07:17,740
It's created that folder from scratch.

110
00:07:19,420 --> 00:07:24,420
So now here's a question. If you wanted to navigate into Test so that when you

111
00:07:24,490 --> 00:07:25,900
print the working directory,

112
00:07:25,930 --> 00:07:30,930
it's going to output users/yourusername/desktop/test.

113
00:07:31,600 --> 00:07:34,570
What would you do? What would be your command? Pause the video and

114
00:07:34,570 --> 00:07:38,800
have a think about that. Alright,

115
00:07:39,070 --> 00:07:42,970
of course, we have to change directory coz at the moment we're in the desktop

116
00:07:43,270 --> 00:07:46,510
which is this, and if we want to go inside this test folder,

117
00:07:46,780 --> 00:07:49,960
then we have to cd into it. So cd into test,

118
00:07:50,380 --> 00:07:54,700
and now we're inside the test folder. And if I hit pwed, you can see

119
00:07:54,760 --> 00:07:57,070
this is where I'm at. Now,

120
00:07:57,100 --> 00:08:00,190
once I've cded into this new directory,

121
00:08:00,460 --> 00:08:05,320
I'm going to create a new file in this directory. To create a new file

122
00:08:05,350 --> 00:08:08,410
the command is a little bit different from creating a new directory.

123
00:08:08,800 --> 00:08:13,480
The key word is touch. And after the key word, there's a space

124
00:08:13,960 --> 00:08:16,390
and then we can provide the name of our file.

125
00:08:16,840 --> 00:08:19,840
So let's say that we want to create a new Python file

126
00:08:19,870 --> 00:08:22,960
which we'll call main.py. Now,

127
00:08:22,960 --> 00:08:26,350
what it's going to do is create this file code in main

128
00:08:26,740 --> 00:08:31,060
which is a Python file and it's going to do that inside the Test folder.

129
00:08:31,330 --> 00:08:34,150
So let's hit enter and there you see it.

130
00:08:34,210 --> 00:08:39,210
There's our Python file created without any clicking or dragging completely done

131
00:08:39,490 --> 00:08:44,440
with our command line. So we've seen how we can create folders,

132
00:08:44,470 --> 00:08:47,200
how we can create files. And by the way,

133
00:08:47,200 --> 00:08:49,780
if you want to create a different type of file that you just change the

134
00:08:49,780 --> 00:08:51,760
extension. So it could be .text,

135
00:08:51,760 --> 00:08:56,760
or it could be .docx or whatever file format you want to create. Now,

136
00:08:56,910 --> 00:08:59,970
what if we wanted delete our file? Well,

137
00:09:00,060 --> 00:09:04,470
all we have to do is make sure we're in the correct directory to be able to

138
00:09:04,470 --> 00:09:06,570
access that file. So when we hit ls,

139
00:09:06,600 --> 00:09:08,760
we should be able to see the file we want to delete.

140
00:09:09,150 --> 00:09:12,960
And then all we have to do is type rm which stands for remove

141
00:09:13,410 --> 00:09:17,100
and then we could put our main.py. So there it is, it's gone.

142
00:09:17,630 --> 00:09:18,463
Okay.

143
00:09:22,190 --> 00:09:26,780
Now, what if I want to delete the Test folder? Firstly,

144
00:09:26,840 --> 00:09:31,580
I have to navigate one step up. Instead of being inside the Test folder,

145
00:09:31,880 --> 00:09:35,330
I can't delete the Test folder while I'm inside the Test folder.

146
00:09:35,690 --> 00:09:38,840
I have to go one step up, which is the desktop folder.

147
00:09:39,740 --> 00:09:42,920
Now of course I could say cd into the full path

148
00:09:42,920 --> 00:09:47,840
which is /Users/angela/Desktop.

149
00:09:48,140 --> 00:09:51,620
Now this would work, but this is really wordy.

150
00:09:52,130 --> 00:09:54,470
A really simple shortcut for navigating

151
00:09:54,470 --> 00:09:59,330
just one step up is writing cd and then two dots.

152
00:09:59,540 --> 00:10:04,100
This is going to take us to the parent folder, which is now Desktop.

153
00:10:06,740 --> 00:10:07,573
Right.

154
00:10:11,330 --> 00:10:15,800
From here I'm going to delete this folder. Now to delete a folder

155
00:10:15,800 --> 00:10:19,070
we can't just put rm. We also have to put a flag.

156
00:10:19,190 --> 00:10:24,190
So a - and then rf. So this is going to recursively, forcibly, remove this

157
00:10:27,710 --> 00:10:31,550
folder that we're going to add here, which is the Test folder.

158
00:10:32,060 --> 00:10:37,060
Now the thing you have to be really careful about rm -rf is it does things

159
00:10:37,880 --> 00:10:41,660
recursively. So if there were lots of folders inside this Test folder,

160
00:10:41,990 --> 00:10:44,180
then it's going to delete everything in there.

161
00:10:44,750 --> 00:10:49,750
And if, God forbid, you actually have this and you put it onto your whole computer,

162
00:10:50,840 --> 00:10:53,210
well then that's going to be a real disaster.

163
00:10:53,690 --> 00:10:57,890
Because the thing you have to know about the terminal is that it's a very

164
00:10:57,890 --> 00:11:02,890
powerful. And what did Spider-Man's uncle say? With great power comes great

165
00:11:02,990 --> 00:11:03,980
responsibility.

166
00:11:05,390 --> 00:11:09,080
There's some pretty funny stories about people who accidentally deleted

167
00:11:09,110 --> 00:11:12,890
everything on their computer just by messing with rm -rf.

168
00:11:13,340 --> 00:11:18,340
So be really careful that you are in the correct location to delete the folder

169
00:11:19,520 --> 00:11:22,190
and to double check that it's the right folder.

170
00:11:23,060 --> 00:11:24,980
Because when I hit enter,

171
00:11:25,040 --> 00:11:28,430
you can see it's not going to ask me for a confirmation

172
00:11:29,030 --> 00:11:34,030
and it's also not going to put that folder or the containing files into the bin.

173
00:11:34,940 --> 00:11:38,120
So be really careful when you're using the terminal.

174
00:11:40,790 --> 00:11:41,623
There you have it.

175
00:11:41,930 --> 00:11:46,930
There's an introduction to the command line using zsh on a Mac and using the

176
00:11:49,970 --> 00:11:53,380
command prompt on Windows. Now,

177
00:11:53,410 --> 00:11:57,460
when you open up PyCharm and you go to this emulator terminal,

178
00:11:57,460 --> 00:12:01,330
so it's a sort of application within an application,

179
00:12:01,630 --> 00:12:04,540
you can see that it looks pretty much the same.

180
00:12:04,870 --> 00:12:09,370
Basically, all that PyCharm's done is just bundled the command

181
00:12:09,370 --> 00:12:14,370
prompt into the PyCharm on windows and the zsh terminal into the PyCharm 

182
00:12:16,150 --> 00:12:20,710
on Mac. So you can do everything that you can do in the terminal

183
00:12:21,310 --> 00:12:22,870
inside PyCharm as well

184
00:12:23,260 --> 00:12:28,260
which makes it really easy to pip install modules or to run our Flask server.

185
00:12:30,040 --> 00:12:30,430
Now,

186
00:12:30,430 --> 00:12:34,630
if you want to know about other things that you could do in the Windows command

187
00:12:34,630 --> 00:12:38,710
prompt or the Mac terminal, you can simply just search for command prompt

188
00:12:38,710 --> 00:12:41,200
cheatsheet or terminal cheatsheet.

189
00:12:42,700 --> 00:12:46,000
And what it will take you to are lots of addresses

190
00:12:46,000 --> 00:12:50,980
which contain basically a lot more things that you could do with your command

191
00:12:50,980 --> 00:12:53,470
line. But the ones that we've talked about today

192
00:12:53,500 --> 00:12:57,430
are some of the most common ones and 99% of the time,

193
00:12:57,460 --> 00:13:00,100
those are going to be the commands that you're going to be sticking to.

194
00:13:00,610 --> 00:13:04,120
So write them down if you need to review them regularly.

195
00:13:04,390 --> 00:13:07,150
And if you just use them on a regular basis,

196
00:13:07,450 --> 00:13:09,280
you won't have any trouble remembering them.

