1
00:00:00,150 --> 00:00:01,230
And we're going to go through

2
00:00:01,230 --> 00:00:03,210
how to manipulate file output.

3
00:00:03,210 --> 00:00:04,200
Typically in Linux,

4
00:00:04,200 --> 00:00:07,710
the standard input is the computer or your mouse.

5
00:00:07,710 --> 00:00:10,398
The standard output is the screen,

6
00:00:10,398 --> 00:00:12,210
but for the command line purposes

7
00:00:12,210 --> 00:00:15,420
it's going to be the display on the CLI.

8
00:00:15,420 --> 00:00:17,490
Now we can change these standard inputs

9
00:00:17,490 --> 00:00:20,610
and outputs using the angle brackets.

10
00:00:20,610 --> 00:00:21,443
For example,

11
00:00:21,443 --> 00:00:22,860
if we're going to use this software

12
00:00:22,860 --> 00:00:24,410
listing that I created earlier,

13
00:00:25,560 --> 00:00:28,260
the standard output is going to be the screen,

14
00:00:28,260 --> 00:00:30,330
the command line interface,

15
00:00:30,330 --> 00:00:35,330
but I can use the same output, and put it in another file.

16
00:00:35,550 --> 00:00:39,060
So we can do software listing one, right.

17
00:00:39,060 --> 00:00:41,190
And the output, we're going to use the right angle bracket.

18
00:00:41,190 --> 00:00:42,023
We want to let it know, hey,

19
00:00:42,023 --> 00:00:45,483
we want to send the output to this test file.

20
00:00:49,830 --> 00:00:52,863
Now, if we look and we see the test file's created,

21
00:00:53,760 --> 00:00:55,410
and we try to view the test file,

22
00:00:56,700 --> 00:00:58,800
we'll see it copy right over for us.

23
00:00:58,800 --> 00:01:02,430
So using the angle bracket to the right,

24
00:01:02,430 --> 00:01:06,090
it replaces what's in that new file,

25
00:01:06,090 --> 00:01:09,000
or creates a file if it doesn't already exist.

26
00:01:09,000 --> 00:01:11,340
Now, if you want to add something to it,

27
00:01:11,340 --> 00:01:12,780
we can use the echo command.

28
00:01:12,780 --> 00:01:14,430
If you want to add specific strings.

29
00:01:14,430 --> 00:01:18,843
So let's say we're going to test.

30
00:01:30,390 --> 00:01:32,370
And now let's do this again.

31
00:01:32,370 --> 00:01:35,040
Now you see it appended the new text

32
00:01:35,040 --> 00:01:36,990
to the bottom of the file.

33
00:01:36,990 --> 00:01:38,640
So it's very important to realize

34
00:01:38,640 --> 00:01:40,500
if you want to add information,

35
00:01:40,500 --> 00:01:43,950
you have to use two angle brackets versus one,

36
00:01:43,950 --> 00:01:45,930
'cause one will replace everything.

37
00:01:45,930 --> 00:01:47,430
So just to use a more clean example,

38
00:01:47,430 --> 00:01:49,120
just say we want to create a file

39
00:01:50,055 --> 00:01:53,790
and we want to have it insert information about the user,

40
00:01:56,340 --> 00:02:00,033
a make of a computer, and the serial number.

41
00:02:02,610 --> 00:02:05,643
And again, we want to add this to, call it testfile2.

42
00:02:09,449 --> 00:02:10,282
Okay.

43
00:02:10,282 --> 00:02:11,116
Now again,

44
00:02:11,116 --> 00:02:15,720
we're going to view this using cat, test,

45
00:02:15,720 --> 00:02:20,673
we did a tab key, and we see it input it to the file.

46
00:02:21,660 --> 00:02:24,300
So again, this operator is very useful.

47
00:02:24,300 --> 00:02:27,480
You don't always have to use a text editor like VIM or Nano,

48
00:02:27,480 --> 00:02:29,400
what you can do is type directly

49
00:02:29,400 --> 00:02:31,350
on the screen it's something quick,

