Hello there, you beautiful people.
So in the last video you learned that there is something called the shell that is interpreting the commands
that you type into the terminal.
Now, one reason that Linux is amazing is that the commands that you type all follow a similar type
of structure in the way that you type them.
Now, by understanding this structure, you'll be able to transition from simply just memorizing commands
and hoping for the best to actually understanding the common language that all Linux commands use,
and that will give you a massive boost in your abilities.
So in this video you're going to learn what commands actually are and how they are structured.
And by the end of this video, you'll have a much deeper understanding of what commands are, and the
commands themselves will actually start to look like a language rather than just random gibberish on
the screen.
So this is going to be a very game changing lecture that if you understand fully what I show you here,
it will make your work with the terminal so much easier.
So let's not waste any time and get right into it.
Okay.
So the first thing you need to know is that all commands are effectively just little computer programs
that are installed somewhere on your computer.
So, for example, date is a program, cal is a program, echo is another program and so on.
Now the command or program name that you want to use is always the first part of the command.
So we'd start a command with the word date or with the word cal or with the word echo like you saw before.
Right now, each command has its own unique behavior that you can actually look up using something called
the manual pages, which I'll show you how to do later in this section of the course.
But the general command structure goes like this.
First you type out the command name.
So that would be like date, cal, echo, whatever it would be.
Then you give the command some options to customize its behavior, then you give the command some inputs
to actually operate on.
Now the first thing you type is the command name.
Now that lets the shell know what program you actually want to run.
And once the shell knows what program you want to run or it knows the name of the program you want to
run, the shell will then search for that program on something called Your Shell's Path, which is just
a list of folders that contain these programs.
Now you can actually see your shell's path by typing echo, then a dollar sign, then path.
So echo space, then dollar sign, then path, and you press enter and you see this terrifying output
come out.
But it's actually it's actually very easy to understand once you notice that these are just different
folder paths, each separated by a colon by these two dots here.
So for example, there's a there's a set of there's a folder here that's called slash user slash local
slash spin.
Then you've got another folder here, slash user slash local slash pin, then another folder here and
another folder here and another folder here and so on and so on.
Okay.
So what the shell will do is it'll start at the very left of the path and it will look inside that folder
for a command called Echo or called Cal or called date or whatever you call it.
So it will look in the leftmost folder, and if it doesn't find it there, it'll move to the next one.
So it would start at the very left, then it would move to maybe to this folder.
Okay, then if it didn't find it there, it would move to this folder and if it didn't find it there,
it would move to this folder and so on and so on and so on until it got right to the end.
So to slash, snap, slash bin, and if it didn't find a folder with that name in any of those folders,
then the, the shell would give you a command, an error like command not found.
So if I tried to do Blue Alert and tried to call that as a command, it says it couldn't find this command.
So what the shell did is it looked for a command called this in each of these folders, didn't find
it and said command not found.
Now this is this has an interesting and interesting impact.
The fact that it the fact that it reads from the very left all the way to the very right, let's say
you had a program called blah and blah was actually in this folder here, slash user slash spin, but
it was also in the very far left folder.
Which one do you think will actually be run?
Well, actually, what would happen is it would only run the version in here because that's where it
found it first.
And if you wanted it to run this version, the version was in this folder, that wouldn't be possible
because it found the same name here first.
Okay, so that's just something to bear in mind.
It's not something you'll really run into, but it's just something to bear in mind.
Okay.
Now you can actually see which folder that a command is stored in by using the which command.
So it's like, which folder is this command in.
So I could say which and then Cal and if I press enter it'll tell me that the Cal command is actually
in the slash user slash bin folder.
And if we look at our path, we can see that slash user slash bin is located here.
So it is on our path and therefore Cal was able to be found.
And let's try that again for Echo, if we do, which echo you can say slash bin, slash echo.
And if we look on here, we'll find somewhere.
Slash bin is somewhere.
Here we are.
Slash bin.
There we go.
So Slash Bin is also on our path.
You can actually also look at the which command.
So the which of which which which folder is the which command in.
And we see it's in slash user slash bin which is here, there we go, slash user slash bin and we see
the which command also runs as well.
So that's how the shell knows where to find your commands.
Now you can customise the way that commands work by giving them different options and different inputs.
Let's go ahead and start with the inputs.
So it's important to note that not all commands actually require inputs.
Some inputs are optional.
For example, the day command doesn't strictly require an input.
You can just type date and be b be done with it.
But most commands do require some form of input which can actually have a fancy name called an operand
because commands operate on the input.
The input is sometimes called an operand.
So to give the command an input or an upper end, you simply type a space after the command name, then
type the input.
That's assuming you don't have any options.
So for example, if we take the cow command, I could just type cow and press enter and I would get
this month's calendar.
But to customise the behaviour I can give it an input.
So for example, if I want to get the calendar for the year 2017, I could type cow 2017 and if I press
enter now I get a completely different input, a complete different output.
Sorry, because I gave the command this input.
You can also give more than one input.
So let me clear the screen using control and l the nice shortcut.
Sometimes you can give more than one input for.
So for example I could type cow 12 2017 and for press enter you can see now that I get I've given command
the cow command two inputs one being 12 which means the 12 month and the the next one being the year,
which is 2017.
So I've said here, can you give me the, the calendar for December 2017.
Pretty cool, right.
So we gave it two inputs and that also customise our output.
So basically you can just give commands inputs.
So like if I say echo when I say hello then echo then hello, sorry was the input to the echo command
you see.
So that's quite straightforward.
All we did was type the command name, which the shell then found on the path and we gave that command
that, that program some input.
So now that we understand inputs, let's discuss options because this is where stuff gets really interesting.
You've seen you've seen us use an option with the command as well.
So the command we gave it the Y option before.
Okay.
So if I do it by default, the cal dash, we will show the current year's calendar.
So we've managed we gave the command, the cal command an option which the Y option which you can see
that has been preceded by this dash and that's common for commands.
They tend to be preceded by by dashes and hyphens and things.
So let's take a look at the date command to understand how options work even better.
Date by default will show today's date in our current time zone.
So if I just say date, it says here's the here's the date and time in the current time zone, which
is apparently British summertime.
Okay.
So.
To get the date in universal time such as UTC or Greenwich Mean Time.
We can type date slash you and we can see now that the date the hour has gone back one because now we're
in UTC rather than British summer time, which is currently an hour forward.
So we gave the date command the U option.
Now if we had other options to give the commands, we could list them right after one another.
So for example, we could do date slash dash a, dash B, dash C, D, E, f, d, and this would give
it these different options.
So the A option, the B option, the C option, the D option, the E option, the F option, the G option.
Or more simply, you could just do dash a, b, c, d, e, f, g.
That's a nice shortcut.
You can just stick them all together like that.
Okay, now this specific example doesn't work.
So if I try that, it will say invalid option.
But it just illustrates the point that if you chain these options together, you can you can actually
chain them together and the order doesn't really matter.
So I could do date, uh, g g e f a and it would have exactly the same effect.
Okay.
All right, then.
So now it can be sometimes be difficult to understand what these options mean.
So sometimes options actually have long form names.
So for example, date slash you dash u sorry, which gives us the date in universal time.
You could also do date dash dash universal now longer and gives us the same output.
Now universal long names are preceded by two dashes.
So you see a dash, dash, universal.
Whereas the short form options which are just one letter, are usually just preceded by one dash.
Now the long form commands can make commands easier to read, but they're not available for all options.
It really depends upon the command that you're using.
And again, just notice the fact that I use two dashes for long forms and one dash for short form commands.
Now, if you wanted to use, for example, three long form options, you would need to do something
like this.
So you'd have to do date dash, dash universal.
That's one long form option, then dash, dash long form option two then dash dash long form option
three.
You can't really chain those together like you can with the short form options.
So that's not going to work.
But the short form options you can do date slash ABCD CFG, but with long form options, you kind of
have to separate them.
Uh, dash, dash universal dash dash.
Long form option to and dash dash long form option three.
Now it's important to note that everything on Linux, including commands, is case sensitive.
So for example, the date command in lowercase is valid, so the one in lowercase is valid, but the
date command like with a capital D would not be valid.
The date command with like a capital A here, that would not be valid either.
So you need to make sure that you spell your stuff correctly and with the right case sensitivity.
And that goes for options and inputs too.
So it's not just the name of the commands.
The date command, for example, has a new option, but I don't think it has a capital view option C
it doesn't.
So I put a capital U and it didn't give me the universal output because it doesn't know that it has
a capital U option.
It only knows that it has a lowercase you option.
So make sure that you spell your commands with the right case sensitivity.
Now, the only other thing to know is that sometimes options can have their own inputs.
So, for example, if we go to Kal, I'm going to clear the screen.
If we go to Kal, we could see the calendar for December 2017 by giving it to inputs, right?
KAL 12, 2017.
Not options to inputs, but there is an option that will allow us to see a certain amount of months
after that too.
So for example, if I did, Kal gave it the capital a option, then wrote the number 112 2017.
This will show December 2017 with one month after and the the a option gives you after.
But it also needs to know how many months after.
So I said one.
So this one here is actually an input to the a option and then you've got the inputs for the command.
Okay.
You can also show a month before.
So for example, Kal Dash be 112 2017 that will show us December 27 said 20th December 2017 with one
month before it.
And you actually also combine these together.
So KAL one month after one month before of December 2017.
So now you've got December 2017 with one month after, which is January 2018 and one month before November
2017.
So here you can see how you can actually provide options with their own inputs and how options are okay
to use.
When you give commands, it's own input so you can use.
There's loads different ways to combine this stuff together.
So here we have the A and B options with their own inputs, and the cow command has its own two inputs,
12 and 27 and 12 and 2017.
So this is starting to get a bit crazy, right?
Like it's starting to get a bit advanced and a bit hairy.
But this is just should just begin to highlight just how powerful Linux commands can actually become.
And the only other thing you might need to know is.
That some commands allow you to put an equal sign to match up those options with their appropriate inputs
more explicitly to make stuff a bit easier to read.
This doesn't work for Cal, but if it did, it would be something like Cal after equals one before equals
112 and 2017.
Now that doesn't work for Cal because its manual page doesn't let it happen.
Um, so we only get 12 2017.
That didn't quite work, but that's how it would work if it was possible for the Cal Command.
And it might, you know, it might just make it a bit easier to read that the options are linked up
with their appropriate inputs.
If there were long form options, you would do something like cal dash dash before equals one, dash,
dash after equals one and 12 2017.
So here you've got long form options also being linked with their inputs.
Again, that's not possible for the cow command specifically, but you can see how features like that,
you know, joining up the inputs with the actual options can make commands easier to read.
So in this admittedly rather in-depth video, you've learned that commands are basically broken up into
three main parts.
First, you've got the command name.
Then you've got some options which are preceded by dashes and hyphens.
And you've also then got some inputs for the command.
Now the command name needs to match a program that is on the Shell's search path.
Now, the path is just a piece of text that's stored in the shell that lists a bunch of folders that
the shell will start searching from the left to the right, separating each folder with a colon, which
is the two dots on top of each other.
And if the shell finds an appropriate program, then that program will run and the shell will pass to
that program any inputs that you have given it in the command.
So you can also customize a commands behavior using options now.
Options are usually just letters that are separated by hyphens.
So a dash like you see at the very top of the summary slide here, you give each option a dash before
it, or you can chain the little letters together in one go.
The order does not matter, and sometimes they have long form versions which are need to dashes but
allow you to use easier to read words.
So instead of having dash you for the universal option, you can use dash dash universal.
But that really depends on whether the command allows that to be possible.
And each command is slightly different.
And one thing that became very clear in this video is that each command behaves very differently to
other commands.
So, for example, some commands can take multiple inputs and others take none.
Some can take long form options and others can't.
Some can have an equal sign to match option inputs with their appropriate option, and others can't.
So now that you understand the overarching command name, then options, then input structure that commands
follow and the different ways of implementing that and the different options that you've got.
How can you know what is possible for a specific command and how you use each specific command?
Well, each command actually comes with their own manual page or main page for short.
That shows you how to use them.
And in the next video, I'm going to be showing you how to access and read the man pages.
So just imagine having all the deets on a big catalog of computer programs just sat there waiting to
be explored.
Using the man pages is going to be a complete game changer for you if you want to become independent
in the way that you use the Linux operating system.
And I really can't wait to show it to you.
So for that goodness, I'll see you in the next video.