1
00:00:00,570 --> 00:00:01,589
In this lesson,

2
00:00:01,589 --> 00:00:03,960
we're going to discuss how you conduct operations

3
00:00:03,960 --> 00:00:05,700
on different files and directories

4
00:00:05,700 --> 00:00:07,410
within the Linux operating system

5
00:00:07,410 --> 00:00:09,420
using some basic commands.

6
00:00:09,420 --> 00:00:11,670
First, we're going to talk about cat.

7
00:00:11,670 --> 00:00:14,130
Now, cat is short for concatenate.

8
00:00:14,130 --> 00:00:16,079
This can actually display, combine,

9
00:00:16,079 --> 00:00:18,120
or create text files for you.

10
00:00:18,120 --> 00:00:20,730
Cat is most frequently used to display the contents

11
00:00:20,730 --> 00:00:22,380
of small text files.

12
00:00:22,380 --> 00:00:23,370
Now, keep in mind,

13
00:00:23,370 --> 00:00:26,250
cat does not have a screen scrolling capability.

14
00:00:26,250 --> 00:00:28,710
Instead, it's just going to keep going over and over again

15
00:00:28,710 --> 00:00:31,200
until it shows all of the file on the screen

16
00:00:31,200 --> 00:00:34,350
and so things can go way off your screen pretty quickly.

17
00:00:34,350 --> 00:00:36,120
Now there are some options available to use

18
00:00:36,120 --> 00:00:37,350
with the cat command.

19
00:00:37,350 --> 00:00:38,880
If you use dash N,

20
00:00:38,880 --> 00:00:40,650
this will actually show the line numbers

21
00:00:40,650 --> 00:00:42,330
in front of the output.

22
00:00:42,330 --> 00:00:43,890
If you use dash B,

23
00:00:43,890 --> 00:00:45,900
this will be actually used to number the lines,

24
00:00:45,900 --> 00:00:48,090
excluding any blank lines.

25
00:00:48,090 --> 00:00:49,650
If you use dash S,

26
00:00:49,650 --> 00:00:52,980
this will suppress output of any repeated empty lines.

27
00:00:52,980 --> 00:00:55,380
And option dash V is used to display

28
00:00:55,380 --> 00:00:56,850
non-printable characters,

29
00:00:56,850 --> 00:00:59,310
such as visible characters other than tabs,

30
00:00:59,310 --> 00:01:01,650
new lines, and form feeds.

31
00:01:01,650 --> 00:01:03,630
If you use the option dash E,

32
00:01:03,630 --> 00:01:06,270
you're going to actually create a dollar sign character printed

33
00:01:06,270 --> 00:01:08,010
at the end of each line.

34
00:01:08,010 --> 00:01:09,180
And if you use dash T,

35
00:01:09,180 --> 00:01:10,800
it's going to print out the tabs

36
00:01:10,800 --> 00:01:15,660
either as a carrot I or a carrot L if it's a form feed.

37
00:01:15,660 --> 00:01:16,890
To run the cat command,

38
00:01:16,890 --> 00:01:20,580
simply type in cat, the options, and the file name.

39
00:01:20,580 --> 00:01:23,370
Now, the next command we're going to talk about is head.

40
00:01:23,370 --> 00:01:24,720
Head is a command that displays

41
00:01:24,720 --> 00:01:27,480
only the first 10 lines of each file.

42
00:01:27,480 --> 00:01:30,090
Similarly, we have a command known as tail,

43
00:01:30,090 --> 00:01:33,600
and tail will show us the last 10 lines of each file.

44
00:01:33,600 --> 00:01:35,430
These commands are really useful

45
00:01:35,430 --> 00:01:38,640
if you only need to see the beginning or ending of a file.

46
00:01:38,640 --> 00:01:40,380
Now, why might you do this?

47
00:01:40,380 --> 00:01:42,960
Well, let's say you want to check a recent log entry

48
00:01:42,960 --> 00:01:45,570
by viewing the last 10 lines of the log file.

49
00:01:45,570 --> 00:01:48,180
You can simply run the head or tail command

50
00:01:48,180 --> 00:01:51,990
by typing in head or tail, the options, and the file name.

51
00:01:51,990 --> 00:01:54,900
The tail command has two commonly used options.

52
00:01:54,900 --> 00:01:57,120
The first one is dash F.

53
00:01:57,120 --> 00:01:59,730
Dash F will dynamically watch a file

54
00:01:59,730 --> 00:02:02,310
and it'll output will automatically update on the screen

55
00:02:02,310 --> 00:02:04,380
whenever that file changes.

