Complete Guide to Nano Editor in Ubuntu Linux (Beginner to Advanced)
The Nano Editor is one of the most popular and beginner-friendly text editors in Linux, especially on Ubuntu systems. If you are new to Linux or frequently work with configuration files, learning Nano is an essential skill.
This complete guide explains everything about Nano Editor, including installation, file editing, navigation, shortcuts, search and replace, syntax highlighting, configuration, and advanced usage.
What is Nano Editor?
Nano is a terminal-based text editor designed to be simple and easy to use. Unlike Vim or Emacs, Nano does not require memorizing complex commands. All important shortcuts are displayed at the bottom of the screen.
Key Features of Nano Editor
- Simple and intuitive interface
- Beginner-friendly keyboard shortcuts
- Lightweight and fast
- Syntax highlighting support
- Ideal for editing system and configuration files
Checking Nano Installation in Ubuntu
Most Ubuntu versions come with Nano pre-installed. You can verify this by running:
nano --version
If Nano is installed, the version details will appear.
Installing Nano Editor (If Not Installed)
sudo apt update sudo apt install nano
How to use Nano editor in Ubuntu Linux - Opening and Creating Files Using Nano
To open a file in Nano, use the following command:
nano filename.txt
If the file exists, Nano opens it. If it does not exist, Nano creates a new file with that name.
Opening Files with Root Permission
For system configuration files, use:
sudo nano /etc/filename.conf
Understanding the Nano Interface
The Nano editor screen is divided into three main sections:
- Top Bar: Shows Nano version and file name
- Main Area: Where you edit text
- Bottom Bar: Displays shortcut commands
The ^ symbol represents the Ctrl key. For example, ^X means Ctrl + X.
Basic Navigation in Nano
Cursor Movement
- Arrow Keys – Move cursor
- Ctrl + A – Move to start of line
- Ctrl + E – Move to end of line
- Ctrl + Y – Page up
- Ctrl + V – Page down
Jumping Within File
- Ctrl + _ – Go to specific line number
- Ctrl + C – Show current cursor position
Saving and Exiting Nano Editor
Saving a File
- Press Ctrl + O
- Press Enter to confirm filename
Exiting Nano
- Press Ctrl + X
Exit Without Saving
- Ctrl + X
- Press N when prompted
Cut, Copy, and Paste in Nano
Cut Text
- Ctrl + K – Cut current line
Paste Text
- Ctrl + U – Paste cut text
Selecting Text
- Ctrl + ^ – Start text selection
- Use arrow keys to select
Search and Replace in Nano
Searching Text
- Ctrl + W
- Type search term and press Enter
Replacing Text
- Ctrl + \
- Enter search text
- Enter replacement text
- Press Y to replace or A to replace all
Undo and Redo in Nano
- Alt + U – Undo
- Alt + E – Redo
Syntax Highlighting in Nano
Syntax highlighting makes code and configuration files easier to read.
Temporary Syntax Highlighting
Nano automatically highlights files like:
- .sh
- .conf
- .py
Enable Syntax Highlighting Permanently
nano ~/.nanorc
Add the following line:
include /usr/share/nano/*.nanorc
Save and exit Nano.
Line Numbers in Nano
Enable Line Numbers Temporarily
- Alt + Shift + #
Enable Line Numbers Permanently
Edit Nano config:
nano ~/.nanorc
Add:
set linenumbers
Backing Up Files Automatically
To enable backup files when saving:
set backup
Backup files will be saved with a tilde (~).
Commonly Used Nano Shortcuts
- Ctrl + G – Help
- Ctrl + O – Save
- Ctrl + X – Exit
- Ctrl + W – Search
- Ctrl + K – Cut
- Ctrl + U – Paste
- Ctrl + C – Cursor position
When to Use Nano Editor
Nano is best suited for:
- Beginners learning Linux
- Editing configuration files
- Quick terminal-based edits
- Server and SSH environments
Conclusion
The Nano Editor is a powerful yet simple text editor that every Ubuntu Linux user should learn. Whether you are editing system configuration files or writing scripts, Nano provides a clean and stress-free editing experience.
Mastering Nano will significantly improve your productivity and confidence while working in the Linux terminal.
