官术网_书友最值得收藏!

  • Learn Linux Quickly
  • Ahmed AlKabary
  • 494字
  • 2021-06-11 18:43:46

The nano editor

The nano editor is a very popular and easy-to-use command-line editor. You can open the nano editor by running the nano command:

elliot@ubuntu-linux:~$ nano

This will open up your nano editor, and you should see a screen like that in the following screenshot:

Figure 4: Inside nano

Now add the six lines that are shown in the following screenshot:

Figure 5: Add these six lines

Look at the bottom of the nano editor screen; you will see a lot of shortcuts:

Figure 6: nano shortcuts

I have included all the useful nano shortcuts in the following table:

Table 5: nano shortcuts

Notice that the Ctrl+O shortcut is triggered by pressing Ctrl and then the letter O. You don't have to press the + key or the upper case letter O.

Now let's use the shortcut Ctrl+O to save the file; it will ask you for a filename, you can insert facts.txt:

Figure 7: Saving the file

Then press Enter to confirm. Now let's exit the nano editor (use the Ctrl+shortcut) to verify that the file facts.txt is created:

elliot@ubuntu-linux:~$ ls -l facts.txt
-rw-r--r-- 1 elliot elliot 98 Apr 30 15:17 facts.txt

Now let's open facts.txt again to fix the false facts we have added there! To open the file facts.txt with the nano editor, you can run the nano facts.txt command:

elliot@ubuntu-linux:~$ nano facts.txt

The first line in the file facts.txt states that "Apples are blue." We certainly need to correct this false fact, so let's use the shortcut Ctrl+\ to replace the word blue with red.

When you press Ctrl+\, it will ask you to enter the word that you want to replace; you can enter blue, as shown in the following screenshot:

Figure 8: The word to replace

Hit Enter, and then it will ask you to enter the substitute word. You can enter red, as shown in the following screenshot:

Figure 9: The substitute word

You can then hit Enter, and it will go through each instance of the word blue and ask you if you want to replace it. Luckily, we only have one occurrence of blue.

Figure 10: Replacing blue with red

Press Y and BOOM! The word red replaced blue.

Figure 11: red replaced blue

There is one more word we need to change here. We can all agree that the Earth is not flat, right? I hope we all do! Now let's replace the word flat with round precisely as we did before, and the result should be like the one shown in the following screenshot:

Figure 12: flat replaced with round

Now let's save and exit the file. So we use the Ctrl+O shortcut to save and then Ctrl+X to exit.

The nano editor is pretty simple to use. And practice makes perfect, so the more you use it, the easier it will become for you. You can practice all the shortcuts in Table 5 as an exercise.

主站蜘蛛池模板: 锦屏县| 康马县| 铁岭市| 比如县| 固阳县| 东阳市| 施甸县| 柳河县| 麦盖提县| 绥阳县| 新津县| 林州市| 龙口市| 勃利县| 神池县| 英超| 临泽县| 阿坝县| 奉贤区| 碌曲县| 汝阳县| 依兰县| 金塔县| 石河子市| 湘潭市| 巴林左旗| 屏东市| 建宁县| 璧山县| 武安市| 宁波市| 江津市| 江达县| 台中县| 东海县| 虹口区| 射阳县| 南通市| 工布江达县| 姜堰市| 迁安市|