In this tutorial, you will learn how to save a file in the Linux nano editor. 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

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
Since nano does not accept input from a mouse, it accepts many keyboard combinations with
Ctrl
and some other key. Some shortcuts are shown at the bottom of the interface. 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.
- 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 meansCtrl + X
. - 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.
- 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.
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 tutorial, 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.