• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install and Use Nano Text Editor in Linux

Written by Admin, Updated On October 3, 2020
nano, terminal
How to Install and Use Nano Text Editor in Linux

It is basic requirement for the command line work to create or edit text files. Vim and Emacs are powerful command line editors but those might be overwhelming for new Linux users. Nano text editor is straightforward and easy to use. It includes all the basic functionality same as other text editors such as UTF-8 encoding, syntax highlighting, search and replace with regular expression support, multiple buffers, spellchecking and more. In this tutorial we will show you how to install and use of nano text editor.

Install Nano Text Editor#

Nano text editor is by default included in macOS and most Linux distributions. The process depends on the operating system you are running. If Nano text editor is pre-installed, you can skip this section to start learning the basic Nano text editing commands. You can check whether nano is installed or not issue the below command:

nano --version

It should show output as given below:

GNU nano, version 2.9.3
(C) 1999-2011, 2013-2018 Free Software Foundation, Inc.
(C) 2014-2018 the contributors to nano
Email: nano@nano-editor.org    Web: https://nano-editor.org/

If you don’t have nano installed on your system, you can install it using the package manager of your distribution. Make sure you need administrator privileges for Ubuntu, Debian and CentOS to install nano.

Installing Nano on Debian and Ubuntu#

To install Nano text editor on Debian or Ubuntu system, issue the following command:

sudo apt install nano

Installing Nano on CentOS and RHEL#

To install the Nano text editor on CentOS or RHEL based platforms, run this command:

sudo yum install nano

Use Nano Text Editor#

Open and Create Files#

Type nano followed by the filename, to create or open an existing file. Make sure that if you want to edit an existing file, you must be in the directory where the file is located. Alternatively, you can specify the full path to the file. To be able to open a file you must have read permissions to the file.

nano filename

It will open a new editor window and you can write or edit it. Use arrow keys on your keyboard to move the cursor around the text. At the bottom of this window, you can find some shortcuts to use with the Nano editor. Symbol ^ means that you must press CTRL + [Key] (CMD + [Key] for Mac users) to use the chosen command.

To save the changes made in the file and continue editing press CTRL + O.

To exit from the editor press CTRL + X. If any changes have been made to the currently open file, it will ask whether to save them or not otherwise it will exit right away. Input y for yes, or n for no, and then press ENTER.

Also, you can get a list of all commands by typing Ctrl+g.

Editing Files#

You can start typing and editing the content immediately after opening the file because nano is modeless editor. In order to select text go to the beginning of the text and press ALT + A. This will set a mark for selecting, then move over the text to be selected with the arrow keys.

To copy the selected text press ALT + 6. This will copy text to the clipboard. To cut text press CTRL + K.

If you want to paste text press CTRL + U. If no text is selected before copying or pasting, it will copy/cut the entire line.

Searching and Replacing Text#

To search for a particular word or part of a text inside the editor, use the “where is” option with the Ctrl+W shortcut (^W). This will open a search prompt where you can type in the text you want to find. To continue to the next result, use Alt+W (M-W).

The search bar can also find specific line numbers. Press Ctrl+T (^T) while in it and the line number you want to find.

You can also search with regex (regular expressions). These represent a search pattern defined by a sequence of characters. To do so, use the Alt+R shortcut (M-R).

If your goal is to find and replace text, press CTRL+W and then CTRL+R. It will ask for the search text and the text to be replaced by. Afterward, the editor will take you to the first instance of the text and ask you whether to replace it or all of the occurrences.

Select, Copy, Cut and Paste Text#

If you want to select part of a file, navigate to the starting of the text, press the Alt+A shortcut (M-A) and use the arrow keys to move over the text you wish to select. The selected text will be highlighted. If you want to cancel the selection press Ctrl+6

Next, you can copy the selected text with the Alt+6 or combination (M-6) or you can cut selected text with Ctrl+K (^K). If you use these shortcuts without selecting any text prior, it will copy or cut the entire line of text.

To paste the text move the cursor to where you want to put the text and press Ctrl+u.

Save and Exit File#

To save changes made by you in a file, use the Ctrl+O (^O) keyboard combination. It will ask you to enter a file name or confirm the name of an existing file. If the file does not exists then it will create once you save it.

To exit out of Nano, press Ctrl+X (Nano displays it as ^X). If there is any unsaved changes it will prompt whether you want to save the changes or not.

Set Nano as the Default Text Editor#

In most of Linux systems, the default text editor is set to vi. You can make nano as a default text editor by making change to VISUAL and EDITOR environment variables.

Bash users can export the variables in the ~/.bashrc file:

export VISUAL=nano
export EDITOR="$VISUAL"

Conclusion#

You have learned how to install and use GNU nano text editor. It is a popular text editor and very straightforward for new Linux users. If you would like to learn more about GNU Nano visit the official nano documentation page.

If any question or suggestion, please leave comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Setup SSH Keys on Debian 10 Buster
Next Article   How to Install WordPress with Nginx on Ubuntu 18.04

Related Posts

  • How to Install SSH Keys on Ubuntu 22.04

    How to Set up SSH Keys on Ubuntu 22.04

    January 7, 2023
  • How to Install Fail2ban on Ubuntu 22.04

    How to Install and Configure Fail2ban on Ubuntu 22.04

    December 5, 2022
  • How to Enable SSH on Ubuntu 22.04

    How to Enable SSH on Ubuntu 22.04

    December 1, 2022

1 Comment

  1. Darlan Reply
    October 21, 2020 at 6:29 pm

    Unico site que eu entendi como usar esse editor.
    Top.

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook