1
00:00:00,000 --> 00:00:02,490
Besides performing basic file operations

2
00:00:02,490 --> 00:00:04,530
like reading, writing, and moving,

3
00:00:04,530 --> 00:00:08,130
we can also manipulate files so that they're more useful.

4
00:00:08,130 --> 00:00:09,510
So, we're just going to go over a few ways

5
00:00:09,510 --> 00:00:12,500
to accomplish this, as well as get metadata about the files.

6
00:00:12,500 --> 00:00:14,580
So the first thing we're going to do is we're going to just look

7
00:00:14,580 --> 00:00:15,480
at a software list.

8
00:00:15,480 --> 00:00:19,200
So, we're just going to use this n option just

9
00:00:19,200 --> 00:00:21,060
to see the number of lines

10
00:00:21,060 --> 00:00:22,860
and going to look at this really quick.

11
00:00:26,010 --> 00:00:28,977
So you see, we have a clear view of the software list

12
00:00:28,977 --> 00:00:30,780
and I added the n option

13
00:00:30,780 --> 00:00:32,159
so we can see the number list

14
00:00:32,159 --> 00:00:32,993
and that's going to be more useful later on.

15
00:00:32,993 --> 00:00:35,460
What we're going to do next

16
00:00:35,460 --> 00:00:36,960
is we're going to use the sort command

17
00:00:36,960 --> 00:00:38,370
And what that is going to do

18
00:00:38,370 --> 00:00:42,000
is sort the file alphabetical order.

19
00:00:42,000 --> 00:00:44,880
And we're going to use the K option

20
00:00:44,880 --> 00:00:47,040
which refers to the column.

21
00:00:47,040 --> 00:00:50,013
So, column one of the software list.

22
00:00:54,810 --> 00:00:56,370
Now, we see this isn't perfect.

23
00:00:56,370 --> 00:00:59,280
There's more options available to make sure

24
00:00:59,280 --> 00:01:01,500
we're not including the header, but you see

25
00:01:01,500 --> 00:01:04,560
that it just data dumps pretty much the entire file

26
00:01:04,560 --> 00:01:05,940
and sorts it from A to Z.

27
00:01:05,940 --> 00:01:09,550
Now, we also do the same thing for the second column

28
00:01:11,310 --> 00:01:15,543
which is going to be pretty much all Ns and a Y.

29
00:01:22,290 --> 00:01:24,960
Next thing we want to do is get some metadata

30
00:01:24,960 --> 00:01:25,860
from this file.

31
00:01:25,860 --> 00:01:28,380
So, we're going to do the word count command.

32
00:01:28,380 --> 00:01:31,440
Now, we're going to do it raw by itself.

33
00:01:31,440 --> 00:01:33,993
So, we're going to use software list3 again.

34
00:01:35,130 --> 00:01:36,570
And if you look at the output,

35
00:01:36,570 --> 00:01:39,960
the first output is the amount of lines in the file,

36
00:01:39,960 --> 00:01:43,020
the second is the amount of words,

37
00:01:43,020 --> 00:01:44,520
and the third is the amount of characters.

38
00:01:44,520 --> 00:01:47,610
Now, this includes all characters, non-printable characters,

39
00:01:47,610 --> 00:01:50,163
anything that the computer uses to process.

40
00:01:51,030 --> 00:01:54,690
So, if we want to see that view so we can see again,

41
00:01:54,690 --> 00:01:59,690
n, software list3, and we see it has 18 lines there,

42
00:02:02,280 --> 00:02:05,040
it's 54 words, 242 characters.

43
00:02:05,040 --> 00:02:07,440
Now again, characters are anything

44
00:02:07,440 --> 00:02:12,360
that's processed by the computer.

45
00:02:12,360 --> 00:02:17,360
So if you look at this display, you'll see that space, tabs,

46
00:02:18,570 --> 00:02:21,180
all these things are characters

47
00:02:21,180 --> 00:02:23,700
and they're encoded to the operating system

48
00:02:23,700 --> 00:02:26,160
so that the computer knows what to do with these things,

49
00:02:26,160 --> 00:02:28,020
how to display that on the screen.

50
00:02:28,020 --> 00:02:29,490
Of course we might not see it,

