1
00:00:00,090 --> 00:00:01,020
In this video,

2
00:00:01,020 --> 00:00:03,300
we're going to discuss some basic Bash commands

3
00:00:03,300 --> 00:00:04,770
so you can start to use the shell

4
00:00:04,770 --> 00:00:07,080
to perform some basic functions here.

5
00:00:07,080 --> 00:00:08,250
There are several commands

6
00:00:08,250 --> 00:00:10,500
that are important for accomplishing basic tasks

7
00:00:10,500 --> 00:00:12,510
within the Linux operating system.

8
00:00:12,510 --> 00:00:14,340
Many of these commands are going to be covered

9
00:00:14,340 --> 00:00:16,050
in greater depth throughout this course

10
00:00:16,050 --> 00:00:17,760
but a few will be discussed now

11
00:00:17,760 --> 00:00:19,920
to provide you some basic command vocabulary

12
00:00:19,920 --> 00:00:22,290
and to get you started with some more hands on practice

13
00:00:22,290 --> 00:00:23,880
within the Bash shell.

14
00:00:23,880 --> 00:00:25,470
It's also important to take note

15
00:00:25,470 --> 00:00:26,580
that both of the commands

16
00:00:26,580 --> 00:00:29,250
and the syntax are really important to get correctly

17
00:00:29,250 --> 00:00:30,690
when you're typing them in.

18
00:00:30,690 --> 00:00:31,620
This is going to be important

19
00:00:31,620 --> 00:00:33,690
to get the proper way of entering in the command,

20
00:00:33,690 --> 00:00:35,220
as well as the right options to use

21
00:00:35,220 --> 00:00:36,660
so that that command's output

22
00:00:36,660 --> 00:00:39,450
creates the expected outcome you're trying to achieve.

23
00:00:39,450 --> 00:00:42,270
The first command I want to cover is known as echo.

24
00:00:42,270 --> 00:00:43,860
The echo command repeats input

25
00:00:43,860 --> 00:00:45,780
back to the user on the screen.

26
00:00:45,780 --> 00:00:48,240
This is commonly used to send information to the user

27
00:00:48,240 --> 00:00:49,260
when you're running a script

28
00:00:49,260 --> 00:00:52,290
or a long series of commands from a given file.

29
00:00:52,290 --> 00:00:56,970
For example, if I type in echo "Good morning!",

30
00:00:56,970 --> 00:00:58,770
this is going to return good morning

31
00:00:58,770 --> 00:01:01,290
inside of the command line interface.

32
00:01:01,290 --> 00:01:03,690
The next command we have is the list command.

33
00:01:03,690 --> 00:01:05,700
This is known as ls.

34
00:01:05,700 --> 00:01:08,670
The ls command lists the contents of a directory

35
00:01:08,670 --> 00:01:10,980
and can be given options to view their permissions,

36
00:01:10,980 --> 00:01:13,320
hidden files and other information.

37
00:01:13,320 --> 00:01:16,650
For example, I like to use the ls -a command

38
00:01:16,650 --> 00:01:18,600
because this lists the directory's contents,

39
00:01:18,600 --> 00:01:21,000
including all the hidden files.

40
00:01:21,000 --> 00:01:21,900
The next one we have

41
00:01:21,900 --> 00:01:24,120
is known as the present working directory.

42
00:01:24,120 --> 00:01:26,490
Now the pwd command is going to display

43
00:01:26,490 --> 00:01:28,830
the current working directory that you're in

44
00:01:28,830 --> 00:01:32,310
while the cd command is the change directory command.

45
00:01:32,310 --> 00:01:34,590
And you use this to change your current working directory

46
00:01:34,590 --> 00:01:36,150
to another directory.

47
00:01:36,150 --> 00:01:40,050
For example, if I typed in cd /etc,

48
00:01:40,050 --> 00:01:42,180
this is going to change my current working directory

49
00:01:42,180 --> 00:01:45,060
over to the /etc directory.

50
00:01:45,060 --> 00:01:47,610
The next command we have is the copy command.

51
00:01:47,610 --> 00:01:50,340
The copy command is written as cp.

52
00:01:50,340 --> 00:01:52,380
The cp command is going to copy a file

53
00:01:52,380 --> 00:01:54,480
or directory to another location.

