Bummer! This is just a preview. You need to be signed in with a Basic or Pro account to view the entire video.

Start a free Basic trial
to watch this video

Sign up for Treehouse

Editing Files


In this video we will see how to use the program nano to edit the contents of a file inside the console.

Teacher's Notes

Advanced Editors

Video Transcript

  • 0:00

    Now, we can actually edit a file. Now, in order to edit a file, we need a text editor.

  • 0:04

    The text editor just allows us to edit text.

  • 0:07

    Now there are quite a few options for text editors that work on the console.

  • 0:11

    The one we'll be using is called nano.

  • 0:14

    Now, nano is another of those programs that actually modeled

  • 0:17

    after Unix program and named slightly differently.

  • 0:20

    The old Unix program is called Pico and this version that's free and open source is called nano.

  • 0:27

    So Pico and nano are both types of small measurements.

  • 0:30

    So you can see to take off from one name to the other

  • 0:33

    which means that Pico and nano are really alias towards the same thing

  • 0:37

    but we'll be using the nano program.

  • 0:39

    So nano works just by typing nano and the text we want to edit.

  • 0:44

    In our case, we'll say our hello.txt.

  • 0:47

    Now, this is another full screen program.

  • 0:50

    So you'll see the top there's a bar that shows us the name of the file

  • 0:55

    and that we're using a program called nano.

  • 0:57

    At the bottom, there are some controls.

  • 1:00

    So this works a lot like a normal editor with keys--arrow keys to move around.

  • 1:04

    If we start typing things, we type another line here.

  • 1:11

    And, how do we actually save this.

  • 1:13

    So you'll see at the bottom, there's something that's a little bit

  • 1:15

    like a menu or really a shortcut sheet.

  • 1:19

    The caret you see here represents the control key.

  • 1:23

    On your keyboard, this should be towards the bottom and either on the left

  • 1:27

    or both left and right side and should be labeled control or Ctrl.

  • 1:34

    Now, this is a modifier key that allows us to use different letters

  • 1:38

    on our keyboard to perform different actions.

  • 1:40

    For instance, if we type Ctrl-G, we get the help,

  • 1:44

    which we can scroll through using our arrow keys.

  • 1:48

    You'll notice that the commands at the bottom have changed,

  • 1:51

    and now if we want to exit we use Ctrl-X.

  • 1:55

    And now we're back into our editing mode.

  • 1:58

    So if we wanted to exit nano, we could type Ctrl-X.

  • 2:01

    Now, it's asking us if we want to save our changes. In our case, we do.

  • 2:06

    So we'll type in the Y-key. If we wanted to cancel out of this, we hit Ctrl-C.

  • 2:11

    So if we'll type in Y, it says--it's now asking the filename to write

  • 2:16

    and it's giving us the current filename, so we're going to overwrite it.

  • 2:20

    So we could just hit enter and it saved it.

  • 2:23

    And so now if we type in less hello.txt, we can see our new

  • 2:28

    hello line has shown up and we saved it.

  • 2:36

    So we can use those commands down at the bottom to move around

  • 2:39

    as well as move through pages, cut and uncut which will be pasting texts, and some other things.

  • 2:46

    We can read the help if we want to know more about it,

  • 2:48

    but if you're on the console and you need to edit a file,

  • 2:50

    I highly recommend nano or maybe Pico if that what's available on the system.

  • 2:56

    It's pretty easy to use.

  • 2:58

    It's not a huge feature set but as far as editing files it should be pretty familiar.

  • 3:02

    It's like a normal text editor that you may use on your system

  • 3:05

    but with some very basic functionality.

  • 3:09

    Now, there are some others you may have heard of like Vim or Emacs,

  • 3:12

    and those are super powerful and are awesome to learn

  • 3:16

    except that they are really sort of difficult to learn.

  • 3:19

    They take a little while to learn, but once you know how to use them,

  • 3:22

    they're extremely powerful.

  • 3:24

    So when you're just beginning, nano is the tool you should reach for when editing a file.

  • 3:29

    So I'm going to exit out of here, and since I didn't make any changes, it didn't modify anything.

Show full transcript


You have to sign up for Treehouse in order to create workspaces.

Sign up


You have to sign up for Treehouse in order to download course videos.

Sign up


  • Jim Hoskins

    Jim is a full stack software developer at Treehouse. When he's not writing code, he's blogging, teaching, or speaking at conferences. On Twitter he is @jimrhoskins.