WEBVTT - This file was automatically generated by VIMEO

0
00:00:07.100 --> 00:00:10.600
In this video, you'll learn how to create files and directories inside

1
00:00:10.600 --> 00:00:11.200
 Linux.

2
00:00:12.800 --> 00:00:15.100
Our plan is to explore how Lennox handles files and

3
00:00:15.100 --> 00:00:15.500
 directories.

4
00:00:16.100 --> 00:00:19.300
We will discuss our files and directories have ownership and permissions that

5
00:00:19.300 --> 00:00:20.500
 could be used to gate access.

6
00:00:21.400 --> 00:00:24.100
Finally, you will use a couple of commands to create your own

7
00:00:24.100 --> 00:00:27.300
 file and directory. Let's get started. Okay. So

8
00:00:27.300 --> 00:00:30.300
 here we are back in the terminal and as you recall from the

9
00:00:30.300 --> 00:00:33.300
 last video files and directories make up the

10
00:00:33.300 --> 00:00:36.200
 Linux file system creating files and directors are

11
00:00:36.200 --> 00:00:37.700
 actually pretty easy in Linux.

12
00:00:38.400 --> 00:00:41.400
Each file and directory is associated with an owner

13
00:00:41.400 --> 00:00:44.500
 a group and has permission access rights for

14
00:00:44.500 --> 00:00:48.000
 three different types of classifications and those classifications

15
00:00:47.300 --> 00:00:51.200
 are user group and other this

16
00:00:50.200 --> 00:00:53.100
 will make a little bit more sense as we go ahead and

17
00:00:53.100 --> 00:00:56.800
 look at some. So let's go ahead and look at a file for permissions. I'm going

18
00:00:56.800 --> 00:00:59.700
 to start right here in our home directory since that's

19
00:00:59.700 --> 00:01:02.400
 gonna be easiest and if remember if you remember we use the ls

20
00:01:02.400 --> 00:01:04.100
 command to list the contents of a directory.

21
00:01:04.900 --> 00:01:06.600
Right now it doesn't look like there's anything.

22
00:01:07.400 --> 00:01:10.400
But if we use the dash a command that'll list

23
00:01:10.400 --> 00:01:13.900
 all files and directories that includes anything hidden and

24
00:01:13.900 --> 00:01:16.400
 so we'll go add the L for the long listing.

25
00:01:16.400 --> 00:01:17.500
 So it's easy to read on the output.

26
00:01:18.200 --> 00:01:21.500
And as you can see here, there are there's seven

27
00:01:21.500 --> 00:01:24.200
 items here and six of those are files and

28
00:01:24.200 --> 00:01:25.000
 one is a directory.

29
00:01:25.800 --> 00:01:28.500
And so we'll focus on the file right

30
00:01:28.500 --> 00:01:31.400
 now called bash RC. If you aren't familiar

31
00:01:31.400 --> 00:01:34.900
 with the dot bash RC file, it is basically a the configuration

32
00:01:34.900 --> 00:01:37.400
 file for your bash. Shell. We

33
00:01:37.400 --> 00:01:40.600
 will get into bash and The Bash and

34
00:01:40.600 --> 00:01:42.100
 Bash scripting in the next section.

35
00:01:43.200 --> 00:01:46.200
So think about this right now all these

36
00:01:46.200 --> 00:01:49.300
 are there's a lot of information here, but this is kind of broken up into

37
00:01:49.300 --> 00:01:52.100
 columns. And so you have column one.

38
00:01:52.100 --> 00:01:55.700
 You can forget about column two for right now column three

39
00:01:55.700 --> 00:01:58.400
 and column 4 and then you have the rest of these columns

40
00:01:58.400 --> 00:02:01.100
 and then obviously the last column which is the file name. We're gonna

41
00:02:01.100 --> 00:02:03.600
 focus on column one column three and column 4.

42
00:02:04.300 --> 00:02:04.700
for this video

43
00:02:05.700 --> 00:02:08.200
So the I'm actually gonna work a little bit backwards here

44
00:02:08.200 --> 00:02:12.000
 so column four, which is highlighted right now. This

45
00:02:11.500 --> 00:02:14.700
 column is the group. So this