56
00:02:04,380 --> 00:02:06,570
The dash N option will allow us to control

57
00:02:06,570 --> 00:02:08,940
how many lines are actually being displayed.

58
00:02:08,940 --> 00:02:11,009
So if I type in dash N five,

59
00:02:11,009 --> 00:02:12,870
I'll only see the last five lines

60
00:02:12,870 --> 00:02:16,170
of a file instead of the 10 that's used by default.

61
00:02:16,170 --> 00:02:18,930
Now, the dash F option only works in tail,

62
00:02:18,930 --> 00:02:21,480
but the dash N option where you can specify the number

63
00:02:21,480 --> 00:02:25,590
of lines to display, will work in both head and tail.

64
00:02:25,590 --> 00:02:27,450
Now, there's two more commands that I want to talk

65
00:02:27,450 --> 00:02:30,420
about here when it comes to displaying files to your screen

66
00:02:30,420 --> 00:02:33,030
and these are known as less and more.

67
00:02:33,030 --> 00:02:35,220
Both the less and more commands are similar

68
00:02:35,220 --> 00:02:37,680
in a way that they enable you to display the contents

69
00:02:37,680 --> 00:02:41,460
of a file and page through those one screen at a time.

70
00:02:41,460 --> 00:02:43,710
The less command has some additional features

71
00:02:43,710 --> 00:02:44,760
that more doesn't,

72
00:02:44,760 --> 00:02:46,650
but newer versions of more have added

73
00:02:46,650 --> 00:02:49,830
a lot of those features too, making them pretty similar.

74
00:02:49,830 --> 00:02:52,020
While you're free to use either command you want,

75
00:02:52,020 --> 00:02:54,930
the less command is generally used by most people.

76
00:02:54,930 --> 00:02:56,820
You can run the less or more command

77
00:02:56,820 --> 00:02:58,680
by simply typing less or more,

78
00:02:58,680 --> 00:03:00,810
the options, and the file name.

79
00:03:00,810 --> 00:03:03,000
There's also some common less command options

80
00:03:03,000 --> 00:03:04,710
that you might want to be familiar with.

81
00:03:04,710 --> 00:03:06,120
Things like dash E,

82
00:03:06,120 --> 00:03:07,740
which is used to exit the program

83
00:03:07,740 --> 00:03:10,350
the second time it reaches the end of the file.

84
00:03:10,350 --> 00:03:13,380
The dash capital E option will be used to exit the program

85
00:03:13,380 --> 00:03:15,960
the first time it reaches the end of the file.

86
00:03:15,960 --> 00:03:17,730
If you use dash capital I,

87
00:03:17,730 --> 00:03:20,340
it'll ignore case inside of your searches.

88
00:03:20,340 --> 00:03:21,690
And if you use dash N,

89
00:03:21,690 --> 00:03:24,480
it'll suppress any line numbers in the file.

90
00:03:24,480 --> 00:03:26,430
Navigation and less uses many

91
00:03:26,430 --> 00:03:28,410
of the same commands you've seen before.

92
00:03:28,410 --> 00:03:30,690
things like the arrow keys to scroll up one line

93
00:03:30,690 --> 00:03:33,180
at a time or down one line at a time,

94
00:03:33,180 --> 00:03:36,900
or page up or page down to scroll a page at a time.

95
00:03:36,900 --> 00:03:39,090
You can also use the forward slash character to

96
00:03:39,090 --> 00:03:41,430
search a file for a particular text string.

97
00:03:41,430 --> 00:03:43,710
And if you press N or capital N,

98
00:03:43,710 --> 00:03:46,200
you can move to the next or previous instance

99
00:03:46,200 --> 00:03:48,450
of a search string respectively.

100
00:03:48,450 --> 00:03:52,020
When you're done, just press Q to quit the program.

101
00:03:52,020 --> 00:03:55,110
Another command that's really important is the copy command.

102
00:03:55,110 --> 00:03:57,630
The CP command enables you to copy

103
00:03:57,630 --> 00:04:00,690
and then paste a file or directory someplace else.

104
00:04:00,690 --> 00:04:02,880
The initial object, that file or directory,

105
00:04:02,880 --> 00:04:04,200
will be left where it is,

106
00:04:04,200 --> 00:04:06,660
but an exact duplicate of that object,

107
00:04:06,660 --> 00:04:07,980
that file or directory,

108
00:04:07,980 --> 00:04:10,950
will be created at the destination you specify.

109
00:04:10,950 --> 00:04:12,510
When you're copying directories,

110
00:04:12,510 --> 00:04:15,960
you may want to specify the dash capital R option.

