nano Save and Exit: Save Files and Quit the Editor

By 

Updated on

4 min read

Saving and exiting a file in the Nano text 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

ActionShortcut
Open a filenano filename
Save changes (stay in editor)Ctrl+O, then Enter
Save and exitCtrl+X, then Y, then Enter
Exit without savingCtrl+X, then N
Save under a new nameCtrl+O, edit filename, then Enter
Cancel exit promptCtrl+X, then Ctrl+C
Show all commandsCtrl+G

For a printable quick reference, see the nano cheatsheet .

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 the Ctrl key. For example, ^X means press Ctrl and X at the same time.
  • The letter M represents the Alt key.

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. Newer nano versions also support optional modern bindings. If nano was started with modern bindings enabled, Ctrl+S saves and Ctrl+Q quits.

Opening a File

To open an existing file or create a new one, type nano followed by the file name:

Terminal
nano filename

A 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 will display the current filename at the bottom and prompt you to confirm.

  • Press Enter to save the file under the same name.
  • Or type a new name and press Enter to save it as a different file.
Nano filename prompt shown after pressing Ctrl+O to save a file
Warning
To save a file, you must have write permission to that file. If you are creating a new file , you need write permission to the directory where the file will be saved.

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?”

Nano save modified buffer prompt shown before exiting with unsaved changes
  • Y: Save changes. Nano will show the filename and prompt you to confirm. Press Enter to 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
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 displays [ Read Only ] in the status bar. You cannot save to a read-only file directly. Exit with Ctrl+X and reopen with sudo nano filename if you need to edit it.

Accidentally pressed Ctrl+X
If Nano shows the save prompt, press Ctrl+C to cancel and return to the editor without losing your changes.

Saving overwrites the wrong file
When Nano prompts for the filename, clear the current name and type a new one before pressing Enter to save as a different file.

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. When Nano shows the filename prompt, clear the current name, type the new filename, and press Enter.

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 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

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

View author page