50
00:02:31,350 --> 00:02:34,440
use the right angle bracket operator

51
00:02:34,440 --> 00:02:36,000
or the double one if you want to append it.

52
00:02:36,000 --> 00:02:36,833
Remember,

53
00:02:36,833 --> 00:02:39,630
a single right bracket operator is going to erase

54
00:02:39,630 --> 00:02:42,330
the contents of a file and replace them with your own.

55
00:02:44,160 --> 00:02:45,393
So let's test this out.

56
00:02:51,570 --> 00:02:56,223
Same thing, USER1, MAKE1, serial number one.

57
00:02:58,410 --> 00:03:00,960
Now when we look at the contents of this file

58
00:03:00,960 --> 00:03:03,003
we'll see that it's replaced.

59
00:03:04,290 --> 00:03:05,540
But if we want to add it,

60
00:03:09,030 --> 00:03:14,030
operator, do it again, now added it.

61
00:03:14,100 --> 00:03:14,933
Again,

62
00:03:14,933 --> 00:03:17,070
that's just another example to further demonstrate

63
00:03:17,070 --> 00:03:20,460
the use of the right angle bracket operator.

64
00:03:20,460 --> 00:03:23,280
Now, next we're going to use the translate command.

65
00:03:23,280 --> 00:03:25,470
Now this command is going to be used to translate

66
00:03:25,470 --> 00:03:27,270
one character to another,

67
00:03:27,270 --> 00:03:31,320
and we're going to use it with the left angle bracket operator.

68
00:03:31,320 --> 00:03:32,153
Okay?

69
00:03:32,153 --> 00:03:33,720
So we're going to just, again,

70
00:03:33,720 --> 00:03:35,820
we're going to look at our test file in here.

71
00:03:37,470 --> 00:03:38,343
Let's see here.

72
00:03:40,320 --> 00:03:41,373
Do test file two.

73
00:03:43,230 --> 00:03:44,063
Okay.

74
00:03:44,063 --> 00:03:45,750
So we see we have this information in there.

75
00:03:45,750 --> 00:03:47,340
So just say we wanted to change

76
00:03:47,340 --> 00:03:50,100
all the Us to lowercase Us.

77
00:03:50,100 --> 00:03:52,683
So we're going to do, translate here,

78
00:03:54,300 --> 00:03:58,260
and the first character's going to be one to be replaced.

79
00:03:58,260 --> 00:03:59,640
So all uppercase Us,

80
00:03:59,640 --> 00:04:02,250
and we'll change it to lowercase Us.

81
00:04:02,250 --> 00:04:05,287
And we're going to do that for our testfile2.txt.

82
00:04:09,450 --> 00:04:12,660
And we can see that now it output the result

83
00:04:12,660 --> 00:04:15,993
showing that the users now have a lowercase Us.

84
00:04:17,940 --> 00:04:19,230
So again, we can do the same thing.

85
00:04:19,230 --> 00:04:23,043
Just to make it a little weird for the uppercase Ms,

86
00:04:24,180 --> 00:04:25,630
change those to lowercase Ms.

87
00:04:27,480 --> 00:04:28,313
And again,

88
00:04:28,313 --> 00:04:29,670
these files are usually used to change things

89
00:04:29,670 --> 00:04:31,350
from lowercase to uppercase.

90
00:04:31,350 --> 00:04:33,810
But again, you see, this is just showing the output,

91
00:04:33,810 --> 00:04:35,100
and it's not actually changing

92
00:04:35,100 --> 00:04:38,730
the content of the test file itself.

93
00:04:38,730 --> 00:04:41,250
Now just say sticking to this same example that we did,

94
00:04:41,250 --> 00:04:44,850
want to change the output and put it in another file.

95
00:04:44,850 --> 00:04:46,530
We can do that same thing.

96
00:04:46,530 --> 00:04:50,640
So again, we want to translate the Us,

97
00:04:50,640 --> 00:04:53,103
or the uppercase Us, to lowercase Us.

98
00:04:54,108 --> 00:04:57,483
And the file we want to use is testfile,

99
00:05:01,170 --> 00:05:04,380
and we want to put it in another file.

