nano Save and Exit: Save Files and Quit the Editor

When you edit a config file in nano, the most common point of confusion is leaving the editor without losing your changes. Nano uses keyboard shortcuts instead of menus, so saving and exiting depends on a few key combinations.
This guide shows how to save a file in nano, exit nano, save and quit in one flow, and discard changes when you do not want to keep them.
For a broader walkthrough of editing, navigation, and search, see how to use the Nano text editor .
Quick Reference
For a printable quick reference, see the nano cheatsheet .
| Action | Shortcut |
|---|---|
| Open a file | nano filename |
| Save changes (stay in editor) | Ctrl+O, then Enter |
| Save the current file directly | Ctrl+S |
| Save and exit | Ctrl+X, then Y, then Enter |
| Exit without saving | Ctrl+X, then N |
| Save under a new name | Ctrl+O, edit the filename, Enter, then Y if prompted |
| Cancel exit prompt | Ctrl+X, then Ctrl+C |
| Show all commands | Ctrl+G |
Nano’s Command Notation
At the bottom of the screen, Nano shows two helplines with commonly used commands. All commands in Nano are prefixed with either ^ or M characters.
- The caret symbol (
^) represents theCtrlkey. For example,^Xmeans pressCtrlandXat the same time. - The letter
Mrepresents theAltkey.
To see the complete list of commands, press Ctrl+G.
Most Linux systems use nano’s default shortcuts, where Ctrl+O writes the file and Ctrl+X exits. Since nano 2.9.0, the default set also binds Ctrl+S to saving the current file, so a plain save does not have to go through the write prompt at all.
Nano 8.0 added optional modern bindings. Start nano with nano -/ or nano --modernbindings to use them. In this mode, Ctrl+S saves, Ctrl+W opens the write prompt, Ctrl+O opens a file, Ctrl+Q quits, and Ctrl+X cuts the current line or selection.
Opening a File
To open an existing file or create a new one, type nano followed by the file name:
nano filenameA new editor window will open and you can start editing the file.
Saving Changes in Nano
When you finish making changes, press Ctrl+O (the letter O, not zero) to save your work.
Nano shows a filename prompt at the bottom. If the buffer already has a name, nano fills it in for you.
- To save under the current name, press
Enter. - To save under a different name, replace the current name and press
Enter. PressYif nano asksSave file under DIFFERENT NAME?. - To save an unnamed buffer, type a filename and press
Enter.
If you choose a different file that already exists, nano asks a question such as File "notes.txt" exists; OVERWRITE?. Press Y only if you want to replace that file. Press N at either confirmation to go back to the filename prompt.

The wording of that prompt depends on the nano version. Nano 8.3 and older label it File Name to Write:, as in the screenshot above, while nano 8.4 and newer label it Write to File:. The keys behave the same way in both.
The help lines under the prompt list the options you can apply before the file is written: M-D switches to DOS line endings, M-A appends the buffer to the target file, M-P prepends it, M-B keeps a backup copy of the previous contents, and ^T opens a file browser. Nano 9.0 and older also show M-M for old Mac line endings, but nano 9.1 removed that format.
On nano 8.5 and newer, the write prompt shows ^Q Discard buffer by default. Ctrl+Q closes the buffer and discards unsaved changes. Press Ctrl+C to cancel the write and keep editing.
Saving with Ctrl+S
When the file already has a name, Ctrl+S usually saves it directly and reports the result on the status bar.
[ Wrote 24 lines ]Nano has bound Ctrl+S to this direct save since version 2.9.0. If the buffer has no filename, Ctrl+S opens the write prompt. If nano detects that the file changed on disk, it asks whether to continue saving.
Exiting Nano
When you are done and want to exit Nano, press Ctrl+X.
If you have not modified the file, Nano will exit immediately and return you to the terminal.
If there are unsaved changes, Nano will ask: “Save modified buffer?”

Y: Save changes. Nano will show the filename and prompt you to confirm. PressEnterto save and exit.N: Discard changes and return to the terminal.Ctrl+C: Cancel the exit prompt and stay in the editor.
Troubleshooting
“Permission denied” when saving
Nano reports the failure on the status bar, for example Error writing /etc/hosts: Permission denied. You do not have write permission to the file or its directory. Use ls -l to check permissions. If you need root access, reopen the file with sudo nano filename.
File opened as read-only
Nano shows File '/etc/hosts' is unwritable on the status bar as soon as the buffer loads. You can still type in it, but the write will fail, so exit with Ctrl+X and reopen the file with sudo nano filename. View mode is a separate case: a file opened with nano -v shows View in the title bar, and nano refuses the edits themselves.
Accidentally pressed Ctrl+X
If Nano shows the save prompt, press Ctrl+C to cancel and return to the editor without losing your changes.
“File was modified since you opened it”
Another program or user changed the file on disk after you opened it. Nano shows [ File on disk has changed ] and asks File was modified since you opened it; continue saving?. Press Y only if you want your version to replace the one on disk.
With the default settings, N returns you to the editor if you started the save with Ctrl+O or Ctrl+S. If you started with Ctrl+X and chose to save, N closes the buffer and discards your unsaved edits. To keep editing in that case, press Ctrl+C at the warning and again at the filename prompt.
Ctrl+S freezes the terminal
That happens outside nano, where Ctrl+S is the XOFF character that pauses terminal output. Press Ctrl+Q to resume. Inside the editor the key saves the file, unless nano was started with --preserve, which hands Ctrl+S and Ctrl+Q back to the terminal.
Ctrl+X cuts a line instead of exiting
Nano is running with modern bindings, started with nano -/ or nano --modernbindings. Press Ctrl+Q to quit, or restart the editor without that option.
FAQ
What is the difference between Ctrl+O and Ctrl+X in Nano?Ctrl+O saves the file and keeps the editor open so you can continue editing. Ctrl+X exits the editor, prompting you to save if there are unsaved changes.
How do I save a file in Nano without exiting?
Press Ctrl+O, then press Enter to confirm the filename. Nano saves the file and you remain in the editor.
How do I exit Nano without saving changes?
Press Ctrl+X, then press N at the “Save modified buffer?” prompt. Nano discards all unsaved changes and returns you to the terminal.
How do I save a file under a different name in Nano?
Press Ctrl+O, replace the current filename, and press Enter. Press Y if nano asks you to confirm the new name.
What does “Save modified buffer?” mean in Nano?
It means Nano has detected unsaved changes. Press Y to save, N to discard changes and exit, or Ctrl+C to cancel and return to editing.
Conclusion
In default nano keybindings, use Ctrl+O or Ctrl+S to save without closing and Ctrl+X to leave the editor. If nano asks whether to save the modified buffer, choose Y to keep the changes or N to discard them.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page