Hello the beautiful people.
And welcome to this video where you're going to learn how you can edit files from the command line using
a really cool command line program called Nano.
So in this video and the next video, I'm going to be showing you how you can use a command called Nano
to edit and create files using a user friendly command line interface.
And by the end of the next few videos, you're going to know how to edit files in Nano.
And when you combine this with the commands that you've already learned so far in this section, it's
very likely that you'll be able to get many of your file related tasks done with Linux without ever
having to leave the command line, and therefore you'll be able to maximize your productivity on Linux.
So this is going to be awesome.
So let's go ahead and get right into it.
All right.
So in this lecture, we're going to make a file called Diary Direct txt using the nano command.
Now the diary text file doesn't actually exist yet, but that's okay.
We can also create the file using nano.
So if we type, let's go to the desktop first.
Let's head over to the desktop and then if we type nano diary dot txt and I press enter, you'll notice
that our terminal has changed its look and we're actually now editing a file called direct txt as you
can see at the top in the nano editor, as you can see here, nano version 2.8.6.
Apparently now we can type whatever we want in here.
So for example, I could type hello, my name is Ziad and I teach Linux and Python courses and more
and it works just like any other graphical text editor that you've ever used before.
You can just type directly there in the shell.
Now down the bottom you can see that there's actually a little toolbar that tells you some of the things
that you can do in Nano, and the options are in the white squares and they're in the form of keyboard
shortcuts.
So literally you had to read them.
Okay, so in Nano, the little arrow head that you see here, the little hat or the carrot symbol,
means the control key on your keyboard.
So for example, here we have the get help command, we have the get help I guess, option from the
toolbar.
And it's given this this shortcut here, it's got the the arrow head and then a capital G.
So if we press control on our keyboard and press G, which is exactly what we're doing, just control
and G together, that executes that command.
And we can see here that we have now we're now in the Get Help menu and we can scroll down and see some
help about using Nano.
Okay.
And we can see here that there's some to close this we would need to press control and X because you
can see the little arrow and then an X.
So for it, control and x, we're back out of there and we're back writing.
Okay.
We can also close nano, for example, by pressing control and X and it will say, Do you want to save
yes or no?
Let's just click cancel by control and see.
There we are.
We've cancelled.
We're still back in.
So how would we save this file?
How do we save this diary.
Dot txt in in our home folder.
Well sorry on our desktop.
Sorry because you can see up here our show prompt says that we're in our desktop.
Well, to do that in Nano you would use the write out function.
So writing a file is a fancy way of saying saving a file.
So saving and writing are basically the same thing.
And so to write a file we need to press control.
And oh, so we've got the arrow, the little carrot symbol here, which means the control key and oh,
so that means we press control and oh, and now it's asking us what do you want to save it as let's
save it as diary lock txt and we press enter.
It'll say it wrote three lines but you can see here that we've actually got diary dot txt.
So if we open that in any other editor, we can see that that file has indeed been created.
So I could write something in here.
I could say like something like Jack and Jill went up the hill.
All right, then press control and oh, press enter.
And if I press control and X to exit, it's gone away.
But if I look inside diary of txt it's saved that data in there.
Jack and Jill went up the hill.
So it's Nano is a text editor that you can control from the command line.
So isn't that incredible?
You can now edit files without needing to load up graphically intensive editors and plus working with
files like this will work pretty much anywhere.
Even if you have remotely accessed a server that might not have a graphical user interface installed,
text editors such as Nano will still work.
So what other things can Nano do?
Well, let's just work our way across the options.
Now we've seen how to get help, how to quit using control and X and how to write or save files using
control.
Now what about the read file option down here?
The control and ah, well read file allows you to get content from another file and basically place
it inside of this one.
So if I head back to our shell, if we exit and we try to create a file that says Happy Birthday and
we echo Happy Birthday into a file called birthday.
TXT we can see that birthdate txt has been created and if we back open up again the diary dot txt and
we head down the bottom and we press control and r control and R is for read file and it's going to
say which file do you want to insert and notice it says from dot slash.
So that means from this directory.
So let's let's try and tell it that.
So the one we.
To actually insert data from is birthday text and if I press enter you can see that happy birthday has
just been inserted so that's that's reading files what about the where is option?
Well the where is option is control and W and what that does is basically search for words in your file.
So if we head back up to the top of the file and we press control and w now we can search for a word,
so let's search for the word birthday.
So if we type a birthday and press enter, we now see that Nano has jumped us right down to where the
word birthday starts and so we can edit it from there on.
Now by default, the where is option searches forward in a file and it searches in a case insensitive
manner.
So that means that uppercase and lowercase don't matter.
So if I went up here and I searched for birthday or in uppercase, actually you can notice that it shows
you what you searched beforehand.
So I'm just going to put birthdate in uppercase.
We can see that it actually didn't matter and it found birthday, even though birthday was all in lowercase.
So where is searches in a case insensitive manner and all by default, search is forward.
But if we head down to the bottom of the file, so if we shift down here and use control w again, you
can see down the bottom, if I maximize the screen, maybe it makes it a bit clearer that there are
actually other options that pop up as well.
Now, some of these options begin with the the the carrot symbol, the hat, which means the control
key.
But some start with this M minus, you can see M minus C, M minus R, M minus B and minus J.
So what's that minus mean?
Well, that M minus stands for modify and this is usually the alt key on your keyboard.
So the alt key.
So you can see here that we've got the m m minus C option which stands for case sensitive.
So if I press alt and see, you can see now that it has changed so that we are now searching in a case
sensitive way.
So if I now search for actually hold on as well because this is only going to search forward.
So if I press Alt and B to search backwards as well, see, now we're going to search case sensitive
and backwards for birthday in uppercase and we'll see that nothing was found, you see.
But if I do just like that control and w it's, you see it's saved as settings, it's going to be case
sensitive and backwards.
But now if I search birthday all lowercase, we see that that has been found.
So that's quite awesome.
Right.
You can also modify the way that these commands behave.
So if you see M minus, that means press the alt key, the alt key on your keyboard.
And if you see the the triangle, the hat, the little arrowhead, that's the control key on your keyboard.
And that will cover pretty much everything that you'll do in Nano.
So let's just head back to our normal menu here.
So in the interest of time, we're going to cut the video here and we're going to pick it right up in
the next video.
We will go through the rest of the options that you have in Nano.
So I hope this was useful.
You've seen that Nano is a text editor that you can open from your command line that allows you to do
all your file editing stuff without ever leaving the command line.
So I could just say, here we go.
We've got that text editor, make some changes, save it exit and we're back in the command line.
So it gives you a really nice way of editing files and getting back to what you were doing.
So let's just get rid of that, save it exit, clear the screen and we're good to go.
Continue on with our work.
So let's pick this up in the next video to take a look at the other options that Nano has to offer.