100
00:05:04,380 --> 00:05:06,033
We're going to name this testfile3.

101
00:05:11,490 --> 00:05:14,670
Now we'll see the output is changed,

102
00:05:14,670 --> 00:05:19,143
and "saves" because it is sent to another file.

103
00:05:23,490 --> 00:05:24,323
Okay.

104
00:05:25,500 --> 00:05:28,986
Again, you'll see the contents of the first file,

105
00:05:28,986 --> 00:05:31,950
testfile2 remains the same.

106
00:05:31,950 --> 00:05:34,260
But we can change that information

107
00:05:34,260 --> 00:05:36,993
and send it to be saved to another file.

108
00:05:38,460 --> 00:05:39,390
So again, once we read it,

109
00:05:39,390 --> 00:05:40,830
if you're looking at the command

110
00:05:40,830 --> 00:05:42,181
we're reading it from left to right,

111
00:05:42,181 --> 00:05:44,070
so we're going to translate the uppercase Us

112
00:05:44,070 --> 00:05:47,223
to lowercase Us in the text file number two,

113
00:05:48,060 --> 00:05:50,463
and send it to test file number three.

114
00:05:51,930 --> 00:05:54,180
So next one I'll work on another file that I created,

115
00:05:54,180 --> 00:05:57,750
this computer lists of users, operating system,

116
00:05:57,750 --> 00:05:59,250
and the make of the computers.

117
00:06:00,210 --> 00:06:02,190
What we're going to do is, I want to sort them really quick.

118
00:06:02,190 --> 00:06:03,870
We're just going to show the output,

119
00:06:03,870 --> 00:06:05,640
and see how we can change the standard

120
00:06:05,640 --> 00:06:07,440
input and output with these as well.

121
00:06:09,420 --> 00:06:10,253
Okay.

122
00:06:10,253 --> 00:06:12,330
So we see that on the first column

123
00:06:12,330 --> 00:06:15,090
it sorted the object in alphabetical order.

124
00:06:15,090 --> 00:06:18,476
Now, again, we see that the header was included,

125
00:06:18,476 --> 00:06:20,550
but we're going to use another example

126
00:06:20,550 --> 00:06:22,620
where the header is not included.

127
00:06:22,620 --> 00:06:24,360
So the name will stay at the top,

128
00:06:24,360 --> 00:06:27,450
and it will sort all the actual fields below.

129
00:06:27,450 --> 00:06:28,920
Now, to do that,

130
00:06:28,920 --> 00:06:31,350
we're going to use the piping command.

131
00:06:31,350 --> 00:06:33,360
So what that does is it redirects

132
00:06:33,360 --> 00:06:37,560
the output from one into another.

133
00:06:37,560 --> 00:06:42,560
So we're going to use the tail, use -n,

134
00:06:42,810 --> 00:06:45,183
so the number of lines, plus three.

135
00:06:46,380 --> 00:06:48,090
So we're going to specify this.

136
00:06:48,090 --> 00:06:51,060
And we're going to use the computer text file.

137
00:06:51,060 --> 00:06:54,633
So that output, we're going to sort that output.

138
00:06:55,770 --> 00:06:56,970
On the first column,

139
00:06:56,970 --> 00:06:59,320
so prior we have the name title

140
00:07:00,330 --> 00:07:02,610
associated with the fields below,

141
00:07:02,610 --> 00:07:04,680
but now it's no longer there.

142
00:07:04,680 --> 00:07:06,630
So again, reading that command from left to right,

143
00:07:06,630 --> 00:07:09,960
you'll see that we're only going to see the bottom 10,

144
00:07:09,960 --> 00:07:11,160
and we're not really concerned about that

145
00:07:11,160 --> 00:07:13,590
because we have less than 10 in here.

146
00:07:13,590 --> 00:07:17,100
The number of lines is going to be the top three, right?

147
00:07:17,100 --> 00:07:20,520
So that means we're going to include line three and below only.

148
00:07:20,520 --> 00:07:23,643
So again, if we were just to capture this out,

