Every beginner seeking to quench their thirst for the mastery of the Linux operating system must at some point go through the famed Nano text editor. It is a straightforward text editor for users yet to master advanced text editors like Vim and ed.
This tutorial will walk us through the installation of Nano text editor on various Linux operating system environments together with a preview of its useful features and how we can use them to accomplish the most basic computing objectives.
Install Nano Text Editor in Linux
The Nano text editor comes pre-installed on major Linux operating system distributions. If for some reason it was uninstalled or not installed on your Linux system, reference the following installation guide.
$ sudo apt install nano [On Debian, Ubuntu and Mint] $ sudo yum install nano [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ sudo emerge -a app-editors/nano [On Gentoo Linux] $ sudo pacman -S nano [On Arch Linux] $ sudo zypper install nano [On OpenSUSE]
After the installation process completes, confirm the installed nano text editor version.
$ nano --version GNU nano, version 6.2
How to Use Nano Text Editor in Linux
We can now look at various beginners’ approaches to using the Nano text editor to accomplish various computing objectives.
Creating a New File in Nano
To create a new file using the nano text editor, simply refer to the following command syntax:
$ nano preferred_file_name
For instance, we can create a file called new_file.txt in the following manner.
$ nano new_file.txt
After the new file is created, you can start writing content into it while using the [Enter]
key to jump to the next line.
Once you are through with populating the file with the needed content, you can proceed to save it with the keyboard key combination [Ctrl]+o
. To close the file and exit its window, use the keyboard key combination [Ctrl]+x
.
Opening an Existing File in Nano
Supposing that the above file we just created already existed, to open an existing file using the nano text editor, we would implement the following command syntax:
$ nano file_name
To re-open the above file, we just created, we would run the command:
$ nano new_file.txt
If the file you want to open does not exist, a new one with the specified name will be created.
Opening a File as read-only in Nano
To open your file as read-only whereby no user is allowed to write or edit it, open the file with a -v
flag.
$ nano -v new_file.txt
Opening Configuration Files in Nano
It is recommended that while the opening configuration files with nano editor, we make use of the -w
flag to avoid text wrapping which tends to alter the proper display of the file content.
$ nano -w new-file.txt
To save a file with a backup copy, use the --backup
command option.
$ nano new_file.txt --backup
The above command will create a backup file with the name new_file.txt~.
$ ls -l new_file.txt $ ls -l new_file.txt~
We are now comfortable with handling files in the Nano text editor. The next article guide will handle how to execute undo and redo operations with this Nano editor.