Nano Text Editor in Linux
Last Updated :
05 Jun, 2024
In the vast world of Linux text editors, Nano stands out as a simple yet powerful tool for editing files directly from the command line interface. Whether you're a novice user or an experienced developer, Nano offers a straightforward and efficient editing experience. In this article, we'll delve into the depths of Nano, covering its features, usage, customization options, and advanced functionalities.
Introduction to Nano
Nano is a command-line text editor that comes pre-installed with most Linux distributions. It's designed to be user-friendly, with a simple interface that resembles popular graphical text editors. Nano provides essential editing features, making it ideal for quick edits, creating configuration files, or writing scripts directly in the terminal.
Installing Nano Text Editor
Nano is generally by default available in many Linux distributions, but if it is not installed, you may install it using the following commands:
sudo apt update
- sudo: This part tells the system to run the command with super user privileges, also known as "root" access. Normally, users don't have this privilege, as it allows them to modify critical system settings.
- apt: This stands for "Advanced Package Tool" and is the main package manager for these systems. It handles installing, removing, and updating software.
- update: This is the specific command within
apt
that tells it to update the list of available software packages.

In case of Debian/Ubuntu
sudo apt install nano
- sudo: This stands for "superuser do" and is used to execute commands that require administrative privileges. Basically, it's asking for permission to make changes to the system.
- apt: This is the package manager used by Debian-based systems. It's like a software store that keeps track of available programs and helps you install them.
- install: This tells the package manager that you want to install something new.
- nano: This is the specific program you're installing, which in this case is the Nano text editor.

In case of CentOS/Fedora
sudo yum install nano
- sudo: This tells the computer you want to run the following command with administrator privileges. Imagine needing a special key to access certain settings on your computer -
sudo
is like that key for commands. - yum: This is the package manager specifically used by certain Linux distributions (like CentOS or RedHat). It's like a giant storeroom for software that keeps track of everything installed and helps you find new programs.
- install: This tells
yum
that you want to add a new program to your system. - nano: This is the name of the specific program you're installing. In this case, it's nano, a popular text editor used for creating and editing plain text files.
Create and Open a New File in Nano Editor
This command will open a new file with new_filename as shown in the output. In case the file already exists it will open the same and in case the file is not there in the current directory it will create a new one. At the bottom of the window, there is a list of shortcut keys for nano.
nano new_filename

Save a file in Nano Editor
It will ask you for the filename. In case, you want to save the changes to a new file or want to create a new file then change the name else keep the name same.
press Ctrl+o
As soon as you will press enter key, then In case, you have changed the name of the file then it will save the file with a new name and if not then it will save the changes to the current file.

Cut and Past in Nano Editor
To cut paste in a file. Ctrl+o is used to cut and Ctrl+u is used to paste the text.
To cut and paste a whole line. Move to the line which you want to cut then press Ctrl+k. Now the line is moved to clipboard, To paste it, go to the position where you want to paste and then press Ctrl+u
To cut and paste the selected text. Select the text which you want to cut then press Ctrl+k. Now the text is moved to clipboard. To paste it, go to the position where you want to paste and then press Ctrl+u. 
Search in Nano Editor
To search a word in a file Ctrl+w is used. Press Ctrl+w It will ask for a word to search for. Enter the word It will search for the word and will place the cursor in the first letter of the first occurrence of the word.

Spelling Check in Nano Editor
To enable spell check in nano. First, install the spell check package.
sudo apt install spell
It will then ask for the password then enter the password. Then press y and then press enter.
- To do spell check first press Ctrl+t
- Now it will ask you to replace the incorrect words
- Enter the word to replace with there
- As soon as you will press the enter key