51
00:02:29,490 --> 00:02:31,800
but this is what the computer sees.

52
00:02:31,800 --> 00:02:34,350
So, all these characters is what's counted

53
00:02:34,350 --> 00:02:36,213
by the word count command.

54
00:02:37,320 --> 00:02:39,240
And again, we can make this very simple

55
00:02:39,240 --> 00:02:40,530
if we just want the word count.

56
00:02:40,530 --> 00:02:44,940
So, we do the w option, software list3 again

57
00:02:44,940 --> 00:02:48,570
and just give us the exact amount of words that we need.

58
00:02:48,570 --> 00:02:49,500
And of course, more options

59
00:02:49,500 --> 00:02:53,160
for lines or characters themselves.

60
00:02:53,160 --> 00:02:54,600
Again, sticking with these same files,

61
00:02:54,600 --> 00:02:58,020
we can also use a command called diff.

62
00:02:58,020 --> 00:03:00,660
So remember, it's going to give us the differentials

63
00:03:00,660 --> 00:03:02,100
between those files.

64
00:03:02,100 --> 00:03:04,410
So, pretty much it's going to let us know which lines

65
00:03:04,410 --> 00:03:06,060
should be added or subtracted

66
00:03:06,060 --> 00:03:09,600
from the first file to match the second file.

67
00:03:09,600 --> 00:03:11,310
So, let's try this out really quick.

68
00:03:11,310 --> 00:03:13,440
So I have a software list I created earlier.

69
00:03:13,440 --> 00:03:16,590
One has less of the software than the other.

70
00:03:16,590 --> 00:03:20,790
So, software list1 is going to have list,

71
00:03:20,790 --> 00:03:22,620
then software list three

72
00:03:22,620 --> 00:03:24,220
'cause I can find these earlier.

73
00:03:26,460 --> 00:03:27,840
And now, what this is telling us

74
00:03:27,840 --> 00:03:32,400
is if you look at the arrows, those arrows pointing

75
00:03:32,400 --> 00:03:35,820
to the right indicate what lines need to be added

76
00:03:35,820 --> 00:03:39,603
to the first file in order to replicate the second file.

77
00:03:40,710 --> 00:03:44,790
So, if you see here, 12, what that means is

78
00:03:44,790 --> 00:03:48,060
after line 12 in software listing one,

79
00:03:48,060 --> 00:03:52,110
add lines 13 through 18 to software listing one

80
00:03:52,110 --> 00:03:54,330
so they can be equivalent.

81
00:03:54,330 --> 00:03:57,090
So again, that's where we've used this cat feature

82
00:03:57,090 --> 00:03:59,310
right with the count

83
00:03:59,310 --> 00:04:02,493
just to verify the correctness of this.

84
00:04:03,570 --> 00:04:05,100
So, we'll see software listing one

85
00:04:05,100 --> 00:04:08,910
has 12 lines and software listing three has 18 lines.

86
00:04:08,910 --> 00:04:11,940
So, it's telling us from lines 13 through 18,

87
00:04:11,940 --> 00:04:15,210
add those to software listing one

88
00:04:15,210 --> 00:04:16,649
in order for them to be equivalent.

89
00:04:16,649 --> 00:04:19,920
Again, this is mostly used when we have a different version

90
00:04:19,920 --> 00:04:21,329
of the same file

91
00:04:21,329 --> 00:04:24,090
and it quickly gives us the differences between the two.

92
00:04:24,090 --> 00:04:26,190
Another command we're going to use is grep.

93
00:04:26,190 --> 00:04:27,420
And we're going to use an example to be able

94
00:04:27,420 --> 00:04:31,230
to pinpoint key information that we would need for a search.

95
00:04:31,230 --> 00:04:34,510
Okay, so we're going to look at this file

96
00:04:36,300 --> 00:04:38,400
and we're going to use the one for the logs,

97
00:04:38,400 --> 00:04:39,840
for the login files.

98
00:04:39,840 --> 00:04:40,673
Okay?

99
00:04:43,470 --> 00:04:46,830
Now we see it gives us a plethora of information,

100
00:04:46,830 --> 00:04:50,790
but sometimes we want to look at specific types of failures

