Nano is the simple terminal text editor that comes with most Linux distributions, macOS, and Termux. Once you open a file with nano filename, the most common question is how to save your changes and leave the editor.

Here is the exact sequence that works on every modern version of GNU nano:

  1. Press Ctrl + O (the letter O, not zero) to “Write Out” (save).
  2. Press Enter to confirm the filename.
  3. Press Ctrl + X to exit.

That’s it. The rest of this guide explains what you see on screen, how to save under a new name, how to quit without saving, and the small differences on Mac, Ubuntu, and Termux.

The Basic Save-and-Exit Steps (Detailed)

  1. Make your edits in the file.
  2. Hold the Ctrl key and press O. The bottom of the screen changes to:

File Name to Write: yourfile.txt

  1. Press Enter to accept the current name (or type a new name if you want to “Save As”).
  2. Nano writes the file and shows a short confirmation such as “Wrote X lines”.
  3. Hold Ctrl and press X. Nano closes and returns you to the shell.

You can also exit first with Ctrl + X. If the file has unsaved changes, nano asks:

Save modified buffer?
Y Yes
N No
^C Cancel
  • Press Y, then Enter (and confirm the name if asked).
  • Press N to discard changes and exit immediately.
  • Press Ctrl + C to cancel and stay in the editor.

Keyboard Shortcuts at a Glance

Action Keys What happens
Save (Write Out) Ctrl + O Prompts for filename
Confirm filename Enter Writes the file
Exit Ctrl + X Quits (asks to save if needed)
Cancel current prompt Ctrl + C Aborts the current question
Exit without saving Ctrl + X → N Discards changes
Help Ctrl + G Opens the built-in help screen

Save As a Different Filename

  1. Press Ctrl + O.
  2. Use the arrow keys or Backspace to edit the filename that appears.
  3. Type the new name and press Enter.
  4. Press Ctrl + X to leave.

How to Exit Nano Without Saving

  1. Press Ctrl + X.
  2. When you see “Save modified buffer?”, press N. Nano closes, and any unsaved changes are lost.

Platform Notes

Linux / Ubuntu / Debian

The steps above work exactly as described. If you opened the file with sudo nano, you will be able to overwrite system files; otherwise you may see “Permission denied” or “File is unwritable”.

macOS

macOS ships with a slightly older nano, but the same Ctrl+O / Enter / Ctrl+X sequence works. On some Mac keyboards, the Control key is clearly labeled; if you are using an external keyboard, make sure you are pressing the Control key (not Command).

Termux (Android)

Nano behaves the same way. On many Android keyboards, you may need to long-press the Ctrl key or use the volume-down + letter combination that Termux provides for Control. Once you can generate Ctrl+O and Ctrl+X, the rest is identical.

Troubleshooting Common Problems

“File is unwritable” or “Permission denied”

You do not have write permission. Re-open the file with sudo nano filename (or change the file’s ownership/permissions outside nano).

Ctrl + X does nothing

Make sure you are pressing Control (not Alt or Command). In Termux, verify the Control key is active.

Stuck on the “Save modified buffer?” prompt

Press Y, N, or Ctrl+C. There is no other way out of that prompt.

I want to keep editing after saving

Just press Ctrl + O and Enter. You stay inside the editor; only Ctrl+X closes it.

Quick Reference for Related Tasks
  • Go to the end of the file: Alt + / or Ctrl + W, then Ctrl + V (or use the mouse if mouse support is enabled).
  • Delete the current line: Ctrl + K
  • Undo: Alt + U (or Ctrl + _ then U on some versions).

These are the commands people search for most often alongside “nano save and exit”.

Summary

To save and exit nano:

Ctrl + O  →  Enter  →  Ctrl + X

To quit without saving:

Ctrl + X  →  N

This works on Linux, Ubuntu, macOS, and Termux with every recent version of GNU nano. Bookmark this page or keep the shortcuts table handy the next time you are editing a config file in the terminal.

Frequently Asked Questions

  1. How do I save a Nano file?
    Press Ctrl + O (Write Out), then press Enter to confirm the filename. Nano will save the file and stay open so you can continue editing. To save and leave the editor in one go, use Ctrl + O → Enter → Ctrl + X.
  2. How do I exit Nano without saving?
    Press Ctrl + X. When Nano asks “Save modified buffer?”, press N. Your changes will be discarded, and you will return to the terminal.
  3. What is Ctrl + O?
    Ctrl + O is the “Write Out” command. It saves the current file. After pressing it, Nano shows the filename at the bottom of the screen — press Enter to confirm, or type a new name if you want to save the file under a different name.
  4. What is Ctrl + X?
    Ctrl + X is the Exit command. It closes Nano and returns you to the command line. If you have unsaved changes, Nano will ask whether you want to save them first (Y = Yes, N = No, Ctrl + C = Cancel).
  5. How do I undo changes in Nano?
    Press Alt + U (or on some systems Esc then U). You can press it multiple times to undo several recent edits. Note that the undo history is limited and is cleared when you save and exit.

Looking for a powerful Linux server? Deploy your applications on bodHOST’s secure Linux VPS Hosting with full root access and reliable performance.

Popular Posts You May Read

Explore more hosting insights, tips and industry updates.

eNlight Cloud Service Details

  What happens if my resource usage begins to exceed the original specifications of my…

creating drop down menus in joomla 1.5

This tutorial will guide you through the process of creating a horizontal drop-down menus in…

About SMF – Unveiling SMF: Forum Platform Insights

What is SMF?SMF stands for Simple Machines Forum. SMF is an open-source software package, which…