How to Save and Exit in Nano Editor
New to Linux and Nano and don't know how to save or exit the editor? Here's what you need to know.
— Team LHB
You are editing files in the Linux terminal with Nano editor. You are new to both Linux and Nano.
You made some changes to the text file, things were going smoothly and now you have no idea how to save changes in Nano.
I have been in your situation. Here's what you need to do:
- Ctrl+o: To save the file and continue editing it
- Ctrl+x: To save the changes and exit editing
In both options, you'll have to confirm the changes. Still confused? Let me go in detail.
Save changes and continue editing
To open any text file with nano, you have to append the filename with the nano command.
For example, if I want to work with a file named
Program.c, then I'm supposed to use the given command:
When you make any changes to the existing file, nano will show the
* symbol with the filename:
Once you're done making desired changes, you'll have to use Crtl+o and it will ask whether you want to apply changes you made recently:
And you have to press the enter key to save the recently made changes to the file.
Save and exit from the Nano editor (or discord the changes)
Once you're done making changes, you just have to use
Ctrl + x and you'll be back to the terminal.
But what if you forgot to save the changes before leaving nano? well, it will ask whether you want to save the modified buffer or not. So you don't have to be afraid of accidental exits.
If you press
Y to save changes, it will show the filename again and you have to press the Enter key and it will close nano and drop you to the terminal.
You can also press
N to discard changes and exit or Ctrl+c to cancel exiting and continue editing.
This was a quick guide on how to save changes and close the nano text editor . To summarize again:
- Ctrl+o: Save and continue editing the file
- Ctrl+x: Save or discard changes and exit the file
Enjoy nano :)