Check out a free preview of the full Complete Intro to Linux and the Command-Line course

The "nano" Lesson is part of the full, Complete Intro to Linux and the Command-Line course featured in this preview video. Here's what you'd learn in this lesson:

Brian gives an overview of text editors already available within the command line, and starts with nano, one of the most common and available options.

Preview
Close

Transcript from the "nano" Lesson

[00:00:00]
>> So, let's get into everyone's favorite discussion, text editors. [LAUGH] This is not a contentious topic at all, especially from someone that works on the Visual Studio Code team. [LAUGH] So someone from the Visual Studio Code team is going to teach you how to use other text editors.

[00:00:18]
So, the next one we're going to get into is one called nano. Now, the reason why I'm going to teach you these things is I still want you to use Visual Studio code. I still think it's objectively the superior editor, and I will fight people on that. But there's just a long running joke that people get stuck in them, right?

[00:00:37]
And I don't want that. So, I'm going to show you how to quit them. That's basically the extent of what I'm going to show you today. But I'm also going to show you how to use nano as a little bit, because it is frequently useful to be able to edit text in the command line and it's good for you to know how to use the two most common ones.

[00:00:54]
I guarantee you on any Linux distro, you always have least nano or vim available to you, hopefully both, usually both. And I just want you to know how to use them and how to quit them. That's it. So, I've never been a command line editor person, I've always used, I started with textmate.

[00:01:14]
And then I moved to sublime, and then I used the Visual Studio code. And I've never even really tried to use vim as like a professional tool. I think it's great if you know how to use it, high fives all around. You're probably not taking this course if you're a vim professional, so.

[00:01:31]
Or maybe you are, I don't know, I could be surprised. But man, I just hate having these discussions, particularly with people that think they're superior because of the text editor that they chose, which is why I put this XKCD in here. It's one of my favorite ones about real people, real programmers use butterflies to redirect light rays and that flip bits on hard drives.

[00:01:57]
That's the real way of programming. People don't use cat or Ed or vim or Emacs or anything like that. So yeah, that's from XKCD. I left it linked here. That's from Randall Munroe, who's so fantastic. There's like four more XKCDs in here, because if you're doing command line, nano makes a lot of command line jokes.

[00:02:19]
So, all this to say, these are all great tools. If you know how to use them, then the tool is as good as the master using it, right? So yeah, that's all I want to say. I want you to not be afraid of these tools, like I know whenever I got thrown into vim, like when I was really early in my career, I would get so frustrated.

[00:02:40]
There's an article on Stack Overflow about how they have like a separate server or a separate specific caching strategy for how to quit vim. Because it's like 80% of their traffic, or something ridiculous like that. So, yeah, it's a problem. If you get thrown into vim and don't how to quit it is the most frustrating thing, because control C and control D both don't work with vim.

[00:03:06]
But let's talk about nano first. So, the reason why I talk about nano is because nano is so small, and it's on literally everything. So, if you need to edit a text file, sometimes vim won't be available. And frequently nano will be the default one. So, sometimes you just get chucked into nano.

[00:03:25]
And if you don't know how to exit it, it can be a little odd. So, nano is a very old open source editor, and it's based itself on another editor called Pico. And Pico was part of a mail client. So, people wrote emails using Pico, but they liked it so much that they actually broke it out of, what was the name of that?

[00:03:49]
Pine, it was called Pine, was the name of like the suite for editing emails and a bunch of other stuff. And they had Pico built into it, but it wasn't licensed in such a way that people could use it. So, they broke it down and they called it nano.

[00:04:01]
It was called TIP for a while, which is called Tip isn't Pico. This is another thing that computer scientists just think that they're hilarious they love to do which is called the recursive acronym, which is an acronym that's defined in terms of itself. Another one would be PHP, which is PHP stands for PHP, hypertext preprocessed, right?

[00:04:21]
That's what Pico is as well, Tip isn't Pico, or that's what TIP was, and then they renamed it eventually to nano. Computer scientists are silly in the weirdest ways. So, it's tiny, it's lightweight, it's very permissively licensed. And so, everyone has nano on their even tiny like embedded devices.

[00:04:47]
nano is so small it's often even on those because it is so small. So, it's good just to know enough about nano that you're not afraid of it, you can use it if you need to. So, let's just go ahead and hop into it. Open back here, and I'm in my home directory here.

[00:05:08]
So, I want you to type nano textfile.txt. This is gonna pop you into nano, which again is maintained by the GNU project, which is like a lot of these programs are. So yeah, nano was written actually at the University of Washington, which is cool for me cuz I'm from Washington.

[00:05:31]
Yeah, that's where Pine was from, and they rewrote it so that they could have a better license for it. Because Pine was not licensed in such a way that the GNU felt comfortable including in its projects. So, that's where nano came from. So, right now I'm just in a text file.

[00:05:50]
So, this is a text file. I can write whatever I want. This is so cool, right? Normal text editor stuff, and you can see down here at the bottom, I have a bunch of different options. I don't really know very much about nano. I know enough to write text and save and quit.

[00:06:13]
And that's really all probably you need to know. I don't know any developers that use nano for their code editing. It's really just for very basic text editing. But I wanna show you going back to this character right there down here at the bottom, that's Control, so Exit would be Ctrl X, get help would be Ctrl G, and then write out is a weird way to say save, right?

[00:06:43]
So, if I wanted to save this file, I would hit Ctrl O. And then it says, do you want to write to the same file? I said yes I do. So, I just hit Enter. And now I have saved to the file. And now if I want to exit, I'm just going to hit Ctrl X, and I am out of nano.

[00:06:58]
And if I open it again, everything comes back the way it was. I think if it's the file is not saved, if I do this you can see at the top right it says modified. If I hit Ctrl X, it's going to say, are you sure? Or is it do you want to save?

[00:07:15]
Or do you want to just go? So, if I hit yes, Enter, I saved it, I exited. And you can see there, my gibberish is there at the end. Cool, that's really all I'm going to show you about nano. There's more to it. It's a decent text editor with some basic features to it, but you're not going to do anything more than just write a couple lines and then exit out of it.

[00:07:46]
Any questions about nano? Cool, yeah, it's meant to be very simple. All right. Yeah, I think the thing to say is like, if I have to do anything more than what I just showed you there, is like I will figure out how to get the file into VS code and then I'll edit everything in VS code and put it back into the file.

[00:08:13]
But if it's just a couple of lines, I don't mind popping into nano really quick to do that.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now