← Back to Knowledge Base
Tutorials · September 10, 2026 · 11 min read

How to Save and Exit in Nano Editor Linux

Nano is one of the easiest text editors to use from the Linux command line. It is commonly used to edit configuration files, scripts, text files, and other files directly from the terminal.

However, many beginners face one common question after editing a file:

How do I save and exit Nano in Linux?

Unlike graphical text editors, Nano does not have a visible Save or Close button. Instead, you use keyboard shortcuts to save your changes, exit the editor, or discard changes you do not want to keep.

This guide explains how to save and exit Nano, save changes without closing the editor, exit without saving, save a file with a different name, and troubleshoot common issues.

Quick Answer: How to Save and Exit Nano

To save your changes and exit Nano:

  1. Press Ctrl + O to save the file.
  2. Press Enter to confirm the file name.
  3. Press Ctrl + X to exit Nano.

You can also press:

Ctrl + X → Y → Enter

This exits Nano and saves your changes when Nano asks whether you want to save the modified file.

What Is Nano Editor in Linux?

Nano is a command-line text editor used on Linux and other Unix-like operating systems. It is popular because it is simple and beginner-friendly.

You can use Nano to:

  • Edit configuration files
  • Create text files
  • Modify scripts
  • Update server settings
  • Edit website and application files
  • Make quick changes through SSH
  • Manage files directly from the Linux terminal

Nano displays useful keyboard shortcuts at the bottom of the editor screen, making it easier to learn than many other command-line editors.

For example, when Nano displays ^O, the ^ symbol means the Ctrl key. Therefore:

  • ^O means Ctrl + O
  • ^X means Ctrl + X
  • ^G means Ctrl + G

The official GNU Nano shortcut reference lists Ctrl + O for writing out a file, Ctrl + X for exiting, and Ctrl + S for saving the current file in supported versions.

How to Open a File in Nano

Before saving or exiting, you first need to open a file in Nano.

Use the following command:

nano filename.txt

For example:

nano testfile.txt

If the file already exists, Nano opens it for editing.

If the file does not exist, Nano creates a new file when you save it.

You can also open system configuration files. For example:

sudo nano /etc/hosts

The sudo command may be required when editing files that need administrator permissions.

How to Save a File in Nano

After making changes to a file, you can save it without exiting Nano.

Step 1: Press Ctrl + O

Press:

Ctrl + O

The letter is O, not the number zero.

In Nano, this command is commonly called Write Out, which means writing the current file contents to disk.

After pressing the shortcut, Nano displays a file name prompt near the bottom of the screen.

You may see something similar to:

File Name to Write: filename.txt

Step 2: Confirm the File Name

If you want to save the file using the existing file name, simply press:

Enter

Nano saves the file and returns you to the editor.

Your changes are now saved, but Nano remains open so you can continue editing.

Save Shortcut in Nano

On current versions of GNU Nano, you may also be able to use:

Ctrl + S

to save the current file directly. The official Nano shortcut documentation lists Ctrl + S as the command to save the current file.

For beginners, however, Ctrl + O followed by Enter remains a familiar and widely used method for saving files.

How to Save and Exit Nano Editor

If you have finished editing the file and want to save your changes and close Nano, follow these steps.

Method 1: Save First, Then Exit

This is the simplest method.

Step 1: Save the File

Press:

Ctrl + O

Then press:

Enter

This saves the file.

Step 2: Exit Nano

After saving, press:

Ctrl + X

Nano will close and return you to the Linux terminal.

Shortcut Summary

Ctrl + O
Enter
Ctrl + X

This method is useful when you want to make sure your changes are saved before leaving the editor.

How to Exit Nano and Save Changes

Another simple method is to exit first and let Nano ask whether you want to save your changes.

Press:

Ctrl + X

If the file contains unsaved changes, Nano displays a message asking whether you want to save the modified buffer.

Press:

Y

for Yes.

Nano may then ask you to confirm the file name.

Press:

Enter

to save using the current file name.

The complete process is:

Ctrl + X
Y
Enter

Nano will save the changes and exit the editor.

How to Exit Nano Without Saving Changes

Sometimes you may want to close Nano without saving the changes you made.

To do this:

  1. Press Ctrl + X
  2. When Nano asks whether you want to save the modified buffer, press N

The shortcut sequence is:

Ctrl + X
N

Nano will discard your unsaved changes and return you to the terminal.

Be careful when choosing this option because changes that have not been saved will be lost.

How to Cancel the Exit Process in Nano

If you accidentally press Ctrl + X, Nano may ask whether you want to save your changes.

You can cancel the exit process and return to the editor.

Press:

Ctrl + C

This cancels the current prompt and allows you to continue editing the file.

This is useful if you accidentally try to exit Nano before finishing your work.

How to Save a File With a Different Name in Nano

Nano also allows you to save a file using a different name.

Follow these steps:

  1. Press Ctrl + O
  2. Nano displays the current file name.
  3. Remove or edit the existing file name.
  4. Enter the new file name.
  5. Press Enter

For example, if you opened:

testfile.txt

you can save a copy as:

backup.txt

This is useful when you want to create a backup or save your edited file as a new version.

Understanding Common Nano Shortcuts

Here are some of the most useful Nano keyboard shortcuts.

ActionShortcut
Save current fileCtrl + S
Save or Write Out fileCtrl + O
Confirm file nameEnter
Exit NanoCtrl + X
Save and exitCtrl + X, then Y, then Enter
Exit without savingCtrl + X, then N
Cancel a promptCtrl + C
Open Nano helpCtrl + G

Nano displays many of these shortcuts at the bottom of the editor screen. You can also press Ctrl + G to open the built-in help documentation.