101
00:04:50,790 --> 00:04:54,270
or specific type of errors within a log.

102
00:04:54,270 --> 00:04:58,140
So, we're going to try to look up a failed password attempt.

103
00:04:58,140 --> 00:05:00,970
So, I'm going to try to, I'm going to switch to a user

104
00:05:02,250 --> 00:05:03,480
and I'm going to log in.

105
00:05:03,480 --> 00:05:06,100
I'm going to just try to log in with the wrong password

106
00:05:08,430 --> 00:05:11,370
and I want to pinpoint that in the log.

107
00:05:11,370 --> 00:05:14,010
Okay, so we see you have an authentication failure

108
00:05:14,010 --> 00:05:16,890
when we're trying to log into the ariley account.

109
00:05:16,890 --> 00:05:18,000
So, what we're going to do is we're going

110
00:05:18,000 --> 00:05:21,030
to find this failure in the log.

111
00:05:21,030 --> 00:05:24,780
So, we use the grep failed and we're going to go clear,

112
00:05:24,780 --> 00:05:29,780
log, secure and we can see there towards the bottom

113
00:05:32,160 --> 00:05:35,970
that password check failed for user ariley.

114
00:05:35,970 --> 00:05:40,710
So again, this is a quick way to search through large logs

115
00:05:40,710 --> 00:05:43,410
and get the key information that you need.

116
00:05:43,410 --> 00:05:44,850
Next we're going to go over linking.

117
00:05:44,850 --> 00:05:46,830
Now, there's two ways to do this.

118
00:05:46,830 --> 00:05:50,100
We can either create a hard link from one file to another

119
00:05:50,100 --> 00:05:52,800
or a symbolic link or soft link.

120
00:05:52,800 --> 00:05:54,335
So for example, first thing we want to do,

121
00:05:54,335 --> 00:05:56,580
we're going to make some directories really quick

122
00:05:56,580 --> 00:05:58,803
into the backup folder.

123
00:06:01,470 --> 00:06:02,610
So, we're going to do the backup,

124
00:06:02,610 --> 00:06:07,000
the log, we'll make an authentication one

125
00:06:07,909 --> 00:06:11,043
and we're also going to make up one for just the current year.

126
00:06:14,460 --> 00:06:15,360
All right.

127
00:06:15,360 --> 00:06:16,380
So, we're going to make a copy

128
00:06:16,380 --> 00:06:18,960
of the secure log into our own folder

129
00:06:18,960 --> 00:06:22,020
that we just created in the backup portion.

130
00:06:22,020 --> 00:06:26,477
So, we're going to do sudo copy var log secure.

131
00:06:29,730 --> 00:06:32,703
I want to make sure we put it in our backup log order.

132
00:06:38,430 --> 00:06:39,263
Okay?

133
00:06:42,360 --> 00:06:46,560
Now we're going to go to the backup log, list it out,

134
00:06:46,560 --> 00:06:48,003
make sure that was created.

135
00:06:49,650 --> 00:06:50,734
So, by default without any options,

136
00:06:50,734 --> 00:06:55,734
when you use the link command it's going to create a hard link.

137
00:06:56,100 --> 00:06:57,210
So, let's do that first.

138
00:06:57,210 --> 00:07:00,270
We're going to do the hard link

139
00:07:00,270 --> 00:07:05,270
for the secure folder that we just secure file.

140
00:07:05,450 --> 00:07:06,870
I mean, that we just copied over.

141
00:07:06,870 --> 00:07:11,870
And going to link that to the 2022 secure file.

142
00:07:13,620 --> 00:07:15,480
Now, a hard link again,

143
00:07:15,480 --> 00:07:19,680
is a full copy of the target destination

144
00:07:19,680 --> 00:07:22,770
and a symbolic link is going to be a reference

145
00:07:22,770 --> 00:07:24,900
to that target.

146
00:07:24,900 --> 00:07:26,700
So if that target gets deleted,

147
00:07:26,700 --> 00:07:30,303
then that symbolic link no longer has any information.

148
00:07:31,410 --> 00:07:33,180
Let's just verify that that was created.

149
00:07:33,180 --> 00:07:34,480
So, we're going to do a list.