149
00:07:24,630 --> 00:07:27,240
we'll see the number of lines

150
00:07:27,240 --> 00:07:29,820
'cause I think it's very useful to see that,

151
00:07:29,820 --> 00:07:31,773
and then run the sort again.

152
00:07:33,720 --> 00:07:36,210
We can see that it started with line three.

153
00:07:36,210 --> 00:07:38,190
So you see John is included

154
00:07:38,190 --> 00:07:41,010
in this result, and it went down.

155
00:07:41,010 --> 00:07:44,133
And we sorted everything with column one.

156
00:07:45,090 --> 00:07:47,220
Next we're going to use the T command.

157
00:07:47,220 --> 00:07:52,140
Now the T command simply does an output redirect

158
00:07:52,140 --> 00:07:56,640
to a file or directory, but also displays it on the screen.

159
00:07:56,640 --> 00:07:57,960
So you could have both.

160
00:07:57,960 --> 00:08:02,820
And you can see what is being sent to the particular file.

161
00:08:02,820 --> 00:08:05,160
So earlier when we used the echo command,

162
00:08:05,160 --> 00:08:08,400
it didn't show us what it actually sent to the file,

163
00:08:08,400 --> 00:08:09,450
but with the T command,

164
00:08:09,450 --> 00:08:11,820
it's going to show us what it sent to the file.

165
00:08:11,820 --> 00:08:13,980
So for this example we're just going to show

166
00:08:13,980 --> 00:08:16,173
the list of files in this folder.

167
00:08:17,400 --> 00:08:20,823
And we're going to just want to copy that list in this folder,

168
00:08:21,690 --> 00:08:25,530
and we're going to send it to another folder

169
00:08:25,530 --> 00:08:29,757
that we're going to name, backup directory.

170
00:08:34,980 --> 00:08:35,909
Now it's letting us know,

171
00:08:35,909 --> 00:08:40,909
we sent the list from this directory to backup directory,

172
00:08:41,190 --> 00:08:43,500
and this is what it looks like.

173
00:08:43,500 --> 00:08:47,373
So if we do a cat, backup directory,

174
00:08:48,240 --> 00:08:51,840
we see the display starting from here.

175
00:08:51,840 --> 00:08:52,673
So again,

176
00:08:52,673 --> 00:08:55,650
it does nothing more than just show us at the same time,

177
00:08:55,650 --> 00:08:58,702
it redirects it to a particular file.

178
00:08:58,702 --> 00:08:59,580
And the last thing I'm going to go over

179
00:08:59,580 --> 00:09:03,663
is how to pipe grep and cut, and use those together.

180
00:09:04,530 --> 00:09:06,480
So we're going to check our secure file

181
00:09:06,480 --> 00:09:08,580
and that pretty much stores all

182
00:09:08,580 --> 00:09:10,920
of our authentication attempts.

183
00:09:10,920 --> 00:09:12,180
So we're going to pull out some

184
00:09:12,180 --> 00:09:15,120
of the information after we've searched through the file

185
00:09:15,120 --> 00:09:18,420
for a particular type of error that we're looking for.

186
00:09:18,420 --> 00:09:22,890
So we're going to find a password check fail,

187
00:09:22,890 --> 00:09:24,480
and then we're going to condense the information,

188
00:09:24,480 --> 00:09:25,590
'cause we don't need everything

189
00:09:25,590 --> 00:09:27,303
that's going to be presented to us.

190
00:09:28,530 --> 00:09:31,953
So for example, we're going to look at the file,

191
00:09:35,340 --> 00:09:37,800
and we see that it gets us a lot of information,

192
00:09:37,800 --> 00:09:39,780
and some of them might be unnecessary

193
00:09:39,780 --> 00:09:41,820
for what we're looking for,

194
00:09:41,820 --> 00:09:43,740
so we're going to condense that.

195
00:09:43,740 --> 00:09:44,675
So the first thing we want to do is,

196
00:09:44,675 --> 00:09:46,110
we're going to do sudo, we're going to grep,

197
00:09:46,110 --> 00:09:46,950
we're going to search through this.