54
00:01:54,480 --> 00:01:58,380
So if you type in cp file1 file2,

55
00:01:58,380 --> 00:02:01,617
this will copy the contents of file1 to file2.

56
00:02:01,617 --> 00:02:03,600
Now if I wanted to make a new directory,

57
00:02:03,600 --> 00:02:07,287
I can use the make directory command or mkdir.

58
00:02:07,287 --> 00:02:10,350
The mkdir command will create a new directory

59
00:02:10,350 --> 00:02:12,300
of the given name that I specify.

60
00:02:12,300 --> 00:02:16,980
So if I type in mkdir newdir,

61
00:02:16,980 --> 00:02:20,400
it's going to create a new directory called newdir.

62
00:02:20,400 --> 00:02:22,770
The next command we have is the clear command.

63
00:02:22,770 --> 00:02:24,000
The clear command is going to be used

64
00:02:24,000 --> 00:02:26,520
to clear the command line interface of all the text

65
00:02:26,520 --> 00:02:28,740
and bring you back to the top of the screen.

66
00:02:28,740 --> 00:02:31,050
I think about this like a magic eraser.

67
00:02:31,050 --> 00:02:34,050
It's going to clean everything off of my screen, instantly.

68
00:02:34,050 --> 00:02:36,330
This is really useful when you're starting a new task

69
00:02:36,330 --> 00:02:38,400
and you want to eliminate any distracting information

70
00:02:38,400 --> 00:02:40,290
from your past command entries.

71
00:02:40,290 --> 00:02:41,670
Another thing we want to talk about

72
00:02:41,670 --> 00:02:43,470
is how we can look at text files

73
00:02:43,470 --> 00:02:46,110
because Linux system configurations are usually held

74
00:02:46,110 --> 00:02:47,700
within these text files.

75
00:02:47,700 --> 00:02:50,430
So if you want to be able to view the contents of those files,

76
00:02:50,430 --> 00:02:52,710
you need to use the cat command.

77
00:02:52,710 --> 00:02:55,410
The cat command or CAT is going to be used

78
00:02:55,410 --> 00:02:56,910
to view the contents of a file

79
00:02:56,910 --> 00:02:59,190
without the option to edit that file.

80
00:02:59,190 --> 00:03:01,200
It's basically just a way to view it.

81
00:03:01,200 --> 00:03:04,290
An example of this would be typing in cat file1

82
00:03:04,290 --> 00:03:06,360
and that's going to display the contents of file1

83
00:03:06,360 --> 00:03:07,800
on the screen.

84
00:03:07,800 --> 00:03:08,970
Now, the problem with this

85
00:03:08,970 --> 00:03:10,860
is that if file1 is really long,

86
00:03:10,860 --> 00:03:12,240
it's going to scroll off the screen

87
00:03:12,240 --> 00:03:13,770
and you're not going to be able to see it all.

88
00:03:13,770 --> 00:03:16,800
So there's another command known as less.

89
00:03:16,800 --> 00:03:19,530
The less command is used to view the contents of a file

90
00:03:19,530 --> 00:03:22,890
when those contents won't fit entirely on one screen.

91
00:03:22,890 --> 00:03:25,740
So by using less, it's going to break the content

92
00:03:25,740 --> 00:03:28,440
into output pages, one screen at a time

93
00:03:28,440 --> 00:03:31,080
that you can scroll through using the CLI.

94
00:03:31,080 --> 00:03:34,110
An example of using this would be less file1.

95
00:03:34,110 --> 00:03:36,120
And this will break the contents of file1

96
00:03:36,120 --> 00:03:37,380
into multiple pages

97
00:03:37,380 --> 00:03:39,360
when its contents are going to be put on the screen

98
00:03:39,360 --> 00:03:40,620
one page at a time,

99
00:03:40,620 --> 00:03:42,510
so I can see it all as it goes.

100
00:03:42,510 --> 00:03:45,000
Then I can press page up or page down

101
00:03:45,000 --> 00:03:47,610
to scroll through the entire screen's worth of content,

102
00:03:47,610 --> 00:03:49,950
one screen at a time and when I'm done,

103
00:03:49,950 --> 00:03:52,230
I'll press Q to exit the less command