150
00:07:35,790 --> 00:07:36,993
2022 folder.

151
00:07:39,270 --> 00:07:43,350
And we can see that blue around it indicates

152
00:07:43,350 --> 00:07:44,253
that it's a link.

153
00:07:45,210 --> 00:07:47,477
Now, let's just verify that the secure file

154
00:07:47,477 --> 00:07:49,800
in the authentication folder is the same

155
00:07:49,800 --> 00:07:52,473
as the secure file in the 2022 folder.

156
00:08:01,877 --> 00:08:06,210
We're just going to look at the bottom portion of this.

157
00:08:08,790 --> 00:08:12,480
And do the same thing for the 2022 folder.

158
00:08:12,480 --> 00:08:13,313
Secure file.

159
00:08:18,177 --> 00:08:20,790
And we can see that they're identical.

160
00:08:20,790 --> 00:08:23,340
So, the next thing we want to do to verify this hard link

161
00:08:23,340 --> 00:08:25,500
is we're going to add some information

162
00:08:25,500 --> 00:08:28,680
to the secure file under the authentication folder

163
00:08:28,680 --> 00:08:30,810
and see if it reflects to the secure file

164
00:08:30,810 --> 00:08:32,909
in the 2022 folder.

165
00:08:32,909 --> 00:08:33,750
So, let's do that really quick.

166
00:08:33,750 --> 00:08:34,743
We're going to nano.

167
00:08:45,390 --> 00:08:48,303
Now, we're going to say some simple information like,

168
00:08:52,290 --> 00:08:57,150
use this month, simple enough.

169
00:08:57,150 --> 00:09:00,130
Going to do control O to save this

170
00:09:02,280 --> 00:09:03,780
and then control X to get out.

171
00:09:05,160 --> 00:09:07,380
So, let's verify this really quick by looking

172
00:09:07,380 --> 00:09:12,380
at the first 10 lines of the 2022 folder, the secure file.

173
00:09:15,720 --> 00:09:20,580
And now we see that it has that begin 06, 2022 line

174
00:09:20,580 --> 00:09:22,173
that we input earlier.

175
00:09:23,670 --> 00:09:27,250
Again, just to double check, go to the authentication folder

176
00:09:29,520 --> 00:09:33,240
and we'll see that successfully linked

177
00:09:33,240 --> 00:09:37,500
and remember that these are copies and not just links.

178
00:09:37,500 --> 00:09:39,813
So, we're going to go ahead and remove this file.

179
00:09:42,840 --> 00:09:44,610
Now, we can verify that even

180
00:09:44,610 --> 00:09:47,940
though we deleted the authentication secure file

181
00:09:47,940 --> 00:09:51,180
that the 2022 secure file is still there.

182
00:09:51,180 --> 00:09:52,380
So, let's just list out that folder

183
00:09:52,380 --> 00:09:53,760
just to make sure it's still intact.

184
00:09:53,760 --> 00:09:55,023
The 2022 folder.

185
00:09:56,190 --> 00:09:58,713
Okay, we see our secure file is still intact.

186
00:09:59,610 --> 00:10:01,530
Now we're going to go to our home directory.

187
00:10:01,530 --> 00:10:04,200
Now, this time what we're going to try to do is see

188
00:10:04,200 --> 00:10:05,850
if we can create a link

189
00:10:05,850 --> 00:10:08,640
between the backup file system

190
00:10:08,640 --> 00:10:11,133
and one into our home directory.

191
00:10:12,030 --> 00:10:13,143
We can go sudo link.

192
00:10:18,120 --> 00:10:21,390
And honestly, we should get a error at this point.

193
00:10:21,390 --> 00:10:25,470
Now with hard links, one thing that we have to take account

194
00:10:25,470 --> 00:10:27,690
is the type of file system.

195
00:10:27,690 --> 00:10:30,480
For a symbolic link, we can span different file systems.

196
00:10:30,480 --> 00:10:33,870
For a hard link, these file systems have to be the same.

197
00:10:33,870 --> 00:10:36,570
So, let's check out what the current file systems are.

198
00:10:40,320 --> 00:10:42,060
If you look at the centos root,

199
00:10:42,060 --> 00:10:46,740
so sda2, the root, the mount point, the root folder,

