1 00:00:00,090 --> 00:00:01,440 Hello the beautiful people. 2 00:00:01,440 --> 00:00:05,910 And welcome to this video where you're going to learn how you can edit files from the command line using 3 00:00:05,910 --> 00:00:08,940 a really cool command line program called Nano. 4 00:00:08,940 --> 00:00:14,610 So in this video and the next video, I'm going to be showing you how you can use a command called Nano 5 00:00:14,610 --> 00:00:19,290 to edit and create files using a user friendly command line interface. 6 00:00:19,290 --> 00:00:22,950 And by the end of the next few videos, you're going to know how to edit files in Nano. 7 00:00:22,950 --> 00:00:27,210 And when you combine this with the commands that you've already learned so far in this section, it's 8 00:00:27,210 --> 00:00:31,920 very likely that you'll be able to get many of your file related tasks done with Linux without ever 9 00:00:31,920 --> 00:00:36,900 having to leave the command line, and therefore you'll be able to maximize your productivity on Linux. 10 00:00:36,900 --> 00:00:38,280 So this is going to be awesome. 11 00:00:38,280 --> 00:00:40,470 So let's go ahead and get right into it. 12 00:00:42,460 --> 00:00:43,180 All right. 13 00:00:43,180 --> 00:00:49,560 So in this lecture, we're going to make a file called Diary Direct txt using the nano command. 14 00:00:49,570 --> 00:00:54,260 Now the diary text file doesn't actually exist yet, but that's okay. 15 00:00:54,280 --> 00:00:57,460 We can also create the file using nano. 16 00:00:57,460 --> 00:01:00,520 So if we type, let's go to the desktop first. 17 00:01:00,520 --> 00:01:09,700 Let's head over to the desktop and then if we type nano diary dot txt and I press enter, you'll notice 18 00:01:09,700 --> 00:01:15,760 that our terminal has changed its look and we're actually now editing a file called direct txt as you 19 00:01:15,760 --> 00:01:23,230 can see at the top in the nano editor, as you can see here, nano version 2.8.6. 20 00:01:23,230 --> 00:01:26,800 Apparently now we can type whatever we want in here. 21 00:01:26,800 --> 00:01:36,160 So for example, I could type hello, my name is Ziad and I teach Linux and Python courses and more 22 00:01:36,730 --> 00:01:42,460 and it works just like any other graphical text editor that you've ever used before. 23 00:01:42,670 --> 00:01:44,890 You can just type directly there in the shell. 24 00:01:44,890 --> 00:01:50,110 Now down the bottom you can see that there's actually a little toolbar that tells you some of the things 25 00:01:50,110 --> 00:01:55,480 that you can do in Nano, and the options are in the white squares and they're in the form of keyboard 26 00:01:55,480 --> 00:01:56,140 shortcuts. 27 00:01:56,140 --> 00:01:57,310 So literally you had to read them. 28 00:01:57,310 --> 00:02:03,940 Okay, so in Nano, the little arrow head that you see here, the little hat or the carrot symbol, 29 00:02:03,970 --> 00:02:07,510 means the control key on your keyboard. 30 00:02:07,510 --> 00:02:12,880 So for example, here we have the get help command, we have the get help I guess, option from the 31 00:02:12,880 --> 00:02:13,600 toolbar. 32 00:02:13,600 --> 00:02:20,140 And it's given this this shortcut here, it's got the the arrow head and then a capital G. 33 00:02:20,140 --> 00:02:25,870 So if we press control on our keyboard and press G, which is exactly what we're doing, just control 34 00:02:25,870 --> 00:02:28,870 and G together, that executes that command. 35 00:02:28,870 --> 00:02:34,810 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 36 00:02:34,810 --> 00:02:36,640 help about using Nano. 37 00:02:36,880 --> 00:02:37,340 Okay. 38 00:02:37,450 --> 00:02:44,410 And we can see here that there's some to close this we would need to press control and X because you 39 00:02:44,410 --> 00:02:46,420 can see the little arrow and then an X. 40 00:02:46,420 --> 00:02:50,230 So for it, control and x, we're back out of there and we're back writing. 41 00:02:50,320 --> 00:02:50,920 Okay. 42 00:02:51,790 --> 00:02:59,050 We can also close nano, for example, by pressing control and X and it will say, Do you want to save 43 00:02:59,050 --> 00:02:59,560 yes or no? 44 00:02:59,560 --> 00:03:02,740 Let's just click cancel by control and see. 45 00:03:03,190 --> 00:03:03,580 There we are. 46 00:03:03,580 --> 00:03:04,060 We've cancelled. 47 00:03:04,060 --> 00:03:04,900 We're still back in. 48 00:03:05,320 --> 00:03:06,790 So how would we save this file? 49 00:03:06,790 --> 00:03:08,200 How do we save this diary. 50 00:03:08,200 --> 00:03:11,350 Dot txt in in our home folder. 51 00:03:11,350 --> 00:03:12,520 Well sorry on our desktop. 52 00:03:12,520 --> 00:03:17,140 Sorry because you can see up here our show prompt says that we're in our desktop. 53 00:03:17,830 --> 00:03:22,120 Well, to do that in Nano you would use the write out function. 54 00:03:22,120 --> 00:03:25,990 So writing a file is a fancy way of saying saving a file. 55 00:03:26,230 --> 00:03:29,380 So saving and writing are basically the same thing. 56 00:03:29,380 --> 00:03:32,290 And so to write a file we need to press control. 57 00:03:32,290 --> 00:03:37,420 And oh, so we've got the arrow, the little carrot symbol here, which means the control key and oh, 58 00:03:37,450 --> 00:03:43,450 so that means we press control and oh, and now it's asking us what do you want to save it as let's 59 00:03:43,660 --> 00:03:47,500 save it as diary lock txt and we press enter. 60 00:03:47,680 --> 00:03:54,070 It'll say it wrote three lines but you can see here that we've actually got diary dot txt. 61 00:03:54,100 --> 00:03:58,540 So if we open that in any other editor, we can see that that file has indeed been created. 62 00:03:58,540 --> 00:04:00,010 So I could write something in here. 63 00:04:00,010 --> 00:04:07,090 I could say like something like Jack and Jill went up the hill. 64 00:04:07,600 --> 00:04:10,960 All right, then press control and oh, press enter. 65 00:04:11,320 --> 00:04:16,660 And if I press control and X to exit, it's gone away. 66 00:04:16,660 --> 00:04:20,110 But if I look inside diary of txt it's saved that data in there. 67 00:04:20,110 --> 00:04:21,399 Jack and Jill went up the hill. 68 00:04:21,399 --> 00:04:26,950 So it's Nano is a text editor that you can control from the command line. 69 00:04:26,950 --> 00:04:28,060 So isn't that incredible? 70 00:04:28,060 --> 00:04:33,520 You can now edit files without needing to load up graphically intensive editors and plus working with 71 00:04:33,520 --> 00:04:35,740 files like this will work pretty much anywhere. 72 00:04:35,740 --> 00:04:41,440 Even if you have remotely accessed a server that might not have a graphical user interface installed, 73 00:04:41,440 --> 00:04:44,260 text editors such as Nano will still work. 74 00:04:44,260 --> 00:04:45,940 So what other things can Nano do? 75 00:04:45,940 --> 00:04:48,280 Well, let's just work our way across the options. 76 00:04:48,280 --> 00:04:54,250 Now we've seen how to get help, how to quit using control and X and how to write or save files using 77 00:04:54,250 --> 00:04:54,550 control. 78 00:04:54,550 --> 00:04:56,950 Now what about the read file option down here? 79 00:04:56,950 --> 00:05:03,190 The control and ah, well read file allows you to get content from another file and basically place 80 00:05:03,190 --> 00:05:04,600 it inside of this one. 81 00:05:04,600 --> 00:05:12,640 So if I head back to our shell, if we exit and we try to create a file that says Happy Birthday and 82 00:05:12,640 --> 00:05:16,090 we echo Happy Birthday into a file called birthday. 83 00:05:16,360 --> 00:05:23,980 TXT we can see that birthdate txt has been created and if we back open up again the diary dot txt and 84 00:05:23,980 --> 00:05:29,770 we head down the bottom and we press control and r control and R is for read file and it's going to 85 00:05:29,770 --> 00:05:35,200 say which file do you want to insert and notice it says from dot slash. 86 00:05:35,200 --> 00:05:37,540 So that means from this directory. 87 00:05:38,020 --> 00:05:40,780 So let's let's try and tell it that. 88 00:05:40,780 --> 00:05:41,560 So the one we. 89 00:05:41,760 --> 00:05:48,570 To actually insert data from is birthday text and if I press enter you can see that happy birthday has 90 00:05:48,570 --> 00:05:54,000 just been inserted so that's that's reading files what about the where is option? 91 00:05:54,000 --> 00:06:00,810 Well the where is option is control and W and what that does is basically search for words in your file. 92 00:06:00,810 --> 00:06:07,470 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, 93 00:06:07,470 --> 00:06:10,620 so let's search for the word birthday. 94 00:06:10,620 --> 00:06:16,890 So if we type a birthday and press enter, we now see that Nano has jumped us right down to where the 95 00:06:16,890 --> 00:06:20,700 word birthday starts and so we can edit it from there on. 96 00:06:20,700 --> 00:06:26,670 Now by default, the where is option searches forward in a file and it searches in a case insensitive 97 00:06:26,670 --> 00:06:27,150 manner. 98 00:06:27,150 --> 00:06:30,270 So that means that uppercase and lowercase don't matter. 99 00:06:30,270 --> 00:06:37,350 So if I went up here and I searched for birthday or in uppercase, actually you can notice that it shows 100 00:06:37,350 --> 00:06:39,090 you what you searched beforehand. 101 00:06:39,570 --> 00:06:41,610 So I'm just going to put birthdate in uppercase. 102 00:06:41,610 --> 00:06:45,990 We can see that it actually didn't matter and it found birthday, even though birthday was all in lowercase. 103 00:06:45,990 --> 00:06:52,800 So where is searches in a case insensitive manner and all by default, search is forward. 104 00:06:52,800 --> 00:06:59,010 But if we head down to the bottom of the file, so if we shift down here and use control w again, you 105 00:06:59,010 --> 00:07:03,900 can see down the bottom, if I maximize the screen, maybe it makes it a bit clearer that there are 106 00:07:03,900 --> 00:07:07,230 actually other options that pop up as well. 107 00:07:08,100 --> 00:07:14,250 Now, some of these options begin with the the the carrot symbol, the hat, which means the control 108 00:07:14,250 --> 00:07:14,700 key. 109 00:07:14,700 --> 00:07:22,500 But some start with this M minus, you can see M minus C, M minus R, M minus B and minus J. 110 00:07:22,500 --> 00:07:24,420 So what's that minus mean? 111 00:07:24,420 --> 00:07:30,090 Well, that M minus stands for modify and this is usually the alt key on your keyboard. 112 00:07:30,090 --> 00:07:32,100 So the alt key. 113 00:07:32,220 --> 00:07:39,120 So you can see here that we've got the m m minus C option which stands for case sensitive. 114 00:07:39,720 --> 00:07:45,900 So if I press alt and see, you can see now that it has changed so that we are now searching in a case 115 00:07:45,900 --> 00:07:47,160 sensitive way. 116 00:07:47,670 --> 00:07:53,940 So if I now search for actually hold on as well because this is only going to search forward. 117 00:07:53,940 --> 00:07:59,010 So if I press Alt and B to search backwards as well, see, now we're going to search case sensitive 118 00:07:59,010 --> 00:08:04,830 and backwards for birthday in uppercase and we'll see that nothing was found, you see. 119 00:08:04,830 --> 00:08:10,860 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 120 00:08:10,860 --> 00:08:11,700 sensitive and backwards. 121 00:08:11,700 --> 00:08:16,890 But now if I search birthday all lowercase, we see that that has been found. 122 00:08:18,270 --> 00:08:20,160 So that's quite awesome. 123 00:08:20,160 --> 00:08:20,310 Right. 124 00:08:20,310 --> 00:08:22,920 You can also modify the way that these commands behave. 125 00:08:22,920 --> 00:08:28,470 So if you see M minus, that means press the alt key, the alt key on your keyboard. 126 00:08:28,470 --> 00:08:34,500 And if you see the the triangle, the hat, the little arrowhead, that's the control key on your keyboard. 127 00:08:34,500 --> 00:08:37,710 And that will cover pretty much everything that you'll do in Nano. 128 00:08:37,710 --> 00:08:40,500 So let's just head back to our normal menu here. 129 00:08:40,500 --> 00:08:44,460 So in the interest of time, we're going to cut the video here and we're going to pick it right up in 130 00:08:44,460 --> 00:08:45,210 the next video. 131 00:08:45,210 --> 00:08:48,870 We will go through the rest of the options that you have in Nano. 132 00:08:48,870 --> 00:08:50,130 So I hope this was useful. 133 00:08:50,130 --> 00:08:55,320 You've seen that Nano is a text editor that you can open from your command line that allows you to do 134 00:08:55,320 --> 00:08:59,460 all your file editing stuff without ever leaving the command line. 135 00:08:59,460 --> 00:09:00,660 So I could just say, here we go. 136 00:09:00,660 --> 00:09:06,150 We've got that text editor, make some changes, save it exit and we're back in the command line. 137 00:09:06,150 --> 00:09:10,980 So it gives you a really nice way of editing files and getting back to what you were doing. 138 00:09:10,980 --> 00:09:15,300 So let's just get rid of that, save it exit, clear the screen and we're good to go. 139 00:09:15,300 --> 00:09:16,260 Continue on with our work. 140 00:09:16,260 --> 00:09:20,520 So let's pick this up in the next video to take a look at the other options that Nano has to offer.