Linux has several text editors to open files, of which the most famous are Nano and Vi. We recommend learning to use Vi, see our VI article. Nano is easier to use if you have no experience with either. For that reason, you always see nano in the instructions in our Knowledge Base.
In this article, we explain how you can efficiently edit files with Nano.
Installing Nano
With a minimal installation, Nano is not available by default in most OSs. Therefore, we go through the installation of Nano first.
CentOS 7
sudo yum -y install nano
Ubuntu
sudo apt install -y nano
Using Nano
The use of Nano is relatively simple and will feel familiar to people who are used to keyboard shortcuts in Windows.
Opening files
In Linux, every file is a text file. You open a file with Nano via the command:
nano /map/bestandsnaam
Suppose you want to view /var/log/messages, here, the command would then be nano /var/log/messages.
General
In Nano, you usually use a key combination of control + a letter. Many commands also have an alternative using the Function keys. Below is an overview of some general management functions of Nano.
Navigating in files
JWith Nano, you can use the arrow, and navigation (home, end, etc.) keys to move the cursor. You often work with larger files and in that case, that is not the easiest way of working. Nano has a number of useful methods to quickly go through a file to the place you want to go to.
Cut copy paste
Do you use Putty in Windows? Then you can select text with your mouse. This will automatically appear in your clipboard and you can paste it in Windows. You can also use the shortcuts in the overview below, or of course keys such as delete or the arrow keys, to remove a character or to move your cursor.
For these functions, if you copy or cut, all content will be in the clipboard until you actually paste it or close nano. Suppose that you copy a line with alt + 6 and then press alt + 6 again, then both lines are remembered in the clipboard. With ctrl + u, you paste them both at once.
Line numbers in Ubuntu 18
Ubuntu 18 has an advantage when using Nano compared to other OSs (at the time of writing): A newer version of Nano is used with which you can display line numbers.
In addition, colour code is also used, for example with commented (#) rules, which makes your files a lot clearer.
Showing line numbers
- In an open file, show line numbers by pressing alt + shift + 3.
- o automatically open line numbers in all files, open / create the file .nanorc
nano ~/.nanorc
set linenumbers
Should you have any questions left regarding this article, do not hesitate to contact our support department. You can reach them via the ‘Contact Us’ button at the bottom of this page.
If you want to discuss this article with other users, please leave a message under 'Comments'.