111
00:04:15,960 --> 00:04:19,079
This will copy the directory recursively with everything

112
00:04:19,079 --> 00:04:21,000
underneath it going as well.

113
00:04:21,000 --> 00:04:24,660
To run this command, simply type CP, your options,

114
00:04:24,660 --> 00:04:26,940
and the file or directory name that you're going to copy

115
00:04:26,940 --> 00:04:29,940
and the file or directory name you are going to put it to.

116
00:04:29,940 --> 00:04:30,900
For example,

117
00:04:30,900 --> 00:04:34,110
let's say I wanted to copy the my files directory

118
00:04:34,110 --> 00:04:35,550
and put its contents into the

119
00:04:35,550 --> 00:04:38,850
slash OPT slash my files directory.

120
00:04:38,850 --> 00:04:42,630
I would do this by typing CP dash capital R

121
00:04:42,630 --> 00:04:47,630
tilde slash my files slash OPT slash my files.

122
00:04:48,060 --> 00:04:49,260
If you want to move files

123
00:04:49,260 --> 00:04:52,680
or directories to another location instead of copying them,

124
00:04:52,680 --> 00:04:54,840
you can do this using the move command,

125
00:04:54,840 --> 00:04:57,180
which is written as MV.

126
00:04:57,180 --> 00:04:59,430
MV is similar to the copy command,

127
00:04:59,430 --> 00:05:01,920
but it doesn't leave the initial object,

128
00:05:01,920 --> 00:05:04,380
that file or directory, in place.

129
00:05:04,380 --> 00:05:07,710
Instead, move is more like a cut and paste operation

130
00:05:07,710 --> 00:05:10,320
instead of a copy and paste operation.

131
00:05:10,320 --> 00:05:12,300
The bash shell itself does not have

132
00:05:12,300 --> 00:05:14,820
a dedicated rename command, but instead,

133
00:05:14,820 --> 00:05:17,790
we use the move command to do that function.

134
00:05:17,790 --> 00:05:19,830
The act of moving a file or directory and

135
00:05:19,830 --> 00:05:23,160
supplying a new name is essentially the same as renaming

136
00:05:23,160 --> 00:05:24,750
that file or directory.

137
00:05:24,750 --> 00:05:28,290
The proper way to run the move command is to type move,

138
00:05:28,290 --> 00:05:31,110
the options, the filer directory name to move,

139
00:05:31,110 --> 00:05:33,720
and the file or directory name's destination.

140
00:05:33,720 --> 00:05:36,510
For example, let's say I wanted to move something

141
00:05:36,510 --> 00:05:41,510
from tilde slash file one to slash OPT slash file one.

142
00:05:41,670 --> 00:05:45,840
I can do this by typing MV tilde slash file one

143
00:05:45,840 --> 00:05:49,110
slash OPT slash file one.

144
00:05:49,110 --> 00:05:50,970
When you wish to rename a file,

145
00:05:50,970 --> 00:05:54,240
you can do this by simply typing MV, your options,

146
00:05:54,240 --> 00:05:56,400
the old name, and then the new name.

147
00:05:56,400 --> 00:05:59,310
So, if I wanted to change file one to file two,

148
00:05:59,310 --> 00:06:03,180
I can just type MV file one file two

149
00:06:03,180 --> 00:06:06,570
and it will change file one to become file two.

150
00:06:06,570 --> 00:06:08,100
The next command we're going to talk about

151
00:06:08,100 --> 00:06:09,540
is the touch command.

152
00:06:09,540 --> 00:06:11,520
Now, the touch command is used when you need to

153
00:06:11,520 --> 00:06:14,100
test permissions or simply create files that are

154
00:06:14,100 --> 00:06:16,500
going to be processed by some application.

155
00:06:16,500 --> 00:06:17,730
The touch command is available

156
00:06:17,730 --> 00:06:19,950
in most distributions in Linux.

157
00:06:19,950 --> 00:06:22,080
Touch is going to change the time of access

158
00:06:22,080 --> 00:06:25,470
or the modification time of a file to the current time

159
00:06:25,470 --> 00:06:27,900
or you can use it to actually specify

160
00:06:27,900 --> 00:06:30,390
the time inside of an argument.

161
00:06:30,390 --> 00:06:32,760
Touch is also used to create an empty file

162
00:06:32,760 --> 00:06:34,350
with a specified file name,

163
00:06:34,350 --> 00:06:37,140
assuming that that file doesn't already exist.

164
00:06:37,140 --> 00:06:40,380
To do this, we just type touch and the file name.

