Google Cloud

How to use Nano Editor in Linux (Ubuntu/Debian/CentOS)

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we recommended.

Pinterest LinkedIn Tumblr

How to use Nano Editor in Linux operating systems like Ubuntu or Debian or CentOS. Nano is one of the easiest command line text editor with syntax highlighting, multiple buffers, search and replace with regular expression support, spellchecking, UTF-8 encoding, and more.

In this guide you are going to learn how to use Nano editor using terminal commands and perform various operations like create, open, edit, save, search and replace, cut, copy, paste and more in Nano editor.


Nano editor installed in your system or server.

If you don’t have Nano installed you can install it easily using the following command.

Install Nano on Ubuntu/Debian

To install Nano on Ubuntu or Debian execute the below command from your terminal or SSH.

sudo apt install nano

Install Nano on CentOS/Fedora

To install Nano on CentOS or Fedora execute the below command from your terminal or SSH.

sudo yum install nano

Basic Control Characters and Keys

There are keyboard combinations for each function in Nano. Control shortcuts (used with the CTRL button) are represented by a carat (^) followed by a symbol.

For example, the shortcut to Exit out of the Nano text editor is CTRL+X(displayed as ^X).

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 an action in a text is ALT+U (displayed as M-U).

1. Create and open a new file with Nano

To create and open a new file you can directly use the nano command with the filename as shown below.

You can also use this command to open an existing file with name.

sudo nano filename.txt

To exit the editor you can use CTRL + X. If you have modified the file you will be prompted to save the changes or ignore it by typing Y for yes and N for no.

2. Search using Nano

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.

Regex search

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).

3. Replace Text with Nano

To search and replace, press CTRL+/. Enter the search term and the text to be replaced with. The editor will move to the first match and ask you whether to replace it.

After hitting Y or N it will move to the next match.

Pressing A will replace all matches.After you have selected the search item, it will ask what you want to replace it with.

4. Cut, Copy and Paste using Nano

To select text, move the cursor to the beginning of the text and press ALT+A. This will set a selection mark. Move the cursor to the end of the text you want to select using the arrow keys. The selected text will be highlighted. If you want to cancel the selection press CTRL+6

Copy the selected text to the clipboard using the ALT+6 command.

To cut the selected text CTRL+K combination.

You can also cut whole lines by simply moving the cursor to the line and press CTRL+K. You can cut multiple lines by hitting CTRL+K several times.

To paste the text move the cursor to where you want to put the text and press CTRL+U.

5. Copy Another File Into the Current File

While editing a file in Nano, it is also possible to insert the entire contents of another file into the current one with the CTRL+R (^R) shortcut.

This command will open the bottom bar in which you must write the path and file name you wish to import.

6. Keyboard Shortcuts for Nano

While editing large files the following keyboard shortcuts will be highly helpful to navigate easily within the file.

  • Move forward one character: Ctrl+F (^F)
  • Move back one character: Ctrl+B (^B)
  • Move forward one word: Ctrl+Space (^Space)
  • Move back one word: Alt+Space (M-Space)
  • Move to the previous line: Ctrl+P (^P)
  • Move to the next line: Ctrl+N (^N)
  • Move to the next page: Ctrl+V (^V)
  • Move to the previous page: Ctrl+Y (^Y)
  • Move to the beginning of the line: Ctrl+A (^A)
  • Move to the end of the line: Ctrl+E (^E)

Prepare yourself for a role working as an Information Technology Professional with Linux operating system


Now you have learned how to perform various operations using Nano editor on Ubuntu or Debian or CentOS systems.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.


Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.