104
00:03:52,230 --> 00:03:54,270
and go back to the command prompt.

105
00:03:54,270 --> 00:03:55,620
Now, just as you need to view

106
00:03:55,620 --> 00:03:57,210
the contents of the text files,

107
00:03:57,210 --> 00:03:58,043
there's going to be times

108
00:03:58,043 --> 00:04:00,030
where you need to edit those text files too

109
00:04:00,030 --> 00:04:02,640
and this is where a text editor comes into play.

110
00:04:02,640 --> 00:04:05,340
Now in Linux, there are lots of different text editors

111
00:04:05,340 --> 00:04:09,330
but the three big ones are vi(m), nano and gedit.

112
00:04:09,330 --> 00:04:11,700
Vi(m) is the default text editor for Linux

113
00:04:11,700 --> 00:04:14,940
but it's pretty complicated to use for most people.

114
00:04:14,940 --> 00:04:17,160
Another one you can use is known as nano.

115
00:04:17,160 --> 00:04:19,440
It's a simple user friendly text editor,

116
00:04:19,440 --> 00:04:22,770
and personally, it's the one I use myself most of the time.

117
00:04:22,770 --> 00:04:24,450
Now, nano is not pre-installed

118
00:04:24,450 --> 00:04:26,790
on all distributions though, like vi(m) is,

119
00:04:26,790 --> 00:04:29,370
so if you don't have nano and you want to use it,

120
00:04:29,370 --> 00:04:31,860
you're going to have to install it before you can use it.

121
00:04:31,860 --> 00:04:33,390
We'll talk about how to install programs

122
00:04:33,390 --> 00:04:34,560
in a future lesson though.

123
00:04:34,560 --> 00:04:36,810
So don't worry too much about that right now.

124
00:04:36,810 --> 00:04:39,690
Now another one we can use is known as gedit.

125
00:04:39,690 --> 00:04:43,050
Gedit is a graphical user interface text editor.

126
00:04:43,050 --> 00:04:44,580
So it's really easy to use

127
00:04:44,580 --> 00:04:47,760
but it does require a desktop graphical environment.

128
00:04:47,760 --> 00:04:49,740
Something like Gnome or KDE

129
00:04:49,740 --> 00:04:51,390
that's installed on your Linux system

130
00:04:51,390 --> 00:04:53,460
if you want to use gedit.

131
00:04:53,460 --> 00:04:54,810
Now, another thing we need to talk about

132
00:04:54,810 --> 00:04:57,810
is how are you going to reboot or shut down your system?

133
00:04:57,810 --> 00:04:59,940
Periodically, it may become necessary

134
00:04:59,940 --> 00:05:01,950
to reboot or shut down your system

135
00:05:01,950 --> 00:05:04,380
and there's several different commands to accomplish this.

136
00:05:04,380 --> 00:05:06,090
The most common one that's used though,

137
00:05:06,090 --> 00:05:07,830
is the shutdown command.

138
00:05:07,830 --> 00:05:10,830
If you type shutdown -h now,

139
00:05:10,830 --> 00:05:13,050
this'll shut down the system immediately.

140
00:05:13,050 --> 00:05:16,380
The -h stands for halting it with no time delay

141
00:05:16,380 --> 00:05:17,850
and then it's going to halt the system

142
00:05:17,850 --> 00:05:21,270
and then shut it down all the way to powered off state.

143
00:05:21,270 --> 00:05:22,230
Now, if on the other hand,

144
00:05:22,230 --> 00:05:24,060
you just need to reboot your system,

145
00:05:24,060 --> 00:05:27,870
you can do that by typing shutdown -r now

146
00:05:27,870 --> 00:05:30,720
which says shut down and reboot the system

147
00:05:30,720 --> 00:05:32,970
and bring it right back up right now.

148
00:05:32,970 --> 00:05:34,500
And this will just reboot the system for you,

149
00:05:34,500 --> 00:05:37,440
instead of stopping it and powering it off.

150
00:05:37,440 --> 00:05:40,290
Now in Linux, the user with the administration credentials

151
00:05:40,290 --> 00:05:43,140
is known as our super user or our root user.

152
00:05:43,140 --> 00:05:45,960
It's generally considered a really bad security practice

153
00:05:45,960 --> 00:05:48,720
for you to log into the system as the super user.

