Enter your email address below and subscribe to our newsletter

How to Save and Exit from Nano in Terminal

Learn how to save and exit from nano in terminal in 2 easy steps.

Share your love

So you just made a few changes to a file in the Nano editor but now you can’t figure out how you are supposed to save changes and exit from the Nano editor.

Worry not.

There are a few shortcuts that you can use to save changes and exit from the nano editor:

  • Press Ctrl + S to save the file without a prompt.
  • Press Ctrl + O and confirm the filename by pressing the Enter key to save changes.
  • Press Ctrl + X to exit the nano editor and will prompt to save changes if the recent changes are not saved.

Yep, it’s that simple.

Want more details, here you have it.

How to save changes in Nano (easy)

By far, the easiest way to save changes and continue editing the file is to press Ctrl + S which won’t prompt for any confirmation and save changes without any additional steps.

For example, here, I created a new file and saved changes by pressing Ctrl + S:

Save changes without exiting nano

As you can see, when I pressed Ctrl + S it wrote 2 lines to the file suggesting the changes have been saved.

Pretty easy, right?

How to save changes with a prompt?

While the previous method was the most efficient way to save changes in the nano editor, you might want to confirm the filename before writing changes.

In that case, you can refer to this method which will prompt you to confirm the filename before you save changes to the file.

To do so, first press the Ctrl + O shortcut and it will ask you to confirm the filename:

confirm filename before saving it in nano

To confirm the filename, press the Enter key and it will show you how many lines were written to the file. In my case, there were only two lines:

Save file in nano terminal

From here, you can either continue editing the file or exit the nano editor (showing how-to in a moment).

How to exit from Nano in Terminal?

Once you save changes from any of the two shown methods, you can exit from the nano editor, you can press Ctrl + X and it will close the nano editor and bring the terminal prompt.

But what if you forgot to save changes? Worry not, when you press the Ctrl + X and if the changes are not saved, it will ask whether you want to save changes before quitting the nano editor.

When you forget to save changes and press Ctrl + X, it will ask you whether you want to save the file or not. You can press Y if you want and in the next step, it will ask you to confirm the filename. There, you simply press the Enter key and that’s it:

Exit from nano in terminal

That’s it!

Learn Nano from Scratch

This was a quick tutorial on how you can save and exit from the nano editor but if you want to learn how to use the nano editor from zero to advanced, then we wrote a detailed guide on that topic:

If you have any other questions, leave us a comment and we will get back to you ASAP 🙂

Share your love
Kabir
Kabir

A tech journalist whose life revolves around networks.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!