Time
8 hours 30 minutes
Difficulty
Beginner
CEU/CPE
10

Video Transcription

00:05
Hello. Welcome to module 103 of the legs. Plus course,
00:10
this monitor will be covering New and Lennox commands UNIX commands.
00:15
This module is the largest portion of the Alex 0103 examples. Here it's a 43%.
00:23
So there are a lot of topics,
00:25
but they're pretty manageable. And just like anything else, a little bit of practice goes a long way towards some level of mastery of these different commands and different,
00:36
uh,
00:37
tasks that typical administrator's gonna have to perform
00:40
in a production environment.
00:43
So we'll look at some command line features how to redirect output from one command to another,
00:49
how to use special redirection like pipes and, uh,
00:54
standard in and standard out
00:56
also touch on how processes air handled
01:00
and how to adjust their priorities, how to kill a process, how to let a process run without being killed.
01:07
We'll get into using regular expressions. These are powerful tools
01:11
to allow you to manipulate data and to search for it in very specific ways.
01:17
And then we'll wrap up with everyone's favorite editor, v I.
01:23
So for the command line,
01:25
uh, look, the command shell is really the primary interface for the typical limits administrator.
01:30
There are plenty of tools that can be used from the window manager. The gooey, but really the command line is probably your best bet in most cases, because you could be very efficient, very quick at getting your job done without having to deal with moving amounts around and finding buttons to click and things of that nature.
01:49
So we're gonna get into a little bit, but more about how the shell operates and not take advantage of some of its convenience features
01:57
unless you've got a pretty large list of commands
02:00
that can be can be utilized for these tasks.
02:06
So you've seen me already using the Olynyk shell.
02:08
I'm using a bash shell because that's the default
02:14
I actually prefer Bash because it has lots of nice features, like color coding of your different file types,
02:22
the ability to do some pretty sophisticated programming within the show.
02:27
I can
02:28
manage multiple shells at one time
02:30
and be able to, uh,
02:34
take advantage of other features like expansion filed lobbing using wild cards and so on,
02:40
and they give you some really nice futures. Once you get comfortable in this come environment
02:46
you could become very proficient and getting getting work done quickly
02:51
and with the ability to do scripting
02:53
the possibilities for automating tedious tasks and so on become much greater
03:02
now any shell in Lenox, regardless of whether it's bash or sea shell corn show,
03:08
or the original shell that's under Slash been,
03:14
each of these supports standard input, standard output and standard her.
03:19
And we need these these three different Io streams, because
03:24
as we interact with the shell, if I run a command and I see the output directly in my window,
03:30
that implies that that that output is being sent to standard out.
03:37
If I'm times ing typing something in
03:38
to a command
03:40
or taking input from another command
03:45
that usually would be referred to as standard input,
03:49
and then we can capture any errors in standard output.
03:53
Standard output is often redirected to standard
03:55
Sorry. Standard error is often redirected to standard output for convenience, so that we can see errors on the same display or the same stream as our normal output would go.
04:08
But we can also redirect that to go to a separate file,
04:12
separate log files, something of that nature
04:15
Now the Shell supports lots of different types of wild cards, and we see some examples here.
04:20
Everyone's probably familiar with the ampersand wild card.
04:24
That just means
04:26
I could match zero orm or or unlimited number of items that follow the ampersand.
04:33
So I'll bring up a shell here and demonstrate some of these here in a bit.
04:40
Uh, so this is really great. If I want to look for things like all text files or all files that begin with a certain string of characters,
04:47
the the ampersand or the splatter, as it's sometimes called, is my most useful tool here.
04:55
Sometimes they only want to match one character
04:58
so I could use the question mark and position it in the correct spot within the string that I'm searching for in order just to match,
05:05
ah, wild card character. In that particular position,
05:11
I can also define a range
05:14
a sense here. This is a range because I've just typed a through E.
05:18
But really, this is any character that's within this.
05:21
These are square brackets.
05:25
I could define that as a true range by using a dash between those characters so I could match
05:30
a through E or R L through Z whenever I wish.
05:34
I can also negate that match by using the exclamation point or the bang, as it's normally called,
05:42
and I can negate a range of characters. So in this case, I show me everything that's not a through E
05:49
or let me match everything that's not a through E.
05:54
And for even greater convenience, I can match specific strings, a specific words, just separating them with a comma.
06:01
And then, lastly, we have the dollar sign.
06:04
So anything that matches previous to the dollar sign in that string
06:10
will will be displayed.
06:14
That's very convenience. So Aiken
06:15
match
06:17
before and after.
06:19
Some characters I want can match a range, or I can negate those things.
06:24
And as you could probably envision, this gives you a lot of flexibility for how to use the shell to do your job or or efficiently from filtering log files or fine,
06:34
um, running other commands.
06:36
That requires some sort of a wild card.
06:41
This gives me a lot of options,
06:46
so let's bring up a shell real quick,
06:53
and I will go to the
06:58
That's been director. There's a bunch of files here.
07:02
In fact, we can run a command real quick. Thio, Count them. I can run the long listing file. Pipe this. So I'm taking the standard output of long listing
07:13
and using a pipe character to send that
07:15
standard output to the Stainer input of another command. In this case, I'm going to use word count.
07:21
Dash l counts the number of lines
07:25
sells tells me there's 646
07:28
lines of output in the L L Command.
07:31
Now, if I wanted to I c just based on the listing here that I've got several items that start with the letter X
07:40
so I can say l l
07:43
or just a last doesn't matter less Dash l of the equivalent
07:46
Show me everything that starts with the letter X using the
07:51
the splatter wild card.
07:55
So I get all these items that we see here.
07:58
Maybe this is too many things that I'm searching for.
08:01
So I might refine this by saying show me everything that starts with X f s
08:07
knowing that that maybe those are the files I'm looking for. Now I'll get a smaller list.
08:13
These two items here don't match. So they didn't show up.
08:18
I can also search in a different way I can say show me everything that starts with X f s
08:30
and maybe an underscore and some other items.
08:33
Now that one didn't work because the way that I'm trying Thio
08:39
specify this
08:43
is not correct for the shell syntax, right? Tells me that it can't find
08:48
those characters.
09:05
So what I can do is modify this a little bit and say, Show me,
09:09
uh,
09:11
everything that starts with letters, X f.
09:13
And then maybe I've got a, um,
09:18
wildcard character
09:20
in the third position.
09:22
I don't really know what that character is going to be,
09:24
but I couldn't, uh,
09:26
used this Platt for the rest of it. So
09:28
I see my accessed files. That way I can also do it this way. I can say show me everything that starts with an X
09:35
possibly has f s as the second and third characters and then the rest I don't care. Maybe I'll use an underscore and then I don't care
09:45
when using the underscore with a wild card,
09:48
give me a little bit tricky,
09:50
but I can find these items
09:52
not going back to my, um,
09:58
original surge of l l of of ex with everything that starts with X.
10:03
I also see that I've got excuse M stats and ex tables
10:09
so I could do a surge
10:11
for
10:13
a father. Has X
10:16
Q M.
10:20
And then maybe I know I've got some other letters there that might match,
10:24
and you could see how it's a little bit of a guessing game if you're not sure what you're looking for. In this case, I could see the files directly. But if I was using these these expansions in wild card characters in different contexts,
10:35
maybe it's not so easy to find exactly what I want, so I can play around with the possible settings
10:41
and, uh,
10:43
find my files that wait.
10:46
I can also try using a range
10:50
so I can say
10:54
what's to us
10:56
tea and then a through T.
11:03
So the reason this matches because
11:07
it's it's matching on X Q MST. But then the range of characters a Through T
11:11
encompasses the letters and tea as well. So I confined my fallen in a way that way,
11:18
lots of flexibility. And as I mentioned earlier section,
11:22
there's almost always more than one way to get things done using Lennox, especially the show
11:28
tab completion saved us a lot of effort.
11:31
This works the same in clinics as a dozen windows. All I have to do
11:35
is start
11:37
typing a command and I can hit Tab. If there's something that matches the text I already typed to have completion, Will will find that text and expand it for me.
11:50
Now you have to have a, uh,
11:52
a unique match in order to get what you really want. Otherwise you might get more than one result.
12:00
So, for instance, um,
12:03
but I can also
12:05
used more than one command on a single line. We're separating with semi colon,
12:09
the logical or logical, and could also be included.
12:13
So let's look at this real quick.
12:20
So if I say I wanted to do a long listing for X,
12:24
if I hit Tab here,
12:26
you'll notice it gives me everything that matches the letter X.
12:30
If I hit X F and
12:33
hit tab again,
12:35
I get excess
12:37
so that that would have excluded these two files X Q and X t r. The first couple of characters so
12:45
it didn't match. By the way, I hate to have more than once It's by the sea. Multiple listings here.
12:52
Now, if I type XL sorry. Except fast with underscored tab again. I still get a list of files, but it's showing me all the ones that begin with except fast with underscore.
13:05
Now I'm trying to narrow this down, so maybe I see. Okay, show me everything that starts with extra fast underscore letter A If I had tab now,
13:11
I only get one file.
13:13
And that's this one here. Ex office admin.
13:20
Now, this is also useful. What? I'm typing alone. Like, if I'm gonna go user share, I just typed s age.
13:26
Uh, and then the letter from star than the tab character. And it expanded that
13:31
It's very, very handy.
13:33
I'm taking a really long path. I only need to know the first couple letters. Each portion I type a couple others hit tab, it expands it, tip a couple letters, hit tab, it expands it. You get the idea there
13:45
now, I can also
13:48
run multiple Koreans on a single line.
13:52
Let me do this first. Clear the screen.
14:03
So here, I'm gonna go to the user share directory to a long listing
14:07
and then run the D F command.
14:11
So the change Directory Command didn't really produce any output
14:16
by itself because we just went to that folder.
14:18
But then the long list in command was run, which is what we see here.
14:22
And then the D F command finally was run at the end.
14:26
I can verify that I'm in that directory by just typing pwd. There we go
14:33
very handy.
14:33
Um, and I can use up arrow to show that that a command string again.
14:39
So this is really useful when I want to, um,
14:43
run a bunch of one multiple commands, but I don't want to keep hitting enter each time
14:50
another feature, which is kind of handy is
14:54
to control. See you to get out of that.
15:00
I can, um,
15:01
also use the backslash character
15:05
as a way to continue lines
15:13
user shares. He Shh.
15:28
Oh, okay. Set. I'm sorry. I got myself confused. What I did there waas
15:33
er typed cd user share.
15:37
And let's say this was a really long command. I could put a backslash character
15:43
and hit, enter and continue in the next line.
15:48
I'll do it. L l so we can see more clearly what's actually happening.
15:52
So use your share.
15:54
Ah, backslash
15:56
Let's d at another slash xml
16:02
and what I've done there is I've effectively typed this command user l l slash user share XML,
16:10
but the backslash was inserted in this position to allow me to split the line into two pieces. I just put the line into multiple pieces.
16:17
And this the reason that this is including the shells, because in the early days of
16:23
using
16:26
user terminals,
16:26
they usually had 80 characters by 25 rows that your your window, Your shell size is very small.
16:33
So in order to or to avoid a messy wraparound command, I can type some portion of the command hit backslash enter. Keep typing my command, backslash enter and so on to split this into multiple pieces.
16:47
So that's what I did here.
16:48
It's a nice, nice convenience feature
16:55
within the shell. We also have the man Paige, and you've seen me use the man comedian several times. You can actually run the manual command on the man command itself,
17:04
So if I type man man, I will see how the man pages work.
17:08
And that might be useful because the manuals have different sections. There's nine different sections.
17:15
Uh,
17:15
whichever section is the 1st 1 to match will be the one that gets displaying. So if I'm
17:22
looking at a system commands user commands. Most likely I'm in the manual section of one or two, and I can specify
17:29
manual section directly if I'd like to.
17:32
Once I'm looking at a man page listing, I can
17:34
navigate within that listing by using the V I editing commands.
17:41
That's very useful,
17:41
as we'll see here in just a moment.
17:49
So first already do a man on the man Paige,
17:55
and this tells me this is my online manual page reference.
18:00
There are a fair number options that you can run,
18:04
but, um,
18:06
generally, the
18:10
the default settings are usually sufficient.
18:12
So if I want to run a manual page on if config,
18:19
it tells me at the top.
18:22
But I'm looking at Section eight, which is stirring Ms Administration commands.
18:27
So it'll give me the information that I want.
18:32
At the bottom, we get, uh, h for help. Cute acquit some a little bit of help,
18:37
but I can also use. Right now I'm hitting the Jakey to go down.
18:41
I'm hitting the K key to go up. These are cursor control commands within V. I
18:48
very useful if I want to just move this a little bit up and down
18:51
or if I want to search for something in particular
18:53
quite often. I will search, for example, so I can type to slash key
18:57
and then just start typing the word example. I don't have to to type the whole thing. I could do a partial match
19:03
are There are no examples in this
19:04
man. Paige. A concert for options
19:07
now often matched, and we see that here because the matching text is now highlighted.
19:15
If I type the letter N,
19:18
I can look for additional match and it tells me there's patterns not found.
19:23
Uh, let's see. I'll find something that looks like a DDR has multiple matches salt type slash.
19:29
You see that the lower left corner,
19:30
a DDR
19:33
and all these different areas light up because they are matching
19:37
now the 1st 1
19:40
It tells me there are some online 42 of 149 lines.
19:45
And if I just keep thinking that the n key, it'll keep on moving me to the next instance of the text a T d r. Which is what I matched on.
19:55
It's very handy
19:57
and I could just take you to quit.
20:00
And as I've demonstrated as well earlier,
20:03
the man pages the most detailed. But I can also type,
20:07
uh, sometimes some command supported dash H option for help.
20:11
Usually older system five commands will do this.
20:15
And typically, I can also
20:19
do a dash dash help
20:22
and get that same text or something slightly different.
20:25
Um,
20:26
if Dash age doesn't work, try dash dash, help! That's the, uh,
20:30
the takeaway there.
20:33
But this gives you a kind of ah, condensed,
20:37
very basic bit of help.
20:40
Whereas the man page here it starts here. Actually,
20:42
the man Paige gives me more detailed help,
20:47
So it just depends on what you're looking for.
20:52
Other useful commands.
20:55
We have the echo command,
20:56
and this one is pretty self explanatory. It takes some bit of text or era variable in this case and sends it to standard output
21:07
and these air commands that you'll use fairly frequently in your administrative tasks.
21:11
We have the you name command, which tells me, my colonel, how long my system
21:18
has been running with certain options. I could look at my host name
21:22
and I can combine commands together,
21:26
using the pipe character for standard output to go to standard input.
21:30
I can also, uh,
21:30
have multiple commands of my line and substitute environmental variables. So let's try a few of these things out
21:45
first. I can try echo
21:49
their basic,
21:51
but I can also use Echo to display something like by environment variables.
21:56
One of my environment variables is a path.
22:00
This shows me my current search path. I can see all of my environment variables by typing envy,
22:07
and you'll notice that
22:11
path is in here somewhere. There it is,
22:15
So the echo command will will take any suitable
22:18
reference and display it to standard out.
22:22
They're handy
22:23
now. Maybe I want to run
22:26
you name command as I type before your name by itself just tells me
22:30
very basic details of my system. It tells me it's Olynyk system,
22:34
so usually I want to run your name. Dash A,
22:37
which tells me it's Lennox system gives me my host name and domain name
22:44
curl information,
22:45
date and time stamp.
22:48
Lots of other good details
22:52
tells me it was built on March 7th,
22:56
and
22:57
I can, um,
23:00
also run various
23:06
other options for your name. I'll go to the help command
23:10
I can. I did that Dash A for all. But I can also just show the colonel information. Just show the process or type
23:15
just the operating system and so on.
23:18
So it's always good to try that Help command
23:22
for additional details
23:25
and then combining some commands, I can say,
23:30
uh, show me
23:34
that. Go Oh
23:37
one.
23:38
And then also echo my user i d number
23:44
So sending some generic output. The number one
23:47
But my user i d number is zero because I am route. If I took the i d command
23:53
your ideas route, my G i d is also my idea zero rather, which is normal for root.
24:00
And so it's another way to to to display some environs rebels.
24:07
But I can do maybe a little bit more complex of a command. I can run tail. This was from the slide.
24:11
Uh, I want to look at
24:18
var along messages.
24:19
I actually don't want to tell Dash off.
24:22
I can
24:25
capt of our log messages.
24:30
So I'm gonna send that whole file to standard output
24:33
and then I'll point that
24:34
to a group command
24:37
dash I for ignoring case, and I'm just gonna search for all instances of the word error.
24:44
So this is a really great way to filter logs.
24:48
In this case, I've got quite a few items,
24:49
but notice I can count these. I can pipe that output again and send it to work out. Dash out. There's 49 errors.
24:57
Maybe I want to get a little bit more specific so I could start
25:03
doing some additional filtering
25:06
with
25:07
with wild card matching and so on.
25:11
But you can start to see how this is very useful, too.
25:15
Be able to string things together
25:18
and make your life a lot simpler.
25:22
I've also used the Print Working Directory and Change Directory Commission several times. These air some of the easiest Lennox commands to learn because they work
25:30
more or less the same way, and windows in. Most people are familiar with that.
25:36
I showed you the Environment Command, E N V.
25:38
I consent in unset variables by using the set and unsent commands.
25:45
If I change in environment variable, I always have to export this in order for it to become available to the shell.
25:52
Just changing the value does not make it available to the shell immediately. So that's a, uh, something to keep in mind when you're using these commands,
26:03
and we typically see this in
26:07
script files.
26:10
So if I go to my home directory,
26:11
do CD to tilt,
26:14
that's a shortcut for the home director of the current user, which in this case is route.
26:21
And I'll do a long listing in my in my file here in my directory,
26:26
and
26:27
you'll notice I have several items I can look at.
26:32
What's let's examine
26:34
Bashar seek?
26:37
So this one has a few things set up. I've got some aliases.
26:41
God,
26:42
if I type ahram, it really doesn't RN Dash I fi type envy for move. It really doesn't move. Dash I
26:49
This one's not showing me looking for Let's look at the profile.
27:00
So here we're making a change to the path environment. Variable seeing if it contained certain items.
27:07
Uh, here the host name variables being set
27:11
history size variables being set and then you'll notice because I'm changing these.
27:15
There's also an export command for both of those.
27:21
So if I, if I modify the variable, have to export it to promote it to the shell to make it usable.
27:27
Just a quick overview showing how this works.
27:34
I can also
27:40
I could also look at the
27:44
sorry for my environmental variables.
27:48
We need to fight this tomb or
27:51
my print working director of my current director You saved is a variable.
27:55
My current home directory is here.
27:59
Display number of these are things that are sometimes needed for other reasons in the shell. So these environment variables become globally accessible to other programs running within this particular shell.
28:10
Also, my history size
28:12
my current shell that I'm running in, which is slash been slash bash,
28:18
user name and so on.
28:21
These are all pretty useful things.
28:23
And as you get more sophisticated with your commands and your usage will be able to take more advantage of these items,
28:32
then we have the history command.
28:34
Now you've already seen me using the up and down arrow keys.
28:37
Thio, look at my history. But I can also run a specific command
28:42
to show me things like showing the last 15 commands I've typed
28:47
or some of my last one or ones that match
28:49
a particular strength.
28:52
The hist size variable
28:55
tells me, or let me define how many commands I'd like to keep in my history.
29:02
Let's go back and look at this.
29:03
So the, uh pero key
29:07
down arrow key
29:08
Very convenient,
29:10
but maybe not so specific, Right? So if I could just say, Well, show me the history
29:14
Last 15 commands There they are.
29:18
And it keeps on account of my absolute number of commands.
29:22
So the the history command I just typed was the 1000 and 31st command that I've typed
29:27
since I've been saving commands
29:30
and I could echo my
29:34
fist size and it's set for 1,000,000 commands to save. So after 1000 it starts getting rid of the oldest ones.
29:44
So bang bang is my last command,
29:48
which is echo his size. It tells me what it was. Shows me the output,
29:52
and I can also do a search.
30:00
So it's new and knows that I was trying to run you name. So I did a search of bang
30:06
unh had found you name and tried to run it.
30:11
So, uh,
30:12
again, with anything that we're talking about, a little bit of practice can help quite a bit
30:18
now. The path that we were looking at earlier
30:22
this is important to know a little bit about because when I when I define a path
30:27
and I exported my path earlier, but would you really don't look at it very closely?
30:32
Whatever I've got defined in this dollar path, variable is where the shell will look first for any commands that I try to run.
30:41
If if it's not found in that path,
30:44
I'll get a message saying Found out, found director not found whatever it might be.
30:48
So I could modify the path
30:51
by stating a new path variable
30:53
and including the old one is part of that new one,
30:56
and I'll show This works here in just a moment,
31:00
but the ideas I defined path as my current dollar path.
31:03
Then I add a colon, some new information that I want to append to my current path and then I can export it.
31:11
So let's try that out.
31:14
So I called my current path,
31:17
and I've got some library Director is usual local. Been use a little Espen
31:23
has been been typical like these air where commands normally would be found for
31:30
a typical user.
31:33
Now I can say
31:34
groups that wasn't good.
31:40
I think it just
31:42
Yeah,
31:44
because I accidentally
31:45
hit Enter. What I did was I set my past $2 Pete, which doesn't mean anything. And now my current path
31:52
is nothing.
31:55
Now I can get my path back
31:56
by executing.
32:04
I can execute my current.
32:07
I don't have a dot profile.
32:14
I'll see now I can't even tie my l s command
32:16
because I have
32:20
erase my current path. This is a great example of how problems can come up and you have to try to figure out how to solve them
32:27
now. Ah, good cheat.
32:29
Because I have this already on the screen. What I can do
32:34
is copy
32:37
and say path
32:38
equals
32:40
paste
32:45
and then export
32:54
in trouble typing today.
32:58
All right, so I've sent my pad path back to what it was
33:00
defined it here
33:04
and then ran the export demand.
33:07
Now it's back available.
33:13
You know, what I was trying to do before was to show I can add something to my path. So if I type more carefully this time,
33:20
so path equal dollar path
33:22
and then I want to add
33:25
home admin.
33:28
And since I want to do this on a single command line,
33:35
No.
33:36
When I look at my path and should contain everything that was previously there plus slash homes. Last admin because I
33:44
I added that right here.
33:45
So pretty, pretty handy.
33:52
All right, so these are the commands that we covered for your command line shelter
33:59
and
34:00
very simple to use. Remember the help committee, remember the main page
34:02
and get some practice in because you're gonna need these for later activities in the course.
34:08
All right, so our next section is processing tech streams using filters. See you there. Thank you.

Up Next

CompTIA Linux+

Our self-paced online Linux+ training prepares students with the knowledge to become a certified Linux+ expert, spanning a curriculum that covers Linux maintenance tasks, user assistance and installation and configuration.

Instructed By

Instructor Profile Image
Dean Pompilio
CEO of SteppingStone Solutions
Instructor