Black Friday Deals for Linux Users are Now Live!
Learn more
Nov 1, 2022 2 min read

How to Save and Exit in Nano Editor

Table of Contents

You are editing files in the Linux terminal with Nano editor. You are new to both Linux and Nano.

You made some changes to the text file, things were going smoothly and now you have no idea how to save changes in Nano.

I have been in your situation. Here's what you need to do:

  • Ctrl+o: To save the file and continue editing it
  • Ctrl+x: To save the changes and exit editing

In both options, you'll have to confirm the changes. Still confused? Let me go in detail.

Save changes and continue editing

To open any text file with nano, you have to append the filename with the nano command.

For example, if I want to work with a file named Program.c, then I'm supposed to use the given command:

nano Programs.c

When you make any changes to the existing file, nano will show the * symbol with the filename:

Unsaved changes in Nano
Unsaved file changes are indicated with asterisk (*)

Once you're done making desired changes, you'll have to use Crtl+o and it will ask whether you want to apply changes you made recently:

Save changes in Nano editor

And you have to press the enter key to save the recently made changes to the file.

Save and exit from the Nano editor (or discord the changes)

Once you're done making changes, you just have to use Ctrl + x and you'll be back to the terminal.

But what if you forgot to save the changes before leaving nano? well, it will ask whether you want to save the modified buffer or not. So you don't have to be afraid of accidental exits.

Exiting Nano editor

If you press Y to save changes, it will show the filename again and you have to press the Enter key and it will close nano and drop you to the terminal.

You can also press N to discard changes and exit or Ctrl+c to cancel exiting and continue editing.

Final Words

This was a quick guide on how to save changes and close the nano text editor . To summarize again:

  • Ctrl+o: Save and continue editing the file
  • Ctrl+x: Save or discard changes and exit the file

Enjoy nano :)

Linux Foundation Training
Team LHB
Team LHB indicates the effort of a single or multiple members of the core Linux Handbook team.
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Linux Handbook.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.