Basic Navigation and Editing in Nano Editor
Nano's interface is intuitive and easy to navigate. Here are some essential commands to get started:
- Navigation: Use the arrow keys to move the cursor up, down, left, or right.
- Page Navigation: Press
Ctrl
+ V
to move to the next page or Ctrl
+ Y
to move to the previous page. - Editing: Type directly to insert text. Use
Backspace
to delete characters, and Delete
to delete the character under the cursor.
Saving and Exiting in Nano Editor
Saving and exiting files in Nano is straightforward:
- Save: Press
Ctrl
+ O
to write the current buffer to a file. Nano prompts you to enter the filename if you haven't specified one. - Exit: Press
Ctrl
+ X
to exit Nano. If there are unsaved changes, Nano will ask if you want to save before exiting.
Replace in Nano Editor
Nano provides powerful search and replace functionalities:
- Search: Press
Ctrl
+ W
to search for a specific term in the file. Nano highlights the first occurrence, and you can navigate through subsequent matches using Alt
+ W
. - Replace: Press
Ctrl
+ \\
to activate the replace mode. Enter the search term, followed by the replacement, and press Enter
to replace the first occurrence. Press A
to replace all occurrences.
Customization Options in Nano Editor
While Nano's default configuration works well for most users, you can customize its behavior to suit your preferences:
- Configuration File: Nano reads settings from the
nanorc
file located in /etc/nanorc
or ~/.nanorc
. You can modify this file to customize Nano's behavior, such as enabling syntax highlighting, defining keyboard shortcuts, or changing default options. - Syntax Highlighting: Nano supports syntax highlighting for various programming languages. To enable syntax highlighting, uncomment or add the appropriate syntax-specific lines in the
nanorc
file.
Advanced Features in Nano Editor
Beyond its basic functionalities, Nano offers some advanced features for power users:
- Multiple Buffers: Nano supports multiple buffers, allowing you to edit multiple files simultaneously. Use
Ctrl
+ R
to open a new file in a separate buffer. - Spell Checking: Nano includes a built-in spell checker. Press
Ctrl
+ T
to toggle spell checking on or off, and Alt
+ T
to jump to the next misspelled word.
Set Nano as the Default Text Editor
Here's how to set nano as the default editor in the command line:
- Open your terminal
- Edit your shell profile (usually
.bashrc
for bash). You can use nano itself to edit this file:
nano ~/.bashrc
- Add the following lines to the end of the file:
export EDITOR="nano"
export VISUAL="nano"
- EDITOR is the most commonly used environment variable for the default editor.
- VISUAL is a fallback variable used by some programs. Setting both ensures wider compatibility.
Save the changes and exit the editor (usually Ctrl+O to save, Ctrl+X to exit).
Refresh your shell configuration to apply the changes. You can do this by either restarting your terminal window or running:
source ~/.bashrc
Conclusion
Nano is a versatile and user-friendly text editor that provides essential editing capabilities for Linux users. Whether you're editing configuration files, writing scripts, or making quick changes on the command line, Nano offers a seamless editing experience. By mastering Nano's features and customization options, you can enhance your productivity and efficiency in managing text files within the Linux environment.
Similar Reads
Linux Text Editors
For Linux users, text editors are essential tools that play a crucial role in various tasks, from coding and writing to system administration and configuration management. Linux offers a wide range of text editors, catering to different preferences and use cases. In this article, we will delve into
10 min read
vi Editor in Linux
The default editor that comes with the Linux/UNIX operating system is called vi (visual editor). Using vi editor, we can edit an existing file or create a new file from scratch. we can also use this editor to just read a text file. The advanced version of the vi editor is the vim editor. Table of C
9 min read
Vim Editor in Linux
If youâre new to the world of Linux, one of the first things youâll encounter is the command line interface. And if youâre going to be working in the command line, youâll inevitably come across various text editors. Among them, Vim stands out as a powerful, yet notoriously complex, text editor. In t
7 min read
Installing Kate text editor on Linux
In Linux, as there are various text editors like Vi and Vim, but all these editors are terminal-based, there is no responsive User Interface in these editors, so we can install UI-based text editors on Linux. There is one of the editors named Kate, which is a popular choice of many Linux users, as t
5 min read
AMP Text Editor for Linux Terminal
Amp is a fully-featured and lightweight text editor inspired by the Vi/Vim text editor. Amp editor is a terminal-based editor, and it is written in the Rust language. It provides the all fundamental features required for a modern text editor. Amp does not need any configuration it comes with all con
3 min read
How to Delete Line in Nano Editor?
In a terminal environment, Nano is a straightforward and widely used text editor for Linux and macOS systems. Deleting lines in Nano is a basic yet essential operation, allowing for efficient editing within files. By following simple keyboard shortcuts like "Ctrl+K," you can swiftly remove lines fro
5 min read
How to Search in Nano Editor?
The Nano editor is a command-line text editor widely used in Unix-like operating systems, including Linux and macOS. Despite its simplicity, it offers a powerful search functionality that allows users to quickly locate and navigate to specific text within a file. Mastering the search feature in Nano
6 min read
Best Text Editor for Kali Linux
Kali Linux is one of the most popular Linux distros, With a special focus on penetration testing and ethical hacking. It is especially popular among those who want to try their hand at ethical hacking. But just as with any other Linux distro, to make the best use of your operating system, you need t
8 min read
How to Save and Exit in Nano Editor in linux
Saving and exiting in the Nano text editor in Linux is a fundamental skill for anyone working with text files in the terminal. Nano is a user-friendly and straightforward text editor, making it an excellent choice for both beginners and experienced Linux users. Whether you're editing configuration f
5 min read
How to Copy in Nano Editor
Nano, a popular text editor in Unix-based systems, provides a user-friendly interface along with powerful features for efficient text editing. One of the fundamental operations in any text editor is copying and pasting text.Here, we will explore various methods of copying text within the Nano editor
4 min read