November 25, 2019
5min Read
Domantas G.

In this tutorial, you will learn how to use Nano, a popular text editor in Linux that comes with many powerful features. It allows you to edit and create various files on your computer or server. So let’s get right into it!
When it comes to editing text via command line, Nano is considered as the easiest tool to use. It beats Vim and Emacs editor, which are known to be overwhelming, especially for novice Linux users.
Though it’s simple, Nano editor packs a complete feature set. To name a few, it allows you to copy, paste, select, and search text. Furthermore, there is a bottom bar inside the editor that shows you useful shortcuts. All in all, the Nano editor is suitable for both advanced users and beginners.
You can often find it prepackaged on Linux PC or server. For example, Hostinger includes Nano text editor on its shared hosting and VPS plans.
Before we begin learning how to use Nano, make sure that you have access to a Linux machine and its command line. If you’re testing the steps on a VPS, you also need to know how to establish SSH connection using PuTTY (Windows) or terminal shell (Linux, macOS)
This process depends on the operating system you are using. Some of them may already come with the Nano text editor pre-installed. If that is the case, you can skip this section.
To install Nano text editor on Debian or Ubuntu machines, execute the following command:
sudo apt-get install nano
Wait for the installation process to finish.
The sudo part is meant for running this command as a root user. This means you may be prompted to enter a password in case you are currently not logged in as a root user.
We can run this command to install Nano text editor on CentOS or RHEL based platforms:
yum install nano
That is it for the installation. As soon as the setup ends, you can use it immediately!
In this part, you are going to learn how to open and close files. Also, search and replace text. Then, we’ll show you some editing tips and other basic commands that you can use in Nano text editor.
The main syntax to open Nano to edit a certain file is:
nano filename
Let’s say we want to open a file named demo.txt. The command would look like:
nano demo.txt.
You can open various file types, like .txt, .php, .html, and so on. Just keep in mind that if you want to specify the file directly, you have to be in the directory where the file is located.
But for example, you are in another folder, and you want to open a file (demo.txt) in /path/to/directory, you should enter this line instead:
nano /path/to/directory/demo.txt
If you enter a name and that file is not present in the directory, Nano will create the file. Meanwhile, if you only execute the nano command without specifying the file name, Nano text editor will create an empty untitled file and ask for a name when you exit the editor.
After running the nano command, a new window will pop up where you can freely edit the file. Below is what the interface of the Nano text editor looks like. Just use the arrow keys on your keyboard to move the cursor around the text.

At the bottom of the window, you can find some shortcuts to use with the Nano editor. The “^” (caret) means that you must press CTRL (Windows) or CMD (macOS) to use the chosen command. Here are a few examples.
Take note that whenever you are opening an important configuration file, it is recommended to use the -w option. It will open the file in a standard format. If you don’t use this option, nano will wrap the text to fit the display by default. The command should be like this:
sudo nano -w /etc/apache2/apache2.conf
To search in the text, press CTRL + W. Insert your value and press Enter. To continue searching for the same text string, use ALT + W.
If your goal is to find and replace a text, press CTRL+W and then CTRL+R to enter the text that you want to search and the text that will replace it. The editor will then take you to the first instance of the text. You can press Y to replace one text or A to replace all instances.
Should you want to go back after typing a shortcut, just use CTRL + C to cancel the current process.
These are the commonly used shortcuts when editing a text in Nano.
We have compiled the most useful commands to help you utilize the Nano text editor more effectively.
| Command | Explanation |
| CTRL + A | Lets you jump to the beginning of the line. |
| CTRL + E | It allows you to tump to the end of the line. |
| CTRL + Y | Scrolls page down. |
| CTRL + V | Scrolls page up. |
| CTRL + G | A Help window will pop out and show you all the available commands. |
| CTRL + O | To save the file. Nano will ask you to edit or verify the desired file name. |
| CTRL + W | It’s used to search for a specified phrase in your text. Press ALT + W to search for the same phrase again. |
| CTRL + K | It cuts the entire selected line to the cut buffer (similar to clipboard). |
| CTRL + U | To paste the text from the cut buffer into the selected line. |
| CTRL + J | Justifies the current paragraph. |
| CTRL + C | Shows the current cursor position in the text (line/column/character). |
| CTRL + R | Opens a file and inserts it at the current cursor position. |
| CTRL + X | To exit Nano text editor. It prompts a save request if you made any changes to the file. |
| CTRL + \ | Replaces string or a regular expression. |
| CTRL + T | Invokes the spell checker, if available. |
| CTRL + _ | Lets you go to the specified line and column number. |
| ALT + A | To select text. You can combine this command with CTRL + K to cut a specific part of the text to the cut buffer. |
Nano is a popular and versatile terminal-based text editor in Linux. It is a perfect fit for beginners and professionals who are looking for a complete tool to modify their text.
In this tutorial, you have learned how to use the Nano text editor. We have shown you a lot of useful commands and editing tips to improve your workflow. Now, we hope that you can easily edit text without having to download and re-upload the file.
Good luck, and be sure to check our other SSH and VPS tutorials.
Leave a reply