How to Save and Exit out of Nano

In this quick guide, we will be showing you how to save and exit out of the Nano text editor.

Nano save and exit

The Nano text editor is one of our personal favorites for quickly editing files within the terminal. It is fairly simple, making it great for people who are new to the command line.

Of course, like all terminal-based text editors, you will need to learn some keyboard shortcuts to utilize it. You don’t have any UI to click, so everything is handled purely through your keyboard. While daunting at first, you will find yourself being more productive as your hands never have to leave the keyboard.

There is one keyboard shortcut in particular that you will want to learn first. That keyboard shortcut is to save and exit out of the Nano text editor. There is little point in using a text editor if you can’t save what you are writing.

This guide will cover two separate topics. The first section will show you how to save and exit Nano, and the second will cover how to save file changes without needing to quit.

Saving and Exiting out of a File in Nano

In this section, we will quickly cover how to save and exit a file in the Nano text editor. This whole process is relatively easy, as Nano will automatically prompt you to save any changes that you have made when you close the editor.

If you simply want to save the changes you have made to a file without any explanation, then all you need to know is to press CTRL + X, Y, and then ENTER.

However, if you want a more detailed explanation with specific steps, be sure to read over our next few steps.

1. To begin the saving and exiting a file in the Nano text editor, press CTRL + X. This tells Nano you want to exit.

If changes have been made to the file you are editing that has yet to be saved, you will be asked a couple of additional questions. Alternatively, if no changes have been made, Nano will exit gracefully.

The asterisk (*) symbol that appears alongside the filename allows you to quickly check if changes have been made during your current session. No symbol means no changes have been made or you have already saved your changes.

File opened in nano with changes

2. When you go to exit a file in Nano, you will be automatically prompted if you want to save any changes that you have made with the message “Save modified buffer?“.

If you want to have Nano save the new content before quitting, press the “Y” key.

Alternatively, if you simply want to exit Nano without saving any of your changes, press “N“.

Save and Exit Prompt in Nano

3. After you say yes to saving your changes, Nano will ask you for the name of the file you want to write these changes to before quitting.

You can keep the same name of the file that you are editing to overwrite its contents. Alternatively, you can type out a new name, which Nano will prompt you again, notifying you that you are trying to save the changes under a different name.

Once you have made a decision, press the ENTER key to confirm that you are saving the contents to the specified filename.

Filename for Nano to Write Changes To

Saving a File in Nano

Of course, when editing a file in Nano, you might not necessarily want to exit every time you make a slight change.

Luckily, Nano has another simple keyboard shortcut that you can press to save your changes. This is especially useful when you are coding or making a large number of changes to a file.

To save the contents of the current file in Nano, all you need to remember is to press CTRL + O followed by the ENTER key.

1. To begin saving a file in Nano, you will want to press CTRL + O on your keyboard.

File opened in nano with changes

2. Whenever you save changes to a file in Nano, you will be prompted to provide the file name to which to write the text. If you are editing an existing file and don’t want to save the changes to a new file, you can simply press ENTER.

However, if you want to save these changes to a brand-new file, type it in now.

Save changes in Nano without Exiting

3. If you decide to write your changes to a new file, you will be greeted with a message asking if you want to “Save file under DIFFERENT NAME?“.

To proceed with saving your text changes, press Y. Alternatively, to abort saving these changes, press the “N” key.

Save under separate name prompt

Conclusion

Now, you should know the super simple keyboard shortcuts you can use to save and exit a file in the Nano text editor.

One of Nano’s key features is that it is a pretty simple terminal-based text editor, which is great for those who are just getting started with the terminal.

Please comment below if you have any issues with saving and exiting files within this text editor.

If you liked this quick tutorial, we highly recommend exploring our many other Linux guides. We also have a more in-depth guide covering many other ways you can use Nano.

Leave a Reply

Your email address will not be published. Required fields are marked *