Quick Answer — Save and Exit Nano in 2 Steps
If you're here for the short version, here it is:
- Save: Press
Ctrl+O, confirm or edit the filename, then pressEnter. - Exit: Press
Ctrl+X. If there are unsaved changes, nano asks you to save — pressYto save,Nto discard, orCtrl+Cto cancel.
That's it. Two keystrokes (plus a confirmation) and you're out. But if you've run into permission errors, need to save to a different filename, or you're on macOS and the shortcuts feel weird — keep reading. There's more to nano than just ^O and ^X.

What Do ^O and ^X Mean in Nano?
Before we get into the steps, a quick note that trips up a lot of beginners. The ^ symbol in nano's bottom toolbar is caret notation — it means "Ctrl." So ^O = Ctrl+O, and ^X = Ctrl+X. You don't press the caret key. You hold down Ctrl and tap the letter.
I've literally watched people type Shift+6 followed by O and wonder why nothing happened. Totally understandable — the notation is a relic from old Unix conventions. Now you know.
Save a File in Nano (Ctrl+O) — Step by Step
When you've made your edits and want to write them to disk without closing nano, Ctrl+O is your command. Here's exactly what happens:
- Press
Ctrl+O(that's the letter O, not zero). - Nano shows a prompt at the bottom:
File Name to Write: yourfilename.txt - If the filename looks correct, just press
Enter. - Nano confirms with something like
[ Wrote 42 lines ].
Your file is saved. You're still inside nano, so you can keep editing.

Example: Save as a New File (Save As)
Want to save your work to a different filename? Easy. When nano shows the File Name to Write: prompt after you press Ctrl+O, just backspace over the existing name and type a new one:
File Name to Write: newconfig_backup.txtPress Enter, and nano creates the new file (assuming you have write permission in that directory). The original file stays untouched. This is nano's version of "Save As" — there's no separate menu option for it.
One thing to watch: if the directory doesn't exist, nano will throw an error. Make sure the path is valid before hitting Enter.
Notes on Filenames, Extensions, and Confirming
Nano doesn't enforce file extensions. You can save as .conf, .txt, .yaml, or no extension at all. It doesn't care. But you should care — proper extensions help other tools (and future-you) understand what's inside.
If you opened nano without specifying a filename (nano with no arguments), the prompt will be blank. Just type your desired filename and path, then hit Enter. The file gets created right there.
Exit Nano (Ctrl+X) — Step by Step
Ready to leave? Press Ctrl+X. What happens next depends on whether you have unsaved changes.
If there are no unsaved changes: Nano exits immediately. No questions asked.
If you have unsaved changes: Nano shows this prompt:
Save modified buffer?
Y Yes
N No ^C Cancel- Press
Y— nano asks for the filename (just like Ctrl+O), then saves and exits. - Press
N— nano exits without saving. Your changes are gone. - Press
Ctrl+C— cancels the exit and returns you to editing.

If you're working on important config files — say, an Nginx or Apache configuration on a Linux VPS — I'd recommend always saving with Ctrl+O first, then exiting with Ctrl+X. That way you explicitly control the save step instead of relying on the exit prompt. Small habit, big payoff when you're editing live server configs at 2 AM.
How to Exit Nano Without Saving (Discard Changes)
Sometimes you open a file, make a mess of it, and just want to bail. No judgment.
Press Ctrl+X, then press N when prompted. That's it — nano closes and your edits vanish as if they never happened.
If you haven't made any changes at all, Ctrl+X exits instantly without even asking. And if you accidentally hit Ctrl+X but don't want to leave? Ctrl+C cancels the exit prompt and drops you back in the editor.
Save When You Don't Have Write Permission
This is where things get real. You open /etc/nginx/nginx.conf with nano /etc/nginx/nginx.conf, spend ten minutes editing, press Ctrl+O, and nano slaps you with:
[ Error writing /etc/nginx/nginx.conf: Permission denied ]Painful. But not fatal. You've got options.
Option 1: Reopen with sudo
The cleanest approach. If you haven't made changes yet (or don't mind re-doing them), close nano and reopen with elevated privileges:
sudo nano /etc/nginx/nginx.confNow you'll have write access. For sensitive system files, this is the method I use 90% of the time.
Option 2: Save to a Temp File, Then Move It
Already deep into your edits and don't want to lose them? Save to a temp location, then move it with sudo:
# Inside nano, press Ctrl+O and change the filename to:
/tmp/nginx.conf.tmp
# Press Enter to save, then Ctrl+X to exit
# Now move it into place:
sudo mv /tmp/nginx.conf.tmp /etc/nginx/nginx.confQuick, effective, and keeps your changes intact.
Option 3: Use sudoedit (Safest Method)
sudoedit is the security-conscious approach. It copies the file to a temp location, opens it in your editor, and copies it back with proper permissions when you save and exit:
sudoedit /etc/nginx/nginx.confThis respects your $EDITOR environment variable. Set it to nano if it isn't already:
export EDITOR=nanoI personally prefer sudoedit over sudo nano for production servers. It avoids running the entire editor as root, which is a subtle but meaningful security improvement.
For more terminal editing fundamentals, check out our guide on how to get started with Nano Text Editor.
Create Backups and Avoid Overwriting
Nano has a built-in backup feature that most people don't know about. If you pass the -B flag (or --backup), nano creates a backup of the original file before overwriting it:
nano -B /etc/hostsThe backup file gets a tilde appended: /etc/hosts~. Want this behavior every time? Add it to your .nanorc:
set backup
set backupdir "~/.nano-backups"Create that backup directory first (mkdir -p ~/.nano-backups), and nano will stash backups there instead of cluttering your working directory.
Nano Command-Line Flags That Affect Saving
Here are the flags you'll actually use in day-to-day work:
| Flag | What It Does |
|---|---|
-B / --backup |
Creates a backup file (filename~) before saving |
-C <dir> |
Sets the directory for backup files |
-w / --nowrap |
Disables automatic line wrapping (critical for config files) |
-c |
Shows cursor position constantly (handy for large files) |
-R / --restricted |
Restricted mode — prevents saving to different filenames |
GNU nano 7.x introduced some refinements to how backups and undo history work. If you're on an older version (check with nano --version), some of these flags might behave slightly differently. Most Linux distros shipping in 2024–2025 include GNU nano 7.2 or newer.
Save and Exit on macOS, WSL, and Windows
Good news: the keyboard shortcuts are the same across platforms. Ctrl+O saves, Ctrl+X exits. But there are a couple of gotchas.
macOS (Terminal.app / iTerm2): The Ctrl key works normally. Don't confuse it with the Cmd (⌘) key — Cmd+O does something completely different in Terminal. Also, macOS ships with an older version of nano by default. If you want the latest features, install via Homebrew: brew install nano.
WSL (Windows Subsystem for Linux): Same key combos, no surprises. However, if you're using Windows Terminal with certain key binding configurations, Ctrl+O might be intercepted. Check your Windows Terminal settings if shortcuts seem unresponsive.
SSH from PuTTY or other Windows terminals: Generally fine, but some terminals remap Ctrl combinations. If Ctrl+O doesn't work, try the F3 key (nano maps function keys to common actions too).
Troubleshooting Common Save Errors
Permission Denied
Already covered above — reopen with sudo, save to /tmp and move, or use sudoedit. If none of these work, check whether the filesystem is mounted read-only:
mount | grep "on / "
# Look for "ro" in the optionsA read-only filesystem needs to be remounted: sudo mount -o remount,rw /. But tread carefully — there's usually a reason it was read-only.
Terminal Not Recognizing Ctrl Combos (screen/tmux)
Running nano inside screen? The default screen escape key is Ctrl+A, which conflicts with nano's "Go to beginning of line" shortcut. But Ctrl+O and Ctrl+X should still work fine.
Inside tmux, the default prefix is Ctrl+B — no conflict with nano's save/exit commands. If you've rebound your tmux prefix to Ctrl+O (some people do), then yeah, that'll intercept the save command. Either change your tmux prefix or use F3 as an alternative save key in nano.
Encoding and Newline Differences
If you're editing a file created on Windows, you might see ^M characters (carriage returns). Nano handles this, but you can convert line endings explicitly with dos2unix before or after editing. Also, if your file has unusual encoding (UTF-16, for example), nano may save it as UTF-8 by default. Use iconv to convert if needed.
Nano Keyboard Shortcuts: Essential Cheatsheet
Here's a reference table covering the most-used commands. The ^ symbol means Ctrl, and M- means Alt (or Esc then the key).
| Shortcut | Action |
|---|---|
^G |
Display help |
^O |
Save file (WriteOut) |
^X |
Exit nano |
^K |
Cut current line |
^U |
Paste (uncut) line |
^W |
Search for text |
^\ |
Search and replace |
^C |
Show cursor position (line/column) |
^Y |
Scroll up one page |
^V |
Scroll down one page |
^_ |
Go to specific line number |
M-U |
Undo last action |
M-E |
Redo last undone action |
Want to learn more about cut, copy, and paste operations? We've got a dedicated guide on how to paste in Nano Editor. And for undo/redo specifics, check out how to undo in Nano Editor.

Recovery: What to Do If Nano Crashed or You Lost Unsaved Changes
It happens. SSH connection drops, terminal crashes, power goes out. So where do your unsaved edits go?
If nano was in the middle of saving when it died, it might have left behind a swap or emergency file. Look for files with a tilde suffix in the same directory:
ls -la /path/to/directory/ | grep "~"If you had backups enabled (-B flag or set backup in .nanorc), you'll find a filename~ backup of the last saved version.
For truly unsaved work (you never pressed Ctrl+O at all), there's unfortunately no recovery mechanism built into nano. Unlike Vim's .swp files that preserve unsaved buffers, nano doesn't maintain a persistent swap file by default. This is honestly one area where Vim's approach with swap files has an advantage.
The lesson? Save early, save often. Especially on remote servers where connections can be unpredictable. A quick Ctrl+O every few minutes costs nothing and can save you from starting over.
References and Further Reading
For the complete documentation straight from the source:
- GNU nano official manual — the full reference for every command, flag, and configuration option.
man nano— run this on any Linux system for the local manual page.nano --help— quick reminder of command-line flags.
If you're evaluating whether nano is the right editor for your workflow, our comparison of the best text editors might help you decide.