200
00:10:46,740 --> 00:10:49,923
you see the type of file system, it's an XFS.

201
00:10:50,760 --> 00:10:54,030
And the ones we wanted to reference, the backup log,

202
00:10:54,030 --> 00:10:56,310
so look at the mount point all the way to the right

203
00:10:56,310 --> 00:10:58,920
and at the very bottom you'll see the backup log.

204
00:10:58,920 --> 00:11:01,710
The file system type is EXT4.

205
00:11:01,710 --> 00:11:03,360
So, they're incompatible.

206
00:11:03,360 --> 00:11:05,430
So, we will not be able to create a hard link,

207
00:11:05,430 --> 00:11:07,830
but we can create a soft link.

208
00:11:07,830 --> 00:11:09,960
Now we're going to do the same thing,

209
00:11:09,960 --> 00:11:12,243
but again, we're going to create the S option.

210
00:11:15,360 --> 00:11:16,830
And now if we list out our folder,

211
00:11:16,830 --> 00:11:20,013
we see the off auth dash log file as created.

212
00:11:21,570 --> 00:11:22,650
Now we're going to just verify

213
00:11:22,650 --> 00:11:24,960
that that link actually has the information

214
00:11:24,960 --> 00:11:27,273
that we actually want to see from this file.

215
00:11:28,860 --> 00:11:30,180
All right, looks like we have made

216
00:11:30,180 --> 00:11:32,883
a successful symbolic link to that file.

217
00:11:34,170 --> 00:11:36,150
So, here we're going to show the difference

218
00:11:36,150 --> 00:11:39,540
between the hard and soft links

219
00:11:39,540 --> 00:11:43,890
by removing the secure file that's in our 2022

220
00:11:43,890 --> 00:11:47,640
under the backup and see if we're able to still access it

221
00:11:47,640 --> 00:11:50,553
in our off log and our current working directory.

222
00:11:51,810 --> 00:11:52,710
So, let's do that.

223
00:11:57,780 --> 00:11:59,080
All right, that's removed.

224
00:12:00,420 --> 00:12:05,420
Now, let's just try to view the contents of this log.

225
00:12:07,890 --> 00:12:12,120
And we see it says no such file or director exists.

226
00:12:12,120 --> 00:12:14,510
Again, 'cause it's referencing the secure file

227
00:12:14,510 --> 00:12:16,920
in the 2022 folder.

228
00:12:16,920 --> 00:12:20,793
So if we list it out, we'll see we have a broken link.

229
00:12:21,690 --> 00:12:23,440
That's what the flashing indicates.

230
00:12:25,620 --> 00:12:30,330
So again, these soft links reference an existing file.

231
00:12:30,330 --> 00:12:32,130
The hard links create a copy

232
00:12:32,130 --> 00:12:34,440
of the existing file and constantly updates

233
00:12:34,440 --> 00:12:38,820
every time the target file gets updated as well.

234
00:12:38,820 --> 00:12:40,050
This goes for even

235
00:12:40,050 --> 00:12:44,880
if the file name is changed or the location is changed,

236
00:12:44,880 --> 00:12:47,880
the link is not automatically updated .

237
00:12:47,880 --> 00:12:49,380
so you're going to have to go in

238
00:12:49,380 --> 00:12:53,400
and reassociate that link to the new file location

239
00:12:53,400 --> 00:12:54,453
or the new file name.

240
00:12:55,350 --> 00:12:57,060
Let's sum things up.

241
00:12:57,060 --> 00:12:59,640
We went over how to view different files,

242
00:12:59,640 --> 00:13:02,133
sort them out in alphabetical order,

243
00:13:03,030 --> 00:13:05,010
word count, of course getting information

244
00:13:05,010 --> 00:13:07,140
about the amount of lines in the text,

245
00:13:07,140 --> 00:13:10,740
the amount of characters, also the word count as well.

246
00:13:10,740 --> 00:13:13,677
We also went through how to search things with grep.

247
00:13:13,677 --> 00:13:18,540
And also, last but not least, symbolic versus hard linking.

248
00:13:18,540 --> 00:13:20,840
Thank you and I'll see you in the next lesson.

