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
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
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
The search bar can also find specific line numbers. Press
^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 (
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.
N it will move to the next match.
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?
Copy the selected text to the clipboard using the?
To cut the selected text?
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?
To paste the text move the cursor to where you want to put the text and press?
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
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:
- Move back one character:
- Move forward one word:
- Move back one word:
- Move to the previous line:
- Move to the next line:
- Move to the next page:
- Move to the previous page:
- Move to the beginning of the line:
- Move to the end of the line:
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.