The nano editor is one of the most popular ways to edit files via the command line on Linux systems. There are plenty of others, like vim and emacs, but nano is praised for its ease of use.

Despite being one of the easier to use text editors, it can still be confusing the first time you open it, especially if you're used to GUI applications. In this guide, we'll go over the step by step instructions to save and exit a file in nano. This is one of the most common and recurring tasks you'll ever do with the text editor.

In this tutorial you will learn:
  • How to save and exit a file in nano editor
Saving and exiting a file in nano editor
Saving and exiting a file in nano editor
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software nano
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Save and exit a file using nano editor


SUBSCRIBE TO NEWSLETTER
Subscribe to our NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


We're assuming you've already opened a file with the usual syntax:

$ nano file-name

After you've made some changes to the file and you wish to save them, use the following instructions to save the file and exit nano.

  1. To exit and save the file, start by pressing Ctrl + X on your keyboard. This will attempt to exit nano. To remember this keyboard combination, check the bottom of the nano menu. ^X just means Ctrl + X.
  2. The menu indicates that Ctrl + X (represented as ^X) will close the editor
    The menu indicates that Ctrl + X (represented as ^X) will close the editor
  3. You'll now be asked if you want to save your changes to the file. You need to respond by entering either "Y" or "N". Since we are trying to save our changes, press "Y" and hit enter.


  4. nano is asking if we want to save our changes to the file
    nano is asking if we want to save our changes to the file
  5. Next, you'll be asked to give a name to the file. If you're trying to overwrite an existing file with your current changes, then you can simply hit enter on your keyboard. Otherwise, fill out a new file name.
  6. Overwrite the existing file or write a new file name
    Overwrite the existing file or write a new file name

That's all there is to it. As long as you had write permissions on the file you were editing, your new changes will be applied to the file.

Closing Thoughts

In this guide, we saw how to exit and save a file using the nano editor on Linux. The key to remember is that you need to press Ctrl + X to close the editor. For everything else, you can simply follow the prompts or refer back to our guide.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.