198
00:09:46,950 --> 00:09:51,003
We want to look for password check, the fail.

199
00:09:54,630 --> 00:09:56,943
We'll look in the var/log/secure,

200
00:10:03,120 --> 00:10:05,280
and we see it returns only the instances

201
00:10:05,280 --> 00:10:07,023
of a failed password attempt.

202
00:10:12,330 --> 00:10:13,230
All right.

203
00:10:13,230 --> 00:10:14,790
Now, we don't need all this information,

204
00:10:14,790 --> 00:10:17,310
so what we're going to do is cut some of this.

205
00:10:17,310 --> 00:10:19,980
And so that's where we're going to use the cut command.

206
00:10:19,980 --> 00:10:22,230
And so I'm going to show what it does by itself.

207
00:10:22,230 --> 00:10:27,230
Going to sudo cut, var/log/secure.

208
00:10:30,510 --> 00:10:32,580
And this D is the delimiter that we're going to use.

209
00:10:32,580 --> 00:10:35,670
So the delimiter that we're going to use is a space.

210
00:10:35,670 --> 00:10:39,180
Delimiter meaning just something that separates fields,

211
00:10:39,180 --> 00:10:40,500
or just say in the English language,

212
00:10:40,500 --> 00:10:42,240
a space separates words.

213
00:10:42,240 --> 00:10:43,920
So for this search that we're going to

214
00:10:43,920 --> 00:10:45,840
use the delimiter, it's going to be the space.

215
00:10:45,840 --> 00:10:47,700
So pretty much what's going to let us indicate

216
00:10:47,700 --> 00:10:51,453
is which fields that we want to specify for the result.

217
00:10:52,890 --> 00:10:53,820
So in this example,

218
00:10:53,820 --> 00:10:57,660
we're going to specify fields five through 12.

219
00:10:57,660 --> 00:10:59,550
And the fields again,

220
00:10:59,550 --> 00:11:01,893
are associated with the spaces in between.

221
00:11:03,840 --> 00:11:07,200
So now I cut off some of the beginning, and most of the end.

222
00:11:07,200 --> 00:11:09,903
So we see that it's a better look for us.

223
00:11:11,640 --> 00:11:13,800
Now let's combine those together.

224
00:11:13,800 --> 00:11:16,002
So we're going to make a smaller output.

225
00:11:16,002 --> 00:11:19,680
So we're going to do, sudo grep, new password,

226
00:11:19,680 --> 00:11:21,900
again, that's what we're looking for.

227
00:11:21,900 --> 00:11:24,803
Check failed for our log secure file.

228
00:11:30,870 --> 00:11:33,330
Now again, now we're going to pipe this.

229
00:11:33,330 --> 00:11:37,530
So pretty much send that information to the cut command,

230
00:11:37,530 --> 00:11:40,743
and the cut command is going to look for spaces,

231
00:11:42,420 --> 00:11:47,420
and is going to use fields five through 12 for the return.

232
00:11:51,180 --> 00:11:52,013
Now look at that,

233
00:11:52,013 --> 00:11:56,040
a much more clean output for exactly what we're looking for.

234
00:11:56,040 --> 00:11:59,220
All right, we went over how to use the echo command,

235
00:11:59,220 --> 00:12:01,620
and use the right bracket angle operator

236
00:12:01,620 --> 00:12:03,630
to send information to a file.

237
00:12:03,630 --> 00:12:05,760
The left angle bracket operator to send

238
00:12:05,760 --> 00:12:07,980
that input to another command.

239
00:12:07,980 --> 00:12:09,810
We also went through how to translate

240
00:12:09,810 --> 00:12:12,510
a few files using the uppercase lowercase.

241
00:12:12,510 --> 00:12:15,120
And how to condense information using the cut.

242
00:12:15,120 --> 00:12:17,760
And how to show our redirection,

243
00:12:17,760 --> 00:12:19,830
the output that is being sent

244
00:12:19,830 --> 00:12:22,290
to the file using the T command.

245
00:12:22,290 --> 00:12:24,090
And I'll see you in the next lesson.