154
00:05:48,720 --> 00:05:50,340
So instead, you should log in

155
00:05:50,340 --> 00:05:52,920
with a non-privileged account for your daily tasks,

156
00:05:52,920 --> 00:05:55,080
something like a standard user account.

157
00:05:55,080 --> 00:05:56,520
However, there's going to be times

158
00:05:56,520 --> 00:05:58,080
where you need to be a super user

159
00:05:58,080 --> 00:06:00,540
to perform some kind of administrative task.

160
00:06:00,540 --> 00:06:04,770
And so we can use the substitute user or SU command.

161
00:06:04,770 --> 00:06:06,510
If you use the su command,

162
00:06:06,510 --> 00:06:08,760
it's going to allow you to switch your user credentials

163
00:06:08,760 --> 00:06:11,340
and by using su, you can now switch your credentials

164
00:06:11,340 --> 00:06:13,260
to that of the root user.

165
00:06:13,260 --> 00:06:14,820
The system then, will prompt you

166
00:06:14,820 --> 00:06:16,500
to enter in the root user's password

167
00:06:16,500 --> 00:06:18,120
for authorization purposes

168
00:06:18,120 --> 00:06:19,290
and if you get it right,

169
00:06:19,290 --> 00:06:20,760
you're going to be logged in as root

170
00:06:20,760 --> 00:06:21,870
and be able to perform tasks

171
00:06:21,870 --> 00:06:23,730
that were previously unavailable to you

172
00:06:23,730 --> 00:06:25,560
because you were only a regular user.

173
00:06:25,560 --> 00:06:27,720
But now, you're the super user.

174
00:06:27,720 --> 00:06:30,120
So think about this like you would on a Window system

175
00:06:30,120 --> 00:06:32,160
of switching to an administrator user account

176
00:06:32,160 --> 00:06:34,590
or doing a run as administrator.

177
00:06:34,590 --> 00:06:36,870
Now, one of the great things about the Bash shell

178
00:06:36,870 --> 00:06:38,400
is that it keeps a history file

179
00:06:38,400 --> 00:06:40,650
of all the commands you've ever entered.

180
00:06:40,650 --> 00:06:43,290
You can reference this file and repeat previous commands

181
00:06:43,290 --> 00:06:45,120
without having to retype all of them.

182
00:06:45,120 --> 00:06:47,430
And therefore, you can increase your efficiency

183
00:06:47,430 --> 00:06:50,040
and your consistency of the commands you're entering.

184
00:06:50,040 --> 00:06:52,560
For example, if you type the history command,

185
00:06:52,560 --> 00:06:53,820
you're going to see the output

186
00:06:53,820 --> 00:06:56,760
of the most recently entered commands in the list format

187
00:06:56,760 --> 00:06:58,380
and you can use the up and down keys

188
00:06:58,380 --> 00:07:00,420
to cycle through that command history.

189
00:07:00,420 --> 00:07:03,150
When you press enter, it will reissue the desired command

190
00:07:03,150 --> 00:07:06,180
from the history to the command line interface.

191
00:07:06,180 --> 00:07:07,950
Another thing that Bash shell supports

192
00:07:07,950 --> 00:07:10,290
is something known as tab completion.

193
00:07:10,290 --> 00:07:12,900
This enables a user to type in enough of a command,

194
00:07:12,900 --> 00:07:15,510
a file name, or a directory name to be unique

195
00:07:15,510 --> 00:07:17,670
and then press tab to automatically fill in

196
00:07:17,670 --> 00:07:19,290
the remainder of that entry.

197
00:07:19,290 --> 00:07:21,570
This feature can reduce typographical errors

198
00:07:21,570 --> 00:07:24,660
and really speeds up the process of entering in commands.

199
00:07:24,660 --> 00:07:28,200
For example, if I type his and press tab,

200
00:07:28,200 --> 00:07:30,390
that'll automatically fill in the rest of the command

201
00:07:30,390 --> 00:07:32,220
and it'll become history.

202
00:07:32,220 --> 00:07:33,720
This can be a great time saver

203
00:07:33,720 --> 00:07:35,310
when you're working on the Linux system

204
00:07:35,310 --> 00:07:37,623
or as a cybersecurity analyst in the future.

