Nano has no menus or close buttons. Every action goes through keyboard shortcuts, which trips up new users when they try to leave. This guide covers how to exit nano in every scenario — saving changes, discarding them, and recovering when something goes wrong.

Understanding Nano’s Keyboard Notation

At the bottom of the editor, two lines show available commands. Two prefix characters come up constantly:

^ means Ctrl. So ^X means press Ctrl and X at the same time.

M means Alt.

Press Ctrl+G at any point to open the full help screen. On newer nano versions with modern bindings enabled, Ctrl+S saves and Ctrl+Q quits — but the default shortcuts below work on every system.

Nano Exit and Save Shortcut Reference

ActionKey Combination
Save without closingCtrl+O, then Enter
Save and exit nanoCtrl+X, then Y, then Enter
Exit nano without savingCtrl+X, then N
Save with a new filenameCtrl+O, type new name, Enter
Cancel the exit promptCtrl+X, then Ctrl+C
View all commandsCtrl+G

How to Save and Exit Nano

The most common path out of the editor:

Press Ctrl+X. Nano asks: “Save modified buffer?” Press Y. Nano shows the current filename at the bottom — press Enter to confirm. The editor closes and returns to the terminal.

To save under a different name before exiting, clear the filename nano shows and type a new one before pressing Enter. If you need a refresher on how Linux organizes files across directories, the guide to moving directories with mv explains how paths and locations work.

How to Exit Nano Without Saving Changes

If you opened a file by mistake or want to throw away your edits:

Press Ctrl+X, then press N when nano asks about saving. The editor closes immediately and all modifications are gone. There’s no second confirmation — once you press N, those changes don’t come back.

How to Save in Nano Without Closing the Editor

Use Ctrl+O (the letter O, not zero) to save mid-session without exiting. Nano shows the filename as a prompt. Press Enter to write to the same file, or type a new name first to save a copy elsewhere.

The editor stays open after this. This is worth doing regularly during long editing sessions. If you’re writing a shell script in nano, the guide on running shell scripts in Linux covers what to do after you’ve saved the file.

How to Cancel the Exit Prompt in Nano

If you pressed Ctrl+X accidentally and don’t actually want to leave:

When nano shows “Save modified buffer?”, press Ctrl+C. This cancels the exit sequence and puts you back exactly where you were. Nothing is lost. This also works if you triggered the prompt on a file you don’t have write access to.

Fixing Common Nano Exit Errors

“Permission denied” when saving means you don’t have write access to the file or its parent directory. Exit with Ctrl+X then N, then reopen using sudo nano filename. The chmod executable guide explains how Linux file permissions work and how to check access rights before editing.

If nano shows [ Read Only ] in the status bar, it detected you lack write permission. You can read the file but not save edits. Exit and reopen with sudo nano filename to get write access.

When the wrong filename appears at the save prompt, clear what nano shows and type the correct name before pressing Enter. This prevents writing changes to the wrong file.

How to Open Files in Nano

Open any file with:

nano filename

If the file doesn’t exist, nano creates it when you first save. For configuration files on remote machines, you’ll need an active SSH connection first — the SSH login guide covers connecting to a remote server before editing files through the terminal.

To copy a file before editing it (a safe practice before modifying config files), the cp command guide covers the syntax for duplicating files in Linux.

FAQs

How do I exit nano without saving?

Press Ctrl+X, then press N when nano asks about saving. The editor closes immediately and all unsaved changes are discarded. No second confirmation appears.

What is the nano save and exit shortcut?

Press Ctrl+X to start the exit sequence. When prompted, press Y to save, then Enter to confirm the filename. The file writes and the editor closes.

How do I save in nano without exiting?

Press Ctrl+O, then Enter to write the file while keeping the editor open. Type a different name before pressing Enter to save a copy under a new filename.

What does “Save modified buffer” mean in nano?

It means nano detected unsaved changes and is asking whether to write them before closing. Press Y to save and exit, N to discard and exit, or Ctrl+C to cancel and keep editing.

Why can’t I save and exit nano on a read-only file?

Nano shows [ Read Only ] when you lack write permission. Exit with Ctrl+X then N, then reopen the file using sudo nano filename to gain write access.

Willie has over 15 years of experience in Linux system administration and DevOps. After managing infrastructure for startups and enterprises alike, he founded Command Linux to share the practical knowledge he wished he had when starting out. He oversees content strategy and contributes guides on server management, automation, and security.