Quick take: The nano editor is the easiest terminal text editor. Open a file with nano file, edit normally, then save with Ctrl+O and exit with Ctrl+X. The shortcut bar at the bottom shows the keys (^ means Ctrl).
Introduction
The nano editor is the friendliest way to edit files in the terminal, which is why it is the default on Ubuntu and many other distributions. Unlike Vim, it works the way most people expect — you just start typing — and it shows the key shortcuts along the bottom of the screen.
This guide covers opening and saving files, the essential shortcuts, searching and replacing, and the options that make nano nicer for editing config files.
Syntax
The basic syntax of the nano command is:
nano [OPTIONS] [FILE]Common Options and Parameters
The most useful options and parameters for the nano command:
| Option | Description |
|---|---|
| Ctrl+O | Write Out — save the file. |
| Ctrl+X | Exit nano (prompts to save if needed). |
| Ctrl+W | Where Is — search for text. |
| Ctrl+\ | Search and replace. |
| Ctrl+K / Ctrl+U | Cut and paste (uncut) a line. |
| Ctrl+G | Open the help screen. |
| Ctrl+_ | Go to a specific line number. |
| -l | Show line numbers. |
| -w | Disable line wrapping (important for config files). |
Practical Examples
Real nano commands you can run today:
# Open or create a file
nano notes.txt
# Open a system file with sudo
sudo nano /etc/hosts
# Open with line numbers shown
nano -l script.sh
# Open without line wrapping (for config files)
nano -w /etc/nginx/nginx.conf
# Open at a specific line
nano +25 app.pyConfiguring nano with nanorc
nano is more capable than its simple interface suggests, and a short configuration file makes it markedly nicer for editing code and config. Settings live in ~/.nanorc for your user (or /etc/nanorc system-wide).
# ~/.nanorc
set linenumbers # show line numbers
set tabstospaces # insert spaces, not tabs
set tabsize 4
set constantshow # always show the cursor position
include "/usr/share/nano/*.nanorc" # enable syntax highlightingThat last line turns on syntax highlighting for dozens of languages and config formats, which makes spotting a misplaced bracket or quote far easier — a real upgrade for editing files like nginx.conf or YAML.
Tips and Best Practices
- The
^in the bottom bar means the Ctrl key — so^Xis Ctrl+X to exit. - Use
-wwhen editing configuration files so long lines are not wrapped and accidentally broken. - If you save a file and the program does not see the change, make sure you edited the right path — use
sudo nanofor files you do not own.
Final Thoughts
nano is the editor to reach for when you want to make a quick change without a learning curve. Remember just two shortcuts — Ctrl+O to save and Ctrl+X to exit — and the rest is plain typing. It is perfect for editing config files and notes; when you need more power, that is when people graduate to Vim.
FAQ: nano Command in Linux
How do I save and exit in nano?+
Press Ctrl+O then Enter to save (Write Out), and Ctrl+X to exit. If you try to exit with unsaved changes, nano asks whether to save first.
What does the ^ symbol mean in nano?+
The caret ^ stands for the Ctrl key. So ^O in the shortcut bar means Ctrl+O, and ^X means Ctrl+X.
How do I search in nano?+
Press Ctrl+W (Where Is), type your text, and press Enter. Press Ctrl+W then Enter again to jump to the next match. Use Ctrl+\ for search and replace.
How do I edit a system file with nano?+
Use sudo: sudo nano /etc/hosts opens the file with the privileges needed to save changes to system locations.
How do I show line numbers in nano?+
Start nano with -l (nano -l file), or toggle them while editing with Alt+Shift+3 (Esc then #). Line numbers help when following error messages.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support