46
00:02:14.700 --> 00:02:15.500
 is the group.

47
00:02:16.400 --> 00:02:19.000
Of this file. So this file belongs to

48
00:02:19.200 --> 00:02:23.300
 this group column three over here is the user. And

49
00:02:22.300 --> 00:02:25.700
 so that means that ec2 user

50
00:02:25.700 --> 00:02:28.500
 which if you recall is the default user created

51
00:02:28.500 --> 00:02:30.600
 by Amazon Linux

52
00:02:31.500 --> 00:02:34.500
And it's not by an accident that the group is also

53
00:02:34.500 --> 00:02:37.400
 named bc2 users. So when you create a user by

54
00:02:37.400 --> 00:02:40.700
 default, you will get a group name the same as the username and we

55
00:02:40.700 --> 00:02:43.100
 will explore those later in another section when we cover

56
00:02:43.100 --> 00:02:44.100
 users in groups.

57
00:02:45.200 --> 00:02:48.100
So here the ec2 user is the

58
00:02:48.100 --> 00:02:51.300
 owner of this bash RC file, which makes sense,

59
00:02:51.300 --> 00:02:54.500
 right? Because it's in the ec2 user directory. You

60
00:02:54.500 --> 00:02:56.300
 would expect it to be owned by that user.

61
00:02:56.800 --> 00:02:59.600
So let's go look over here in column one. So

62
00:02:59.600 --> 00:03:02.800
 column one is a set

63
00:03:02.800 --> 00:03:05.400
 of permission and these permissions are broken into

64
00:03:05.400 --> 00:03:08.800
 three different classifications. Like I said earlier user

65
00:03:08.800 --> 00:03:09.500
 group and other

66
00:03:10.800 --> 00:03:13.400
the first Dash right out here is

67
00:03:13.400 --> 00:03:16.400
 what it is called file type and it basically

68
00:03:16.400 --> 00:03:19.300
 tells us what type of file it is. And if you look down here

69
00:03:19.300 --> 00:03:23.200
 on the data SSH, it has a d which denotes

70
00:03:22.200 --> 00:03:25.400
 directory but we'll get to that in a second. You can

71
00:03:25.400 --> 00:03:28.100
 see here the dash meaning that it's just a standard file.

72
00:03:28.100 --> 00:03:31.200
 It's not set the next three characters here.

73
00:03:32.100 --> 00:03:35.600
Are their permissions for the user classification?

74
00:03:36.400 --> 00:03:37.900
and what the

75
00:03:38.700 --> 00:03:41.300
Options you have here for your permissions and

76
00:03:41.300 --> 00:03:44.900
 I'll write this out right now is read right and

77
00:03:44.900 --> 00:03:48.100
 execute denoted by the rwx. And

78
00:03:47.100 --> 00:03:50.500
 so they do exactly what they say.

79
00:03:50.500 --> 00:03:53.200
 You can read permission you have a right permission.

80
00:03:53.200 --> 00:03:56.500
 You have an execute permission. So if we look at our back at our Bashar C

81
00:03:56.500 --> 00:03:59.700
 example here, you can see that the first

82
00:03:59.700 --> 00:04:02.100
 three characters we have read and write

83
00:04:02.100 --> 00:04:05.200
 or set but the X the execute bit is

84
00:04:05.200 --> 00:04:08.100
 not set that's denoted by the by the just the

85
00:04:08.100 --> 00:04:08.600
 the dash there.

86
00:04:09.600 --> 00:04:13.100
The next classification which is the group classification,

87
00:04:12.100 --> 00:04:15.600
 you can see that we have the r bit

88
00:04:15.600 --> 00:04:18.600
 the read bit set, but no right or execute

89
00:04:18.600 --> 00:04:22.000
 it and the last classification which

90
00:04:21.200 --> 00:04:24.500
 is other which kind of means any anybody else.

91
00:04:25.300 --> 00:04:28.700
You can see that the read bit is set but they're

92
00:04:28.700 --> 00:04:31.100
 right in execute better not set very similar to group.

93
00:04:32.200 --> 00:04:35.100
Okay, so let's talk about the files put this all together just for the

94
00:04:35.100 --> 00:04:35.400
 file.

95
00:04:36.300 --> 00:04:39.600
We could see here that the ec2 user

