nano-text-editor-and-nano-command-in-linux-1

Use a Nano Text Editor or Nano command in Linux

Nano command in Linux is not just a command but it is a text editor. Nano text editor is used to create and edit files, included in most Linux distributions.

It has a very simple interface, Which makes it a great choice for Linux beginners. If you are not pro in Linux then this tutorial is very useful.

I will cover of nano text editor of nano command in Linux with appropriate images.

Today, I am using CentOS 8, So I will show demonstration images on it.

How to Install Nano Text Editor on Linux

As I have told you already, Nano is by default included in most Linux distributions. However, if you didn’t get pre-installed nano on your system. Then It is necessary, You must know the installation process.

It is very easy, can be completed in simple two steps.

Step 1: Update repository:

Open the terminal and update the apt repositories with the command:

sudo apt update

Step 2: Install Nano Text Editor

Then, install Nano by running the following command. You must use different commands on different OS.

Debian/Ubuntu:

sudo apt install nano

RHEL/CentOS/Fedora:

yum install nano

With this, you have successfully installed the text editor.

I am using CentOS, which has a preinstalled nano text editor. So I can run nano commands without any interpretation.

Create a New file by using nano command in Linux

You can read another article on how to create a file in Linux. I have described 5 ways to create a new file including cat command, touch command, etc.

You can use several methods to open nano text editor.

As it is a command-line editor, now your first step is to open the terminal. You can open the terminal and the easiest way to access the terminal is the Ctrl+Alt+T shortcut key.

You can use nano command without any argument, You will get open a blank nano file.

Later on, you can decide to save or discard the file at the time of exit (Ctrl+x)

Press Ctrl+X to exit from the file.

Press (Ctrl+X) for exit the file, You will see the 3 option on the bottom of the screen.

  • Y for Yes
  • N for No
  • Ctrl+C for cancel

If you press y to save the file, you will have to give the name of the file. Type the name and press Enter.

In this example, the provided name is file.php.

As you hit enter the will be saved in the current working directory. If you want to save in another location then you will have to specify the path.

Use nano command to open an existing file

Open an Existing File by nano command

You can use the nano command to open an existing file, use the nano command followed by the file name. It is pretty simple.

For example, if the file is in your current location named file.php, the command will be as follows:

nano file1.php

If you want to open a file in another directory, you must include the path in the command, where the file is located.

I am going to open the file.php file which exists in the location /home/vijay/Documents/file.php. So the command will be

nano /home/vijay/Documents/file.php

It is also possible to open a file and directly go to a specific line or column.

nano +line,column file.php

Edit files in a nano text editor

Nano text editor has a graphical interface that makes it more attractive. I agree this doesn’t full graphical interface, but you can interact directly with what are you writing inside the file. You may see what is written already inside the file.

And You can do everything with the help of a keyboard inside the nano editor. example save the file, search the content, replace the content, and many more.
These are keyboard shortcuts.

Keyboard shortcuts of Nano command in Linux

When you open the nano text editor, you will see multiple keywords written on the bottom. You can see in the image.

These are keyboard shortcuts. You can control the keyboard shortcuts with a combination of the Ctrl button on the keyboard (Ctrl). which are represented by a carat (^) followed by a symbol.

For example, Press Ctrl+X to Exit out of the Nano text editor, but it is displayed as ^X in the bottom of the file.

In addition, there are combinations that require the Meta key (usually the Alt button). They are represented by the letter M followed by a symbol.

For example, the shortcut to Undo action in a text is Alt+U (displayed as M-U).

The two bottom lines in the text editor will display some of the most commonly used shortcuts, as seen in the image above.

If you want to see all valid shortcuts for a nano text editor, then press Ctrl+G (displayed as ^G) or F1. This will open Nano’s help text and list all possible keyboard shortcuts.

Conclusion

Now you have learned about know how to create a file in linux by using nano text editor. You have learned the basic text commands and commands used for creating, editing and saving files.

You can always refer to the Help text with Ctrl+G (^G) for additional commands.

If Appreciate My Work, You should consider: