How to install and use nano editor

  7 months ago     Views:  476  
Jitesh Meniya
2 Follows


Many times, working in command line, many times we have to create and edit files. Also working in the server by ssh, we also need to create and edit files. There are many command line text editor available to do these type of work. Vim and Emacs are the most popular command line text editor but they are difficult for the new users. There is also one text editor available for that.

Nano or GNU Nano is a simple and user friendly text editor for Unix and Linux systems which provides command line interface. Nano provides all basic features like text editing, search and replace, go to line and column number, auto-indentation, feature toggles and filename tab completion. Most of hosting providers and linux distribution comes preinstalled with Nano text editor.

In this article, we will discuss on how to install and use Nano text editor in Linux. Before we start, make sure you have basic knowledge of Terminal or CMD. If you are working in remote server, make sure you have already connected with server through ssh connection.

Install Nano text editor

Nano text editor comes pre-installed on macOS and most Linux distros. If you want to check if it is installed on your system or not, use this command.

nano --version

You will see bellow response, if you have already Nano text editor installed.

You can also install Nano text editor with bellow commands.

Debian based Linux system

sudo apt-get install nano

Fedora and CentOS Linux system

sudo yum install nano

Basic commands

Most of commands for Nano text editor are like:

nano [OPTION]... [FILE]

To create or edit existing files, use bellow command.

nano /path/to/file/file.txt

If file is already exist, it will open for edit, other wise new file will create when you save the file.

Run the command nano in the Terminal and bellow window will appear. At the bottom of the window, there are some shortcuts available. All the shortcuts with ^ (caret) signs indicates CTRL or CMD key while some shortcuts with M- (Meta key) indicates ALT key.

Here are some Standard commands for Nano text editor:

CTRL + G shortcut displays all shortcuts and help text.

If you want to find some text, first press CTRL + W key, then input the search keyword. Press ENTER to find the first matched text. Then press ALT + W to go to next matched text.

To replace text, first press CTRL + \ to enter the text that you want to replace with keyword and hit ENTER. This will ask to replace the first matched text with Y or N key.

To select the text, first press ALT + A key, this will start selecting. Now press ARROW KEYS to move the cursor to select text and then press ALT + 6 key to copy or CTRL + K to cut the selected text. Press CTRL + U to paste the copies text.

Press CTRL + _ to go the specific number line.

To save the file with changes, press CTRL + O. If you want to exit Nano text editor, press CTRL + X shortcut. If there are some changes, it will ask to save changes with Y or N option.

CTRL + C to get Cursor's current position or cancel the current active shortcut.

If you want to scroll to the next page, press CTRL + Y or previous page with CTRL + V.

There are also some options you can pass to do following changes.

-B     Backup file befor editing the file.
-E     Converts tabs to spaces while editing
-R     Don't read or write to any file not specified on the command line;
-S     Text will scroll line-by-line instead of page
-i     Automatic indentation
-c     Continously display cursor position
-t   Don't ask to save file before exiting.

 

Conclusion

This is the basic shortcuts you can use the GNU nano text editor. For more information about Nano visit the official nano documentation page. I hope this article will help you.

Also if you have any question, feel free to comment in the bellow comment section.


Was this article helpful?

0 out of 0 person found this article helpful.

Leave a comment

OR

No Comments