96
00:04:39.600 --> 00:04:42.400
 who is the user of this file the owner

97
00:04:42.400 --> 00:04:43.000
 you could say.

98
00:04:44.100 --> 00:04:47.200
That person can read and write to this

99
00:04:47.200 --> 00:04:49.300
 file which makes sense because it's their file.

100
00:04:50.200 --> 00:04:53.900
If you are a user inside the ec2 user

101
00:04:53.900 --> 00:04:54.100
 group.

102
00:04:55.300 --> 00:04:58.500
You have the read permission of this file meaning you can read any

103
00:04:58.500 --> 00:04:59.700
 of the contents of that file.

104
00:05:00.300 --> 00:05:03.400
And if your other anybody else that not of

105
00:05:03.400 --> 00:05:06.600
 those two classifications you can read this file as well. So

106
00:05:06.600 --> 00:05:10.000
 that is the basic overview of file permission.

107
00:05:10.600 --> 00:05:13.700
So let's take what we just learned about there about ownership

108
00:05:13.700 --> 00:05:16.300
 and permissions. And now let's talk about that in

109
00:05:16.300 --> 00:05:17.600
 the context of a directory.

110
00:05:18.300 --> 00:05:21.400
So like I said before the D out here, lets us know the

111
00:05:21.400 --> 00:05:24.500
 file type which is a directory and this dot SSH

112
00:05:24.500 --> 00:05:27.400
 directory. Just if you're not familiar with it, this contains all of

113
00:05:27.400 --> 00:05:30.500
 your information either a local SSH config and your

114
00:05:30.500 --> 00:05:33.200
 SSH key. So this is sensitive information that you

115
00:05:33.200 --> 00:05:36.300
 would want protected. You wouldn't want anybody to be able to just

116
00:05:36.300 --> 00:05:40.000
 read this right only the owner of these files

117
00:05:39.300 --> 00:05:40.900
 inside this directory.

118
00:05:41.700 --> 00:05:44.200
And the director itself, of course, so you

119
00:05:44.200 --> 00:05:47.700
 can see here in our first classification which is the user we have

120
00:05:47.700 --> 00:05:51.100
 rwx which is read right execute. And

121
00:05:50.100 --> 00:05:53.600
 then if you look at the other two classifications the

122
00:05:53.600 --> 00:05:53.800
 group

123
00:05:54.700 --> 00:05:55.300
and the other

124
00:05:56.300 --> 00:06:00.200
none of them are set by the dashes. So only so

125
00:05:59.200 --> 00:06:02.600
 the way that this reads is only the

126
00:06:02.600 --> 00:06:05.100
 ec2 user who the owner of this

127
00:06:05.100 --> 00:06:08.700
 directory can actually read write and execute anything

128
00:06:08.700 --> 00:06:10.700
 and anything to do with this directory.

129
00:06:11.800 --> 00:06:14.900
So that is the basic file

130
00:06:14.900 --> 00:06:17.500
 permissions and file and

131
00:06:17.500 --> 00:06:20.300
 directory ownership on a Linux file system.

132
00:06:20.300 --> 00:06:23.200
 Obviously, there's a lot more you can cover here, but I wanted to

133
00:06:23.200 --> 00:06:25.300
 keep it high level for brevity.

134
00:06:26.400 --> 00:06:28.100
We'll explore ownership and permissions.

135
00:06:29.100 --> 00:06:30.900
When we get into users and groups.

136
00:06:32.200 --> 00:06:36.100
We're going to use a few commands called touch make their

137
00:06:35.100 --> 00:06:38.500
 MV RM and CP

138
00:06:38.500 --> 00:06:41.000
 to manage files and directories as we

139
00:06:41.200 --> 00:06:41.900
 go through this lesson.

140
00:06:44.400 --> 00:06:47.900
Don't worry about if you're not familiar with a lot of these commands. I'll we'll

141
00:06:47.900 --> 00:06:50.200
 use all of them. I'll tell you what they

142
00:06:50.200 --> 00:06:53.300
 are. So you get a little familiarity with them. So let's start off

143
00:06:53.300 --> 00:06:56.500
 with the touch command the touch command creates an empty file if