165
00:06:40,380 --> 00:06:42,330
When you do this, if the file doesn't exist,

166
00:06:42,330 --> 00:06:43,740
a new one will be created.

167
00:06:43,740 --> 00:06:45,030
If one already exists,

168
00:06:45,030 --> 00:06:48,960
it will update its last access time to the current time.

169
00:06:48,960 --> 00:06:51,870
Another command we have is the remove command.

170
00:06:51,870 --> 00:06:54,540
The remove command is written as RM.

171
00:06:54,540 --> 00:06:57,690
The remove command will remove files and directories.

172
00:06:57,690 --> 00:06:59,550
If you want to do this recursively,

173
00:06:59,550 --> 00:07:02,160
you're going to use the dash capital R option

174
00:07:02,160 --> 00:07:04,980
and this will recursively remove files, sub directories,

175
00:07:04,980 --> 00:07:07,050
and the parent directory itself.

176
00:07:07,050 --> 00:07:09,570
The proper way to run the remove command is to type

177
00:07:09,570 --> 00:07:12,930
remove, the options, and the file or directory name.

178
00:07:12,930 --> 00:07:14,730
So let's say I wanted to remove the

179
00:07:14,730 --> 00:07:18,840
tilde slash my files directory and all of its contents.

180
00:07:18,840 --> 00:07:22,290
I can do that by typing RM dash capital R

181
00:07:22,290 --> 00:07:24,600
tilde slash my files.

182
00:07:24,600 --> 00:07:26,010
There's also going to be times when you

183
00:07:26,010 --> 00:07:28,590
need to remove files but not directories

184
00:07:28,590 --> 00:07:31,380
and you can do this using the unlink command.

185
00:07:31,380 --> 00:07:32,880
When you use the unlink command,

186
00:07:32,880 --> 00:07:35,640
it's very similar to using the remove command.

187
00:07:35,640 --> 00:07:36,810
Now, at this point,

188
00:07:36,810 --> 00:07:38,460
you have seen much of the power

189
00:07:38,460 --> 00:07:40,950
of the LS or list command that we've done to

190
00:07:40,950 --> 00:07:42,630
list the contents of directories

191
00:07:42,630 --> 00:07:44,340
as well as their permissions information

192
00:07:44,340 --> 00:07:47,490
of directories and files when we talked about users, groups,

193
00:07:47,490 --> 00:07:49,440
and permissions earlier in the course.

194
00:07:49,440 --> 00:07:51,150
Now, there are a lot of useful options

195
00:07:51,150 --> 00:07:52,920
when you're using the LS command.

196
00:07:52,920 --> 00:07:55,410
Let's cover a few of these key options.

197
00:07:55,410 --> 00:07:57,690
The first one is dash L.

198
00:07:57,690 --> 00:08:00,960
If you use dash L, this is going to display a long list,

199
00:08:00,960 --> 00:08:03,690
including the permissions, the number of hard links,

200
00:08:03,690 --> 00:08:07,140
the owner, the groups, the size, the date,

201
00:08:07,140 --> 00:08:10,440
and the file name all for you right there on the screen.

202
00:08:10,440 --> 00:08:12,210
If you use dash F,

203
00:08:12,210 --> 00:08:14,790
this is going to be used to display the nature of a file,

204
00:08:14,790 --> 00:08:17,490
basically telling you is it an executable file

205
00:08:17,490 --> 00:08:20,520
and slash if it's going to be a directory.

206
00:08:20,520 --> 00:08:22,440
If you have the dash A option,

207
00:08:22,440 --> 00:08:24,150
this is going to display all the files

208
00:08:24,150 --> 00:08:25,680
in the present directory,

209
00:08:25,680 --> 00:08:28,350
including the files whose names begin with a period,

210
00:08:28,350 --> 00:08:30,240
which is a hidden file.

211
00:08:30,240 --> 00:08:32,460
If you use the dash capital R option,

212
00:08:32,460 --> 00:08:34,890
this'll recursively display all the sub directories

213
00:08:34,890 --> 00:08:37,080
as well as the present directory.

214
00:08:37,080 --> 00:08:38,549
If you use dash D,

215
00:08:38,549 --> 00:08:39,809
it'll display information

216
00:08:39,809 --> 00:08:41,909
about symbolic links or directories

217
00:08:41,909 --> 00:08:43,289
rather than the link's target

218
00:08:43,289 --> 00:08:45,480
or the contents of that directory.

219
00:08:45,480 --> 00:08:47,700
And if you use the dash capital L,

220
00:08:47,700 --> 00:08:50,010
it'll display all the files in the directory,

