12.07.2024

How to use Nano and What is it?

To work with the Linux operating system you need a terminal, shell and utilities that provide the user with the ability to manage and configure the system, as well as the basic performance of ordinary tasks! One of the popular utilities for working with text in Linux is nano. Let's take a look at its functionality, control options and evaluate its usability, both for a beginner and for an experienced specialist.

What is Nano and how to find it?

Nano is a text editor that is primarily intended for use via the console. It is part of the GNU software package, so it is quite popular and frequently used. It is easy to learn and can be useful even for beginners. To start working with nano you need to check if the package is installed, for this we will type the command into the terminal:

nano

Screenshot №1 — Check installation nano

If the output looks like this, then the package is probably not installed and you can do so via the package manager:

apt update && apt upgrade && apt install nano

For RPM-like systems, the command to install a package with its dependencies might look like this:

dnf update && dnf upgrade && dnf install nano

After making sure that all dependencies with the package are installed, via the nano command, we can move on to its syntax!

Syntax nano

In order to edit a file, write the path to it, or if you are in the folder with this file, just its name.

nano [path to file]

For example, we need to open a file with logs, for this we will write the full path:

nano /var/log/cloud-init.log

Screenshot №2 — Open file with nano

Once we have opened the file, we can see the inside of the file, as well as technical information such as headers and the control panel at the bottom. By default, the file can be immediately edited and changes can be made. You can move with the arrows on the keyboard. If you want to save your changes, press Ctrl + O, to exit without saving Ctrl + X. To call the utility help press Ctrl+G:

Screenshot №3 — Help page

If you notice, the ^ sign in the terminal is invoked via Ctrl and all the above pictured commands in the tooltip can be used via it, alternatively you can press Esc twice!

How to copy and paste via nano?

For copying there is a set of hotkeys Ctrl+K and Ctrl+U. You can select data on the keyboard by pressing Shift beforehand and moving the cursor with the arrows:

Screenshot №4 — Select data

Then use Ctrl+K to copy and Ctrl+U to paste the copied area. All steps in the tutorial can be performed on powerful cloud servers. Serverspace provides isolated VPS / VDS servers for common and virtualize usage.

Screenshot №5 — Create Server

It will take some time to deploy server capacity. After that you can connect in any of the convenient ways!

How to search for text via nano?

Let's assume we know a certain pattern, a template, for which we need to find data, for this purpose we press the key combination Ctrl + W. And enter the search mode, the line at the bottom will display the input data. After the input is finished press Enter, unfortunately, the word or data will not be highlighted, but only the cursor will stand at the beginning of the first occurrence. To search for the next occurrence press Ctrl + W again and without entering anything press Enter.

Screenshot №5 — Search text

Working with Linux requires knowledge of the terminal, shell and utilities that allow you to manage and configure the system and perform basic tasks. One of such useful utilities is the nano text editor. It is easy to learn, convenient for both beginners and experienced users. We have covered how to install and use nano, from basic operations to copying and searching text. This editor demonstrates that file management in Linux can be intuitive and efficient. Now you are ready to use nano to edit text files and optimise your work in the Linux console environment.