[Autogenerated] Now.
Yes, I can see by that face, you're probably not that impressed.
Are you however, remember we are just making a start.
But of course,
there is a lot more that we can do with sd an our line
numbering just take a look at this.
We can elevate our privileges with sudo end said.
And of course, we can write to our E T C host file to begin with though.
We probably don't want to write.
So we haven't specified to edit the file.
So we're just printing everything through to the screen.
But look at this.
We're going through to our last line of the dollar
and we're app pending a new entry.
If that all looks good, we can edit the file.
Now, you might say, well, OK, why don't we use redirections?
Well, redirections isn't going to work using sudo because the redirections,
our operators that are working at the shell level.
So this becomes an easy way we can append to the last line of our file.
But of course, if we have appended,
we might need to delete that entry when we no longer want it.
So it's very easy then to go through and remove the last line dollar D.
But also we might want to insert as the first line.
We might want a little bit of header information,
a pen put after the line I for insert, inserts before the line.
So we can go to line one and insert a new comment
saying that this is managed by set.
When we take a look at some of the tools that we've used here,
we've used the minus I for our in place edit.
We're using A to append I to insert and D to delete.
But of course, we really need to practice this.
And I'll say you need a system where you have root access and you can gain that.
As you can see using sudo,
we're going to be moving out to our command line and start
seeing how we can really start os things.
The power of said by editing content by the line number.
We're going to see how easy it is to insert a pend and delete.
We're going to test first of all just by viewing our output,
either the complete file or just looking at certain lines,
our pattern match.
And when we are confident we can then do our in
place edit using the option minus I.
We'll also see how we can take this same strategy and use
it for editing files with VM very often.
If we've got an error in a file,
it will say we've got an error on line 253 or we can go directly to line 253
using these same mechanisms that we've been using with sd.
So, come on, let's really start increasing our power of the command line.
Hey, look at this, our glorious command line.
What we're going to really stretch to the power and abilities of sd?
Come on, let's do some powerful stuff.
Now, we might want to write through to our host file and as a standard user,
we might think that we can append to our host file using redirections.
Now, there's no reason why we shouldn't try that.
But even if I use S two an echo elevating our privileges with echo and
then we can try and maybe write an entry in for Google.
So 8.8 dot 8.8 and Google and append that to forward
slash E T C forward slash host, we can hit the big enter key.
But look at this, even with sudo permission is denied,
we're raising the privileges of an echo,
but the operator greater than greater than is coming from the shell,
not the command.
So we need to elevate SSH to be able to do this.
Now,
there are ways we could pipe the output of echo through to sudo and T
but we can easily do it with sd as well with said,
we don't have to make the edit straight away so we can print to the screen.
This gives us a really good way to make sure that
the edit we think we are making.
So here we're going to go through to the last line
of the file dollar and app end.
So we can see that the edit we think we're making is really the
edit that we're making before we commit it.
So we're elevating our privileges for sd.
Sd is reading the E T C host file and writing through to the screen And
we can see now that we've got our entry and that's OK,
8.8 dot eight and Google.
But if this was a larger file,
it might be difficult to see the information correctly.
So we could also go through and use the option minus N to suppress
our standard output and automatically we then just see the lines
that we've match within our pattern.
So if our edit then looks good, we're now ready to commit it.
We can change our option minus N to minus I for an in place edit.
So as easy as that,
we've been able to edit our file and edit it programmatically,
there's no need to open up an editor, go to the end of the file and edit it.
But of course, just in the same way as we've gone through and added that in,
we can print our last lines.
So as we saw before suppressing our output and dollar P,
we can go through and print out the last line of our file Now,
of course, having added our entry in,
we might do some testing and then without having made any other changes,
we want to delete that last line now that we've done our,
our testing.
And of course, we can then go back an up arrow key,
change the minus N to a minus I for our in place,
edit and change the P to be D for delete.
So we've got a to app end after a line D to delete the line.
Of course, going back now and printing the last line,
we can see its our 1 27 entry.
So all of this becomes really useful.
But again, I really want you to get some good hands on practice.
So maybe even work with your own files,
especially non critical files to make sure you can get the right
information correctly written through to your file.
But do you know as well as a pending and deleting?
We can also insert, insert is going to come before a line.
So if I go through then and put one, I,
we're inserting before line one and we can maybe put a comment in here so we
can go through and say manage by said or whatever we need.
But its very, very easy then to go through and put the comment in that we want.
If we now go through and clear our screen and take a
look at our E T C and host file,
you can see then that we've got our nicely configured comment.
Now, that might be a comment like we're putting in here,
but we can equally go through and put in into
scripts if they don't already exist.
So there's lots of things that we can start thinking
about of how we can put this to use.
But what we're learning here working with our line numbers can
also be used in other places at the command line.
If you're used to using the VM text editor,
you're going to know very often that you'll get an error coming back from a
configuration file saying there's a problem on line 273.
Or do we have to navigate all the way down to line 273?
No, we can tell vim that we want to go to that line,
whether it's line 273 or whether it's the last line of the file,
we can do things in exactly the same way as we've been
working at the command line with sd.
Do you want to try it?
Go on, I dare you sudo and win plus.
Well,
I don't have 273 lines but maybe go to line three for my
forward slash E T C forward slash hosts file.
And you can see my cursor is on the local host entry for IP version six.
So line three.
Well, OK, that's good.
That has worked and we can jump out of that we can
also use the dollar symbol here.
So if I go plus dollar, we're automatically going to the last line of the file.
So it becomes very easy for me to then quickly app end text to the
end of the file using my interactive editor.
If I can't or don't want to do it using sd.
So much of what we're learning here is also
going to help you in other mechanisms.
We don't want you just being able to master said we want you to be able
to master the Linux command line and become the guru.
You always wanted to be.