How to Save a File Using Nano?

In Linux, the Nano is a text editor to modify text files through the command line. Nano is often replaced by the more complex and feature-rich vim and emacs text editors. It is a most popular choice for Linux users who want a more user-friendly text editing experience. Another benefit is that it comes pre-installed in the Linux operating system, so you don’t need to install it.

This guide will demonstrate methods to create and save a file using nano in the Ubuntu system. The supported content of this article is as follows:

Prerequisite: How can a File be Created Using Nano?

A new file, “first_file” is created with the “nano” utility before saving data in the Nano Editor. For instance, the below script will create an empty file as below:

$ nano first_file

It navigates to the Nano Editor on which you can write some content. In our case, write “Hello Everyone…!!!”. Apart from that, you can write any data or information in it:

Let’s save the created file:

How can a File be Saved Using Nano?

To save the opened file “first_file” in the Nano Editor, press the “Ctrl+S” shortcut key from the keyboard. In this way, the specific content will be saved, which is written in the particular file:

If you close the file without saving it, a pop-up window is generated “Save modified buffer?”. For instance, hit the “Y” key to save the particular file:

How can a File be Saved With a Different Name Using Nano?

To overwrite a file with a different name, hit the shortcut key “Ctrl+O” and type the new name of the file which you want to store. In our case, write the “second_file” to replace “first_file” and press the “Enter” key:

It requires confirmation to save the file under a different name, presses the “Y” to save the file with a new name:

Now, you can verify that the “second_file” has been overwritten with the “first_name” using Nano Editor:

Let’s head over to save the file with the specified format:

How can a File be Saved With a Specified Format Using Nano?

In Nano Editor, you can store the file in a specific format. To do so, press the “Ctrl+O” to place the file name as “first_file.txt” and hit “Enter”:

For confirmation, press the “Y” key from the keyboard to change the file format:

Now, you can verify that “first_file.txt” has been saved in the below screenshot:

Conclusion

In Ubuntu, the existing file can be saved by pressing the shortcut key “Ctrl+S” in Nano Editor.

Additionally, the shortcut key “Ctrl+O” enables the users to overwrite the file with a different name or file format. After modification, hit “Enter” to apply the changes to the particular file. This guide has explained various methods to save a file Using Nano Editor.