Hello.
The beautiful people know at the end of the last video, I gave you a little bit of a teaser about something
called aliases.
Now, aliases are basically little nicknames for your commands or for your command pipelines that make
them a lot easier to remember.
Now, in this video, you're going to be learning how to create your very own command aliases.
So very exciting.
Now, in this video, I'm going to walk you through step by step, everything you need to do to create
your own command aliases.
And by the end of the video, you should have all the skills that you need in order to create easy to
remember nicknames for your pipelines so that once you've written them, no matter how complicated they
are, you can just use them over and over and over again without typing them all out, just using instead
the easy to remember nickname.
So this is super cool stuff and let's go ahead and jump right into it.
Okay.
So the first thing you need to do to start creating your own command aliases is to create a special
file called Bash Aliases in your home folder.
So to do that, to create the file, what we want to do is we want to click on activities at the top
left and then in the search bar here, just type the word text.
And it should come up with a thing that says Here, Text editor, just click on that and it will open
up a new window where we've actually got a file.
Now there's a button at the top here where you can click that says Save.
So I'm going to click Save and in my home folder I'm going to type a file that starts that.
It needs to be spelled exactly the way that I'm going to tell you.
So first of all, you type a period or full stop, then you type bash base all in lowercase, then an
underscore, then aliases.
So s okay, so that's bash underscore aliases with a period or full stop at the beginning, everything
in lowercase and then go ahead and hit save.
Okay so now we have our bash aliases file and actually I don't think for the for the minute we'll need
the terminal.
So I'm just going to close that as well.
So make sure it is spelt exactly as it is up here.
Full stop then bash underscore aliases, aliases, everything in lowercase.
And once you've got that, we should be all good to go.
So now you might be wondering why did we actually need to name the file with a full stop at the beginning?
That's quite strange.
We don't normally name files like that, do we?
Well, that full stop makes the file a special type of file called a Hidden File.
So if we go back into the file browser here and we look at our home folder, you'll see that the bash
aliases file isn't actually there.
Oh, where has it gone?
Well, it's a hidden file, so it's kind of hidden.
But where it actually is, if you click on this button here with the three bars, if you click that
and then click on down here, there'll be a checkbox that says Show Hidden Files.
If we check that, we'll be able to see that our Bash Aliases file has been created.
But there are actually also plenty of other plenty of other hidden files here that we hadn't seen before.
But here we are.
Here's our bash alias file that we're currently editing as well as actually even some hidden folders
that maybe you didn't even know were sneaking around your system.
But anyway, we don't need to worry about those for now.
Let's just go ahead and click those three bars again and undo viewing hidden file so it all disappears
again.
So we don't have to continue looking at monsters under our bed and now we can go ahead and actually
keep editing the bash alias file.
Okay.
So now that we're in our batch alias file, making an alias is actually really quite easy.
So here's the command that we want to make an alias for.
It's going to be a really long command with loads of complicated stuff in it.
But we can do this, okay?
It's there's nothing new.
It's just quite it's just quite long.
So we're going to type the date command.
We're going to pass that into the cut command.
We've seen this a bajillion times, right?
We're going to tell it that the delimiter is a space and we're going to get the first field.
Now, we also want to have a copy of that data.
We want to take a snapshot.
So we're going to take the T command and save that in a file in our home folder called full date txt.
Okay.
So we're doing well so far.
Then we're going to take a snapshot of just the day of the week.
We're going to save that in our home folder in a file called Short Date txt.
And then everything that comes out, we're going to pass into the echo command, but also give the echo
command its own argument.
Whew, that's quite a long command.
Right?
So we're doing a lot of stuff in here.
But the point is that it's long because then you can see how useful aliases are, right?
So the only thing to make it work for your computer is instead of having Ziad Well, unless in the one
in a bajillion chance that your name is also Ziad and you chose it to be your username on your virtual
machine, which I think is unlikely.
But if you are, send me a message, but otherwise just go ahead and change that with your username
so that it matches the correct path on your computer.
Otherwise you're going to start getting errors.
Okay, so just if you, if your username was, you know, Sally, just change it to be Sally, but mine
was Ziad, so I'll keep it at that.
Okay.
So this is the command that we want now to make an alias for it.
Let's say, for example, we wanted to instead of typing out this massive command every time we wanted
to do it, instead of just typing out that, what if we wanted to just type, get dates and that was
going to be our alias?
Well, all we have to do is just type the word alias, which is a special word.
Then press a space, then get dates.
An equal sign and then an apostrophe on either side of that command.
So you can see there's an apostrophe here and there's an apostrophe here.
So like a single quote on either side of the whole massive command, then alias at the beginning, the
name of the alias and equals sign and then quotes on either side of the massive command.
So what we're saying is, Hey, I want to make an alias called Get Dates.
That is exactly equal to this command.
Now when we save it and close it, so we need to close the the editor.
So we go, we click on these three, these three bars over here, click close OC and close.
All of this in general, I think let me just drag that down and close.
Now, when we open our terminal, when we reboot our terminal, that alias should be loaded.
Okay.
So I want you to think of these aliases as being like your own commands.
So if we try and run the get dates command, shall we call it?
If we go ahead and press enter remembering that get dates was the name of our alias we actually get
some output, so that's pretty cool.
Now if we go ahead and look in our in our home folder, we'll also see that two new files have been
created.
So we've got full dates and short dates.
So let's go ahead and take a look in full data.
TXT We've actually gone and got the full date.
All the data has been passed into that and short date dot txt has had just the day of the week passed
in.
Isn't that awesome?
Okay.
Because this has come from the alias.
If I delete those and go ahead and run the get dates command again, we see that the files have been
created one more time with the same data in them.
So this is super cool, right?
Like instead of typing out that really really really long alias, that really, really long command,
every time we wanted to get that functionality because we've created an alias and basically given a
cute nickname to the command get dates instead of the massive pipeline, we can now get the same functionality
but in a much easier to remember way and a way that's actually easy to reproduce.
So that's really awesome.
But now let me show you something super cool.
You can actually also use aliases in bigger pipelines, so think of your alias as just being its own
pipeline, right?
If your alias if that mini pipeline that you save can accept standard input, if the first command in
it can accept standard input, then you can just pipe to the alias and run the whole pipeline and then
pipe out of the alias and continue on.
It's like having your own little pipeline building block so let me show you.
Okay.
Let's say that we wanted to have an alias for our command that showed a calendar with one month before
and one month after the current month.
So the command for that would be KAL then A one, B one.
So after one month before one month and we get the current month with one month after and one month
before.
So that's the command.
If we go and head back in here, click these three horizontal arrows, horizontal bars, sorry, and
show hidden files.
Click on our bash aliases file to open it up and go on to a new line in the file.
Let's create a new alias for that command.
So we're going to say alias.
We're going to say cow magic, short for calendar magic, and we're going to type in equals sign.
And then you can actually type some speech marks.
You don't have to have the single quotes, you can have speech marks as well and we're going to type
in their KAL.
Then the a option, give it a number one as its own argument, then a, B, capital B, then one is
its own argument and we're going to output that into a file in my home directory called thing txt.
And of course remember to replace this bit with your username that you're using on your virtual machine.
So we're going to call that cow magic.
But the cow command here, right, the cow command only accepts command line arguments.
You can't pipe to the cow command by default.
So to make this a valid pipeline that you can actually this this whole cow magic thing, a valid pipeline
that you can pipe to we need to actually put the x args command at the beginning.
So let's just do that.
If you don't understand what I'm doing at the minute, just bear with me, okay?
We're just making a building block, this whole thing that we can pipe to.
Okay, so that's what we've done right there.
Now, whatever's going to be pipe to cow magic will actually be piped to the x args command, which
will then convert the data from standard input, which cow doesn't accept to command line arguments,
which cow does accept.
And so therefore the whole pipeline will work.
This is going to be awesome.
Just trust me.
Okay, let's go ahead and do this.
Let's close.
Let's save and close the close that close everything and close our terminal and reboot it.
So I'm going to press control.
Alton T Terminal about terminal.
Now if I echo 12, 2017 into cow magic, what's going to happen is I'm going to be echoing this data
as command line arguments to the cow magic command.
So what we're expecting to happen is that we're expecting that we're going to get December 2017, the
calendar for it with a month before and a month after.
Okay, save to a file in our home directory.
So if I press enter, we don't get any output.
But if we go into our files here, we will see that there is a file in here called here thinks text
that we've actually managed to save the calendars for December.
So December 2017, one month before and one month after into a file called thing txt in our home folder.
And the reason that happened, it's probably a lot easier to see if I actually get rid of these hidden
files.
No, no, I will.
I will keep.
Because otherwise I'll lose where I am.
But what happened is we echoed.
We basically passed to the X Command to piece of information, but it 12 and 2017, which were then
given as command line arguments to the calendar command.
So you can see how all this stuff is starting to tie together.
Right.
And we've made a mini pipeline called Cow Magic that will now be able to run a command whenever we want.
So we don't have to type out this ugly thing.
We just have to remember cow magic.
And because we made it possible to pipe to the first command in our alias, the whole pipeline will
work and we can just use it like a mini building block in whatever programs that we want to make.
So how awesome is that right?
Can you see how crazily powerful the ability to write aliases for pipelines and use those aliases in
other pipelines can actually be right.
The possibilities really are limitless with what you can achieve with that ability.
So let's just leave it there.
I'm going to leave your mind blown with that.
And let's just go ahead and now take a summary of what we've learned about aliases.
So that's enough being mind blown for now.
I hope you're as excited as I am by what you've learned in this video about aliasing.
Aliasing is an absolutely incredible ability with really limitless potential if used in the right way.
So let's just have a quick recap to make sure that you've got it all down.
So in this video, first of all, you learn that an alias is basically just an easy to remember nickname
for a command or a series of commands.
Join together in a pipeline.
Now to create an alias, you need to first have a file called Dot Bash, underscore aliases or in lowercase
in your home folder.
And that's where you actually put you.
That's the file that you actually put your aliases in.
And these aliases, therefore, will be specific to your user.
Now, as a bonus point, you learn that a period or full stop or a dot at the start of a file name makes
that file hidden.
So and you also saw how to turn on or off the visibility of hidden files in your file viewer.
Okay.
Now inside the bash alias file, you saw that it was actually quite easy to make an alias, right?
This is the way that you do it.
First you type the keyword alias all in lowercase, then you put a space and then you put the alias
name.
So as was get dates or it was cow magic or whatever you want to call it, that's your nickname.
Then you put an equal sign without adding a space without a space at all between the alias and the equal
sign you put in.
So you just put it in equal sign immediately, then you open some quotes.
These quotes can be either single quotes using an apostrophe or, you know, normal double quotes like
you would use for speech marks again without any spaces, without any gaps.
Between that and the equal sign, then you just create your pipeline or you use your command.
Again, you can have options and command line arguments just like you normally would.
Okay, these can go on for as long as you want now.
As long as you make sure that you restart your terminal, you'll then have access to that alias forever.
And as another bonus point, look at you.
Look, you get two bonus points in this summary.
You should be very it should be feel very spoiled.
But as long as you make sure the first command in that alias in that pipeline can actually be piped
to OC, then you can just pipe to the alias, pipe to the nickname, and it's as if you're piping to
the whole pipeline.
If I say the word pipe one more time, I'm probably going to go insane.
But you get the point, right?
If you make it so that your pipeline can be piped to either by using the x args command or by just using
a normal command that can accept standard input, then instead of having to, you can basically use
that alias, that mini pipeline as a tiny building block in some massive other pipeline that you're
building to create a really epic bit of functionality.
So aliases using the right way with what you've learned about piping and x args and all sorts of stuff,
making these long pipelines is an epic, epic ability.
So now you can build your own command pipelines and even save them for use later when you understand
that basically anything in the Linux operating system can be modified using command line.
You've really understood the crown jewel that makes the Linux operating system so amazing because anything
can be edited using the command line and you know how to create these commands, how to use these commands
and pipe them all together to do whatever you want.
You've really got a master key there to take your computing to the next level, but in order to take
advantage of this, all you need now are just some more building blocks to actually build your pipelines
with, right?
So in the next section of the course, we're actually going to be covering a whole bunch of those building
blocks because the next section of the course is all about navigating your file system, creating a
manipulating files, making folders, copying and pasting files, creating backups of your system,
and so much more.
But before we get into all that goodness, I want to make sure that you understand everything that we've
covered in this entire section of the course first, because it's been an incredibly foundational,
incredibly important section of the course.
And if you understand everything in this section, you will not go far wrong with anything else you
learn when using Linux.
And I also want to make sure that you're duly congratulated for your amazing progress so far.
You really, really deserve to have some recognition of what you've done in this section, what you've
learned, and how far you've come.
So in the next video, we're going to have a celebration of your really impressive progress and a quick
recap of what we've covered in this section.
It's going to be awesome.
So for review of this section and some well deserved celebration and praises, I will see you in the
next video.