Save and Exit Nano - Command Line

by|inArticles||3 min read
Save and Exit Nano<br>
Save and Exit Nano<br>

Nano, when compared to other popular Command Line Editors like Vim or Emacs, is a slim editor which can be used with Syntax highlighting as well. Still, for many beginners it is not very obvious how to work with the editor, as you can not use your mouse to point and click. Let's explore the editor and the commands to save and exit Nano together.

Launching Nano

Alright, first things first. We can launch nano by just typing `nano` in the console. This would open an editor which is not related to any file. To open a (text)file - some code or notes - we can call nano with the corresponding filepath of the file:

nano
nano /home/ersocon/script.php

As soon as the editor is opened, you can start writing right away. This is different to an editor like vim, where you need to launch a command to be able to enter some characters.

Fresh Nano Editor<br>
Fresh Nano Editor<br>

Let's add some content:

Nano with PHP Syntax Highlighting<br>
Nano with PHP Syntax Highlighting<br>

In the top right corner Nano will tell you that the current state of the content is "Modified", hence unsaved. Furthermore, for well known languages Nano will highlight the code.

Saving Content to a File

So far we have managed to open a file and add some content, great! But how can we save this content to the opened file? This is usually achieved by the Command "CTRL+O".

Save Confirmation in Nano<br>
Save Confirmation in Nano<br>

By triggering this command Nano will ask you to which file name you would like to save the content. In our case, we opened a file, so Nano will suggest the same filename. By confirming with Enter, Nano will overwrite the opened file contents with the content we modified. Furthermore we will see the number of lines that has been written to the file in the bottom information field of Nano.

Amount of written lines in Nano<br>
Amount of written lines in Nano<br>

Closing Nano

Finally, to finish our work on a file, we need to close Nano. This can be achieved by the command "CTRL+x", which stands for Exit. When the file is saved, Nano will close. But, when Nano is in the "modified" mode, as we have seen before, it will ask you if you would like to save the content.

Save Confirmation on Nano Exit<br>
Save Confirmation on Nano Exit<br>

By confirming with "Y" Nano will execute the save operation as we have seen before. With this knowledge, we can save us a bit of work. We don't need to trigger the save command explicitly. We could have as well just open the file, modify the content and hit the exit command. In the end, the result is the same.

Thank you for reading this far! Let’s connect. You can @ me on Twitter (@debilofant) with comments, or feel free to follow. Please like/share this article so that it reaches others as well.

Related Articles

© Copyright 2023 - ersocon.net - All rights reservedVer. 388