Nano Editor
Nano Editor
In this tutorial, we will discuss the basic usage of the Nano editor, as well as some of
the features it provides.
Please note that all the examples and instructions mentioned in this article have been
tested on Ubuntu 16.10 LTS, and the Nano version we've used is 2.2.6.
The following sections explain the basic usage usage as well as some of the features of
Nano.
$ nano
or
$ nano [file-name]
The second way can also be used to open an existing file. Needless to say, if you want
to open a file which is not located in your current directory, then you have to provide
the absolute or relative path to that file.
The following screenshot shows a file opened in the nano editor:
As you can see, at the bottom of the editor window, there's useful information related
to keyboard shortcuts that let users perform some basic operations such as cut and
paste text. Shortcuts that let you exit the editor and launch help are also there.
Nano also allows you to save files in different OS formats. For example, you can save in
DOS format by pressing Alt+d. Note that to change the format, first you have to
initiate the usual save process by pressing Ctrl+o, and then use format-specific
shortcut Alt+d .
3. How to cut and paste text in Nano
To cut and paste a particular line, first bring the cursor to that line. Now,
press Ctrl+k to cut, then head to the place where you want to paste it, and finally
use Ctrl+u to paste.
For example, in the screenshot below, if the requirement is to cut the first line and
paste it to the bottom. Then, go to the line and press Ctrl+k. Now, navigate your
cursor to the bottom and press Ctrl+u.
You can also copy a particular string instead of full line. Nano can not directly perform
COPY-PASTE. Instead you should perform
CUT -> PASTE(same position) -> PASTE(another position)
1- From the first character you want to copy, hold SHIFT down and go all the way to the
end using right arrow key.
2- Press CTRL+K, which cuts the text from the file.
3- Press CTRL+U, paste to the same position again.
4- Place the cursor anywhere you want.
5- Press CTRL+U, again.
As you can see in the above two screenshots, ‘made’ was selectively cut and pasted at
the bottom.
For example:
As you can see in the above screenshot, the cursor was at the second line and fifth
column when the file was opened.
For example:
For example:
$ nano -B abc.txt
The backup will be saved in the current directory with the same filename but suffixed
with a tilde (~).
Note that files created for the first time can not be backed up.