How to use the nano editor
nano is a command-line text editor preinstalled on many Linux distributions. It's easy to use and suitable for quickly editing server configuration files.
Installing nano
On many systems, nano is installed by default. If it's not installed, install it:
# Debian/Ubuntu sudo apt update && sudo apt install -y nano # CentOS/RHEL/AlmaLinux/Rocky sudo yum install -y nano # or sudo dnf install -y nano Code language: PHP ( php )Launch and create a file
Open an existing file or create a new one:
nano /etc/nginx/nginx.conf nano myfile.txtIf the file does not exist, nano will create it when saving.
Symbols in tooltips
Hotkeys are shown at the bottom of the nano window. The ^ represents the Ctrl . For example, ^X = Ctrl+X . The M- typically stands for Alt (Meta).
Basic hotkeys
| Action | Combination |
| Save file | Ctrl+O |
| Exit nano | Ctrl+X |
| Undo operation / display cursor position | Ctrl+C |
| Reference | Ctrl+G |
| Search | Ctrl+W |
| Replace (Search and Replace) | Ctrl+\ |
| Cut a line | Ctrl+K |
| Paste (insert previously cut) | Ctrl+U |
| Mark (start selecting) | Ctrl+^ |
| Go to row/column | Ctrl+_ (then enter the number) |
| To the beginning of the line / to the end of the line | Ctrl+A / Ctrl+E |
| Page up / down | Ctrl+Y / Ctrl+V |
Save and exit
- Save:
Ctrl+O, thenEnter - Exit:
Ctrl+X - If there are unsaved changes, nano will ask whether to save the file: press
Y(Yes) orN(No)
Search and replace
- Search:
Ctrl+W, enter the string and pressEnter - Search further:
Alt+WCtrl+Wagain →Enter - Replace:
Ctrl+\- enter the search text, then the replacement text, confirm withY/A(Yes / All)
Cut, copy, paste
- Cut line:
Ctrl+K - Paste:
Ctrl+U - Select a block:
Ctrl+^(hold and move the cursor with the arrow keys), thenCtrl+K/Ctrl+U
Line numbering and other settings
Create (or edit) the ~/.nanorc to enable useful options. For example:
nano ~/.nanorcAdd the following lines:
set linenumbers # show line numbers set tabsize 4 # tab size set softwrap # wrap long lines set mouse # allow mouse use in terminal set historylog # save search history Code language: JavaScript ( javascript )Alternatively, you can enable line numbers at startup:
nano -l file .txt Code language: CSS ( css )Editing files with root privileges
If the file is owned by root, open it with sudo :
sudo nano /etc/hostsOr use sudo -e (uses the default editor, which can be set via the EDITOR ):
sudo EDITOR=nano -e /etc/hostsUseful launch arguments
| Option | Description |
-l | Show line numbers |
-c | Show cursor position |
-m | Enable mouse support |
-i | Auto-indents |
-E | Show tab characters |
Frequently asked questions
You don't have write permissions to the file. Open the file with sudo, or save it under a different name, and then move the file with the correct permissions.
Press Ctrl+_, enter the line number and press Enter.
In new versions of nano, it's enabled by default for popular languages. You can also enable additional rules in ~/.nanorc.