144
00:06:56.500 --> 00:06:57.500
 it doesn't already exist.

145
00:06:58.800 --> 00:07:01.500
The make dir command or

146
00:07:01.500 --> 00:07:04.500
 mkdir command stands for make directory

147
00:07:04.500 --> 00:07:06.000
 creates a new directory.

148
00:07:06.700 --> 00:07:10.200
The MV command moves and renames

149
00:07:09.200 --> 00:07:12.900
 files and directories. It's kind of does both the

150
00:07:12.900 --> 00:07:15.300
 RM command removes files

151
00:07:15.300 --> 00:07:18.900
 and directories and the CP command copies files

152
00:07:18.900 --> 00:07:21.500
 in direct. So let's put all these commands to

153
00:07:21.500 --> 00:07:24.300
 use. So we're gonna create a directory right here in

154
00:07:24.300 --> 00:07:27.600
 our home directory called engineering if by any

155
00:07:27.600 --> 00:07:29.400
 chance, you're still not in the home directory.

156
00:07:30.500 --> 00:07:33.300
There's a little shortcut you can do and if you remember the the command we

157
00:07:33.300 --> 00:07:36.400
 used earlier which was CD which for change directory if you

158
00:07:36.400 --> 00:07:39.500
 just type CD and do not give it any arguments and

159
00:07:39.500 --> 00:07:42.200
 hit return. It'll return you to your

160
00:07:42.200 --> 00:07:45.300
 home directory every time. Okay, so let me clear the screen.

161
00:07:47.100 --> 00:07:51.100
And we're gonna create our directory and we're gonna use the mkdir

162
00:07:50.100 --> 00:07:53.200
 command and we're gonna pass it the name

163
00:07:53.200 --> 00:07:54.700
 of the director, which is engineering.

164
00:07:58.300 --> 00:08:01.200
So type that in your terminal and then when

165
00:08:01.200 --> 00:08:01.600
 you hit return

166
00:08:02.800 --> 00:08:05.600
we should have a directory created. So let's verify that so

167
00:08:05.600 --> 00:08:07.200
 we're going to use the ls command again.

168
00:08:08.700 --> 00:08:12.200
And as you can see here, we have the engineering directory

169
00:08:11.200 --> 00:08:14.300
 created and we can knowing what we just learned.

170
00:08:14.300 --> 00:08:17.200
 We could go ahead and validate that as well and we're going

171
00:08:17.200 --> 00:08:20.300
 to use the dash L here for the long format so you can see the permissions and

172
00:08:20.300 --> 00:08:20.800
 ownership.

173
00:08:22.200 --> 00:08:25.600
And as we can see here, the engineering directory was

174
00:08:25.600 --> 00:08:28.800
 created its own by the ec2 user and

175
00:08:28.800 --> 00:08:31.300
 the ec2 user group which makes sense. That's the

176
00:08:31.300 --> 00:08:34.500
 default on that logged in is that user? So when I create it it

177
00:08:34.500 --> 00:08:34.800
 uses that

178
00:08:35.900 --> 00:08:37.700
But here's something interesting. So if you look at

179
00:08:38.700 --> 00:08:41.600
Column one here. You can see in this

180
00:08:41.600 --> 00:08:44.300
 classifications. The user has read

181
00:08:44.300 --> 00:08:47.200
 right and execute. The group has read right and

182
00:08:47.200 --> 00:08:50.900
 execute on this on this directory which makes sense. So any myself or

183
00:08:50.900 --> 00:08:54.100
 anybody in the ec2 user group can do

184
00:08:53.100 --> 00:08:56.300
 all those things can read right and execute stuff in

185
00:08:56.300 --> 00:08:58.600
 this directory and then if you look at

186
00:08:59.700 --> 00:09:02.300
The other it's read and execute meaning

187
00:09:02.300 --> 00:09:06.000
 they can't write to any of the files in inside this

188
00:09:05.300 --> 00:09:08.300
 directory are or right to this directory,

189
00:09:08.300 --> 00:09:10.800
 but they can read and execute.

190
00:09:12.100 --> 00:09:15.100
So, okay, so we validated that so what we're

191
00:09:15.100 --> 00:09:18.700
 going to do next is we want to create a file inside this

