Author Jim Hoskins

Total Time 3 minutes 35 seconds

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

Launch Console

Teacher Notes

Advanced Editors

Video Transcript

  • 00:00

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

  • 00:04

    The text editor just allows us to edit text.

  • 00:07

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

  • 00:11

    The one we'll be using is called nano.

  • 00:14

    Now, nano is another of those programs that actually modeled

  • 00:17

    after Unix program and named slightly differently.

  • 00:20

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

  • 00:27

    So Pico and nano are both types of small measurements.

  • 00:30

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

  • 00:33

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

  • 00:37

    but we'll be using the nano program.

  • 00:39

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

  • 00:44

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

  • 00:47

    Now, this is another full screen program.

  • 00:50

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

  • 00:55

    and that we're using a program called nano.

  • 00:57

    At the bottom, there are some controls.

  • 01:00

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

  • 01:04

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

  • 01:11

    And, how do we actually save this.

  • 01:13

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

  • 01:15

    like a menu or really a shortcut sheet.

  • 01:19

    The caret you see here represents the control key.

  • 01:23

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

  • 01:27

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

  • 01:34

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

  • 01:38

    on our keyboard to perform different actions.

  • 01:40

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

  • 01:44

    which we can scroll through using our arrow keys.

  • 01:48

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

  • 01:51

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

  • 01:55

    And now we're back into our editing mode.

  • 01:58

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

  • 02:01

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

  • 02:06

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

  • 02:11

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

  • 02:16

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

  • 02:20

    So we could just hit enter and it saved it.

  • 02:23

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

  • 02:28

    hello line has shown up and we saved it.

  • 02:36

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

  • 02:39

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

  • 02:46

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

  • 02:48

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

  • 02:50

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

  • 02:56

    It's pretty easy to use.

  • 02:58

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

  • 03:02

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

  • 03:05

    but with some very basic functionality.

  • 03:09

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

  • 03:12

    and those are super powerful and are awesome to learn

  • 03:16

    except that they are really sort of difficult to learn.

  • 03:19

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

  • 03:22

    they're extremely powerful.

  • 03:24

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

  • 03: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
Extra Credit

Try creating a folder that contains several text files. Try organizing notes using these files.

Downloads

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

Sign up