The text editor called Nano for Linux is considered one of the most common among beginners. It has the advantage of being able to edit configuration files without any problems, it is also easy to use, and it is available from most distributors. In this tutorial we will tell you how to save a file in Nano. if you have already made changes to the configuration file.
Nano is a simple command-line text editor that is often used in Linux distributions. It provides basic text editing functions such as insertion, deletion, search and replace, and supports various programming languages thanks to syntax highlighting.
It has a simple interface and control keys, making it accessible to command line novices. It is one of the most popular text editors in Linux due to its ease of use. To start Nano, just type the command "nano" in the terminal and it will open a text file in the Nano editor where you can make changes and save files.
There are several ways to save. Let's look at each one in detail.
The easiest way is to press the keyboard shortcut Ctrl+O
. once all changes to the file have been made to save them. At the bottom of the program, you can see all the hotkey shortcuts you need to use the utility. This part of the program lists all the shortcuts that can help you in your work.
Immediately after pressing the keys, the editor will ask you to enter the name of the file to save:
Once you are done, press Enter. To return to the editing window press Ctrl+X
. Next, the program will inform you that the file has been successfully saved.
At this point you can close the editor by pressing Ctrl+X
.
Let's also consider the case when you need to save data to a file that belongs to another user or superuser, and this record has no access or permission. In such a case, the user will see: "Write error /filename/file name: Access denied":
How to solve the problem? The easiest way is to close the editor(Ctrl+X
) without saving the changes. The answer to the question is No:
After you have done this, you can run the editor as a superuser:
$ sudo nano /etc/passwd
Next, you can write the data to a file. If the changes cannot be lost, at the file name prompt, specify the path to the new file in your home directory, e.g. ~/temp_passwd
:
However, if you try to save data to a file belonging to another user or superuser to which you do not have access (for example, configuration files in the /etc directory), you will get the error: "Error writing /filename/file name: Access denied":
The easiest thing to do is to close the editor by pressing Ctrl+X
without saving the changes. You should answer the editor's question about saving the buffer with No:
And then open the editor as a super user:
$ sudo nano /etc/passwd
After that you will be able to write data to the file as described above. If you don't want to lose the changes, you can specify the path to the new file in your home directory during the file name request, e.g. ~/temp_passwd:
The file will then be saved there, where you can then easily move it to replace the old one with the mv
command using sudo
:
$ sudo mv ~/temp_passwd /etc/passwd
Remember that all system files should be edited as superuser.
Has several advantages that make it a popular text editor for Linux users:
These advantages make Nano a popular choice for those looking for a simple and efficient text editor in a Linux environment.