192
00:09:18.700 --> 00:09:21.200
 directory. So I'll clear

193
00:09:21.200 --> 00:09:22.000
 the screen one more time.

194
00:09:22.800 --> 00:09:25.000
So let's change directory into engineering.

195
00:09:28.200 --> 00:09:31.100
And then we are going to create a file and let's just call it

196
00:09:31.100 --> 00:09:31.600
 test.

197
00:09:32.600 --> 00:09:35.500
And we're going to use the touch command for this and like I said touch will

198
00:09:35.500 --> 00:09:37.200
 create an empty file if it does not exist.

199
00:09:38.200 --> 00:09:42.300
So you'll type in touch and the file we want to create hit

200
00:09:41.300 --> 00:09:42.400
 enter.

201
00:09:43.300 --> 00:09:46.300
And if we just do a quick LS you can

202
00:09:46.300 --> 00:09:49.100
 see it's there. If I add the Long View so we can see the

203
00:09:49.100 --> 00:09:52.400
 permissions you can see that we created a user just like

204
00:09:52.400 --> 00:09:53.300
 the directory it is.

205
00:09:54.400 --> 00:09:57.000
It is by the ec2 user and it is in the

206
00:09:57.600 --> 00:09:58.000
 ec2 user group.

207
00:09:58.600 --> 00:10:01.400
And we can see that the user and group can both

208
00:10:01.400 --> 00:10:04.300
 read and write to this file, but anybody else can

209
00:10:04.300 --> 00:10:04.900
 only read it?

210
00:10:06.200 --> 00:10:09.300
Okay, so at this point we've created a

211
00:10:09.300 --> 00:10:11.500
 directory and we have a file inside this directory.

212
00:10:12.300 --> 00:10:15.100
Let's pretend that we made a mistake on the

213
00:10:15.100 --> 00:10:18.700
 name of this file and we were meant to name. It contributors instead.

214
00:10:18.700 --> 00:10:21.900
 We can use the MV command here to

215
00:10:21.900 --> 00:10:25.000
 go ahead and rename this file. So MV

216
00:10:24.200 --> 00:10:27.700
 will take the name of the file or the source

217
00:10:27.700 --> 00:10:30.100
 and then the the name you want

218
00:10:30.100 --> 00:10:32.200
 to rename it as so we'll type MV.

219
00:10:33.600 --> 00:10:35.900
test and then contributors

220
00:10:37.200 --> 00:10:38.600
I can spell it and

221
00:10:39.800 --> 00:10:42.200
we'll hit return. So now if we do

222
00:10:42.200 --> 00:10:44.100
 an LS with the long format.

223
00:10:44.800 --> 00:10:47.700
We could see that we have a file called contributors now

224
00:10:47.700 --> 00:10:50.600
 and test is no longer there. We've just renamed

225
00:10:50.600 --> 00:10:53.000
 it. It has the same permissions the same user and group.

226
00:10:54.300 --> 00:10:57.600
Okay, so from here, let's jump back into our home directory

227
00:10:57.600 --> 00:11:00.800
 and we're going to use this the CD shortcut and

228
00:11:00.800 --> 00:11:01.700
 I'll clear the screen.

229
00:11:03.200 --> 00:11:06.400
Okay, so let's create another file and this file we're

230
00:11:06.400 --> 00:11:09.600
 gonna call config.y ML and this is

231
00:11:09.600 --> 00:11:12.100
 basically a like configuration yaml file

232
00:11:12.100 --> 00:11:15.800
 if you're not familiar with the ammo don't it's not that big of a deal right now, but

233
00:11:15.800 --> 00:11:18.200
 what we're gonna do is we're gonna create that in our

234
00:11:18.200 --> 00:11:21.200
 home directory not in the engineering directory.

235
00:11:22.800 --> 00:11:25.200
And we'll touch config.yamo.

236
00:11:26.200 --> 00:11:30.000
And if we do a quick LS we could see that config.yamo and

237
00:11:29.200 --> 00:11:32.100
 the engineering directory now in our home directory.

238
00:11:33.200 --> 00:11:36.900
So what we're going to do now is we've realized

239
00:11:36.900 --> 00:11:39.500
 that hey we've should actually made