221
00:08:50,010 --> 00:08:52,170
including your symbolic links.

222
00:08:52,170 --> 00:08:53,670
To run the LS command,

223
00:08:53,670 --> 00:08:57,600
you'll type LS, the options, and the file or directory name.

224
00:08:57,600 --> 00:09:00,270
Normally, when I execute the LS command,

225
00:09:00,270 --> 00:09:03,450
I like to use LS dash LA.

226
00:09:03,450 --> 00:09:04,500
By doing that,

227
00:09:04,500 --> 00:09:07,290
I'm going to list out all the files and directories,

228
00:09:07,290 --> 00:09:08,790
including their permissions,

229
00:09:08,790 --> 00:09:11,130
and the A tells me to show me everything

230
00:09:11,130 --> 00:09:13,380
including those hidden files.

231
00:09:13,380 --> 00:09:14,760
If you're in the bash shell

232
00:09:14,760 --> 00:09:16,650
and you execute the LS command,

233
00:09:16,650 --> 00:09:18,690
you may notice that the results sometimes appear

234
00:09:18,690 --> 00:09:20,280
in different colors.

235
00:09:20,280 --> 00:09:21,900
These colors are used to distinguish the

236
00:09:21,900 --> 00:09:23,400
different file types.

237
00:09:23,400 --> 00:09:26,160
The different colors distinguish normal text files.

238
00:09:26,160 --> 00:09:28,470
while blue is going to be used for directories.

239
00:09:28,470 --> 00:09:32,190
Sky blue will be used for symbolic links and audio files.

240
00:09:32,190 --> 00:09:35,460
And if you're using green, that shows an executable file.

241
00:09:35,460 --> 00:09:38,760
If you have yellow with a black background, that's a device.

242
00:09:38,760 --> 00:09:40,920
If you have pink, that's an image file.

243
00:09:40,920 --> 00:09:42,927
If you have red, that's an archive file.

244
00:09:42,927 --> 00:09:45,270
And if you have red with a black background,

245
00:09:45,270 --> 00:09:47,910
that distinguishes it as a broken link.

246
00:09:47,910 --> 00:09:50,070
These colors can be very useful when you're looking

247
00:09:50,070 --> 00:09:53,010
at this to figure out exactly what you're looking at.

248
00:09:53,010 --> 00:09:54,570
Now, another command we need to talk about

249
00:09:54,570 --> 00:09:56,280
is how we make directories,

250
00:09:56,280 --> 00:09:59,610
and this is going to be done using the MKDIR command.

251
00:09:59,610 --> 00:10:01,500
This is the make directory command.

252
00:10:01,500 --> 00:10:04,110
It's used to create or make a directory.

253
00:10:04,110 --> 00:10:06,150
To use it, you're simply going to give the name

254
00:10:06,150 --> 00:10:08,400
of the directory you want as an argument.

255
00:10:08,400 --> 00:10:13,380
So, I would type MKDIR Jason to create the Jason directory.

256
00:10:13,380 --> 00:10:15,210
If I want to remove that directory,

257
00:10:15,210 --> 00:10:19,590
I can use the remove directory command, which is RMDIR.

258
00:10:19,590 --> 00:10:21,870
Now, when you're using RMDIR,

259
00:10:21,870 --> 00:10:25,800
it will only delete a directory if that directory is empty.

260
00:10:25,800 --> 00:10:27,840
If you want to delete a directory that has things

261
00:10:27,840 --> 00:10:29,940
in it like files or other directories,

262
00:10:29,940 --> 00:10:32,130
you're going to have to use the remove command,

263
00:10:32,130 --> 00:10:34,020
RM with the recursion.

264
00:10:34,020 --> 00:10:38,250
So it's RM dash R and the name of the directory.

265
00:10:38,250 --> 00:10:40,860
To use either make directory or remove directory,

266
00:10:40,860 --> 00:10:43,560
simply type in make directory and the directory name

267
00:10:43,560 --> 00:10:46,020
or remove directory and the directory name.

268
00:10:46,020 --> 00:10:47,040
So, as you can see,

269
00:10:47,040 --> 00:10:48,510
there are lots of different commands

270
00:10:48,510 --> 00:10:50,040
that you need to be familiar with

271
00:10:50,040 --> 00:10:52,200
inside the Linux operating system to get

272
00:10:52,200 --> 00:10:53,880
around in the command line.

273
00:10:53,880 --> 00:10:55,800
I recommend you take some time to practice

274
00:10:55,800 --> 00:10:56,850
each of the ones we covered

275
00:10:56,850 --> 00:10:59,013
in this lesson and get familiar with them.