Example: Save and Exit a File in Nano

Let’s look at a simple example.

Suppose you open a file using:

nano example.txt

You make some changes to the file.

Now you want to save your work and exit.

Option 1: Save First

Press:

Ctrl + O

Then press:

Enter

After the file is saved, press:

Ctrl + X

You will return to the terminal.

Option 2: Exit and Save When Prompted

Press:

Ctrl + X

Nano asks whether you want to save the changes.

Press:

Y

Then confirm the file name by pressing:

Enter

The file will be saved and Nano will close.

What Does “Save Modified Buffer?” Mean in Nano?

When you edit a file, Nano stores your changes in memory until you save them.

This working copy is often referred to as a buffer.

When you try to exit without saving, Nano may display a message similar to:

Save modified buffer?

Nano is asking whether you want to keep the changes you made.

You usually have three options:

Press Y

Press Y if you want to save your changes.

Press N

Press N if you want to discard your changes and exit.

Press Ctrl + C

Press Ctrl + C if you want to cancel the exit process and return to the editor.

This confirmation helps prevent accidental data loss.

Why Is Ctrl + O Used to Save in Nano?

In many graphical applications, users are familiar with pressing Ctrl + S to save a file.

Nano also supports Ctrl + S in current versions, but Ctrl + O has traditionally been one of Nano’s main save commands.

The O shortcut refers to Write Out, which means writing the file contents to storage.

When you press Ctrl + O, Nano asks you to confirm the file name before saving.

This is also useful when you want to save the file under a different name.

How to Exit Nano When There Are No Changes

If you open a file in Nano but do not make any changes, you can simply press:

Ctrl + X

Nano will close and return you to the terminal.

You usually will not receive a save confirmation because there are no unsaved changes.

What Happens If You Exit Nano Without Saving?

If you press:

Ctrl + X

after making changes, Nano checks whether the file has been modified.

If there are unsaved changes, Nano asks whether you want to save them.

If you choose:

N

Nano exits without saving.

Any changes made since the last save will be discarded.

For this reason, it is always a good idea to confirm that important changes have been saved before exiting.

Common Problems When Saving Files in Nano

Permission Denied Error

Sometimes Nano may show a permission error when you try to save a file.

This usually happens when your current user does not have permission to modify the file.

For example, many system files require administrator privileges.

You may need to open the file using sudo:

sudo nano filename

For example:

sudo nano /etc/hosts

Be careful when editing system files because incorrect changes can affect your Linux system or server.

Unable to Save a File

If Nano cannot save a file, check the following:

  • Do you have permission to modify the file?
  • Do you have permission to write to the directory?
  • Is the file system full?
  • Is the file system mounted as read-only?
  • Are you editing a protected system file?

If necessary, check the file permissions or open the file with the appropriate administrative privileges.

Accidentally Exited Nano

If you exit Nano and choose not to save your changes, those unsaved changes may be lost.

To avoid this, always choose:

Y

when Nano asks whether you want to save the modified file.

Pressed the Wrong Shortcut

Nano provides a built-in help screen.

Press:

Ctrl + G

to view available commands and keyboard shortcuts.

This can be useful when you are new to Nano or forget a command.

Nano Save and Exit Shortcuts for Beginners

If you only remember three things, remember these:

Save a File

Ctrl + O → Enter

Save and Exit

Ctrl + X → Y → Enter

Exit Without Saving

Ctrl + X → N

These shortcuts cover the most common tasks when using Nano in Linux.

Frequently Asked Questions

How do I save a file in Nano?

Press Ctrl + O and then press Enter to confirm the file name and save the file.

On current versions of Nano, Ctrl + S can also save the current file.

How do I save and exit Nano in Linux?

You can save the file with Ctrl + O, press Enter, and then press Ctrl + X to exit.

Alternatively, press Ctrl + X, then Y, and finally Enter to save and exit.

How do I exit Nano without saving?

Press Ctrl + X and then press N when Nano asks whether you want to save the modified file.

What does Ctrl + O do in Nano?

Ctrl + O opens the Write Out or save process. You can confirm the current file name or enter a different name before pressing Enter to save.

What does Ctrl + X do in Nano?

Ctrl + X closes the current Nano buffer and exits the editor. If you have unsaved changes, Nano asks whether you want to save them.

How do I save without exiting Nano?

Press:

Ctrl + O

Then press:

Enter

The file will be saved, and you can continue editing.

How do I save a Nano file under a new name?

Press Ctrl + O, change the file name shown in the prompt, and press Enter.

What does ^X mean in Nano?

The ^ symbol means the Ctrl key.

Therefore:

^X = Ctrl + X

Similarly:

^O = Ctrl + O
^G = Ctrl + G

How do I get help in Nano?

Press:

Ctrl + G

Nano opens its built-in help screen, where you can view available commands and shortcuts.

Final Thoughts

Saving and exiting Nano is simple once you understand its keyboard shortcuts.

The easiest method is:

Ctrl + O → Enter → Ctrl + X

This saves your changes first and then closes the editor.

You can also use:

Ctrl + X → Y → Enter

to exit and save your changes when prompted.

If you do not want to keep your changes, use:

Ctrl + X → N

Nano is designed to be simple and accessible, especially for Linux users who need to edit files directly from the terminal. These basic shortcuts are particularly useful when managing files, scripts, and configuration settings on a Linux VPS Hosting server or a local Linux system.

Once you remember how to save and exit Nano, you can confidently edit, save, and manage files while working with Linux servers and VPS environments.

Learn more knowledge base: How to Install NPM and Node.js on Mac