240
00:11:39.500 --> 00:11:42.200
 this in the engineering directory. I know these are all

241
00:11:42.200 --> 00:11:45.400
 very contrived, but I wanted to make sure that you got exposed

242
00:11:45.400 --> 00:11:48.700
 to all the commands and some reasonable light explanations.

243
00:11:49.300 --> 00:11:52.100
We want to make a copy of the config yaml file

244
00:11:52.100 --> 00:11:55.000
 and it should be in the engineering directory as well.

245
00:11:56.300 --> 00:11:57.900
So we're going to use the CP command.

246
00:11:58.700 --> 00:12:01.300
And like I said before cop is the CP command

247
00:12:01.300 --> 00:12:04.200
 copies of file or directory from a source to a

248
00:12:04.200 --> 00:12:05.800
 destination. So we are gonna

249
00:12:06.800 --> 00:12:09.200
we are gonna say the config.yaml file.

250
00:12:09.200 --> 00:12:11.800
 We want to copy it into the engineering directory.

251
00:12:12.400 --> 00:12:15.300
So we'll hit enter right there after you

252
00:12:15.300 --> 00:12:19.300
 type that in terminal and if we look we still have a version

253
00:12:18.300 --> 00:12:21.200
 of the config diama file

254
00:12:21.200 --> 00:12:24.500
 in our home directory, but also if I

255
00:12:24.500 --> 00:12:28.000
 look in the engineering directory with the long format

256
00:12:27.200 --> 00:12:28.400
 of LS

257
00:12:29.600 --> 00:12:33.100
You can see that now we have the contributors file and

258
00:12:32.100 --> 00:12:35.400
 we have the config.ieml file and they

259
00:12:35.400 --> 00:12:37.300
 have the same permissions same users and groups.

260
00:12:38.500 --> 00:12:41.000
Let's decide that, you know.

261
00:12:42.100 --> 00:12:45.500
We don't really need this in our home directory anymore. It's fine just

262
00:12:45.500 --> 00:12:48.500
 to have one copy of it in the engineering directory. So

263
00:12:48.500 --> 00:12:51.000
 we're going to use the RM command at this point and this

264
00:12:51.100 --> 00:12:54.000
 is the remove command. So removal remove a file or directory.

265
00:12:54.800 --> 00:12:56.200
And so we use RM.

266
00:12:56.900 --> 00:12:59.400
And then we'll use the config and you notice out. We're

267
00:12:59.400 --> 00:13:02.900
 still in our home directory not in the engineering directory and

268
00:13:02.900 --> 00:13:04.700
 you go ahead and remove config.aml.

269
00:13:06.200 --> 00:13:09.800
And if we do a quick LS we can see that it is now gone.

270
00:13:09.800 --> 00:13:12.300
 Okay. So this was the

271
00:13:12.300 --> 00:13:15.800
 quick overview of files and directories and

272
00:13:15.800 --> 00:13:18.200
 the commands you would use to manipulate them.

273
00:13:18.200 --> 00:13:21.900
 You also introduced to ownership and permissions.

274
00:13:21.900 --> 00:13:24.900
 So let's jump back over and let's recap

275
00:13:24.900 --> 00:13:25.800
 of what we did in this video.

276
00:13:26.800 --> 00:13:29.100
Okay, so let's talk about what we did in this

277
00:13:29.100 --> 00:13:29.200
 video.

278
00:13:30.100 --> 00:13:33.200
You first learned about Linux files and directories and how to

279
00:13:33.200 --> 00:13:37.100
 manage them. You introduced to ownership categories user

280
00:13:36.100 --> 00:13:38.000
 group and other

281
00:13:38.600 --> 00:13:41.400
we also talked about permissions like read right and

282
00:13:41.400 --> 00:13:44.400
 execute. These will make more sense later on when we apply

283
00:13:44.400 --> 00:13:47.600
 them in another video you use common commands like

284
00:13:47.600 --> 00:13:50.400
 touch and make dirt to create a

285
00:13:50.400 --> 00:13:52.600
 file inside the engineering directory.

286
00:13:54.700 --> 00:13:57.200
In the next video you will get a crash course

287
00:13:57.200 --> 00:13:59.300
 in user management. See you soon.
