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