nano is the editor for people who just need to change a line and get on with their day. It opens the file, shows its most important shortcuts at the bottom of the screen, and lets you type straight away, with no modes to learn.
That friendliness hides most of what it can do. The shortcut bar shows the basics; several of the keys that matter for real config work, such as moving a block, cutting to the end of a file and counting lines, are not on it. This page is a practice session: you build one realistic config file and work through twelve exercises on it, from saving and quitting to search and replace and undoing mistakes.
At the end, one diff tells you whether every exercise went right. The file and the twelve tasks are identical to the vi practice walk-through, so you can learn both editors on the same ground. Every keystroke here was run against nano 7.2 and the result compared byte for byte.
Applies to: nano 7 and later on any Linux distribution; the keys that changed in nano 8 are called out where they matter
Quick answer
Open a file with nano filename and start typing. These are the keys you need to finish the job:
| You want to | Press |
|---|---|
| Save | Ctrl+O, then Enter to accept the file name |
| Quit | Ctrl+X |
| Quit without saving | Ctrl+X, then N at the prompt |
| Search | Ctrl+W |
| Undo the last change | Alt+U |
What is on the nano screen
Everything you need to read is in four places, and exercise after exercise uses them the same way: you press a key, the status line asks you something or reports what happened, and the shortcut rows change to show the answers you can give.
In the shortcut rows ^ means hold Ctrl, and M- means hold Alt. So ^X is Ctrl+X and M-U is Alt+U. When nano asks a question, the bottom rows change to the possible answers, such as Y Yes, N No and ^C Cancel, and Ctrl+C cancels any question.
Before the first exercise
Four things set up the practice session. Each takes one command.
One. Check your nano version. It decides whether Ctrl+F searches or just moves the cursor, so it is worth knowing before you start.
nano --version | head -1
GNU nano, version 7.2
That is Ubuntu 24.04, and every exercise here was run on it. Where nano 8 and later use different keys, the page says so. If the command is not found, install it with sudo apt install nano or sudo dnf install nano.
Two. Make a folder so nothing you do touches a real system file.
mkdir -p ~/editor-practice && cd ~/editor-practice
Three. Create the practice file. Paste the whole block into your terminal at once: it writes a small web server config with deliberate problems in it, a typo, a duplicate line and settings that need changing. If you already did the vi walk-through, run it again anyway to start from a clean copy.
mkdir -p ~/editor-practice && cd ~/editor-practice
cat > practice.conf <<'EOF'
# web01 site configuration - practice file for vi and nano
# Owner: ops-team Reviewed: 2026-01-15
server_name web01.example.local;
listen 8080;
root /var/www/html;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# Backend pool
backend app01.example.local:8080;
backend app02.example.local:8080;
backend app03.example.local:8080;
backend app03.example.local:8080;
# Maintenance contacts
contact alice@example.local;
contact bob@exmaple.local;
contact carol@example.local;
# Deprecated - remove before go-live
debug_mode on;
legacy_tls TLSv1.0;
EOF
wc -l practice.conf
23 practice.conf
Four. Open files with line numbers from now on. The exercises refer to lines by number, and -l shows them in a margin that is never saved into the file:
nano -l practice.conf
-l. The emergency exit, whatever state you are in, is Ctrl+C to cancel any question, then Ctrl+X and N to leave without saving.
Twelve exercises
Do them in order. Each one starts from where the previous one finished, and exercise 12 saves the result that the final comparison checks.
1. Open a file and get out without changing it
The task: look at a config file and leave.
Ctrl+X nothing changed, so nano exits straight away
Now the case that confuses people. Open the file again with nano -l practice.conf, press Ctrl+K once (it cuts the line the cursor is on), then press Ctrl+X. This time nano asks:
Save modified buffer?
Y Yes
N No ^C Cancel
Y saves, N throws the change away and quits, Ctrl+C goes back to editing. Press N and check the file is untouched:
wc -l practice.conf # still 23 lines
2. Create a new file, type in it, save and quit
The task: write a short note from scratch. Naming a file that does not exist yet is how you create it.
nano notes.txt
The status line shows [ New File ]. Type three lines, then save and leave:
(type) Server web01 rebuilt on 2026-09-24
Owner: ops-team
Next review: 2026-12-01
Ctrl+O Write Out; the status line shows: File Name to Write: notes.txt
Enter accept the name
Ctrl+X exit
[ Wrote 3 lines ]
cat notes.txt
Save modified buffer?, and Y leads to the same File Name to Write: prompt. Both paths produce the identical file.
3. Move around the practice file
The task: jump straight to a line, to the end and back to the top.
nano -l practice.conf
Ctrl+/ 18 Enter go to line 18 (bob's address)
Alt+/ go to the end of the file
Alt+\ go to the first line
The shortcut bar labels Go To Line ^/. On many terminals Ctrl+_ sends the same code, and Alt+G is the alternative the help screen lists, useful if neither of the first two does anything. You can also open the file at a line from the shell: nano -l +18 practice.conf.
To see where you are, press Ctrl+C:
[ line 18/24 (75%), col 1/33 ( 3%), char 506/653 (77%) ]
The file has 23 lines, and nano says 24. It counts the empty line below the last line of text as a line of its own: Alt+/ takes you there, and Ctrl+C then reports line 24/24. Alt+D, which counts lines, words and characters, reports [ 23 lines, 89 words, 653 characters ], matching wc -l.
4. Fix a typo
The task: bob’s address on line 18 says exmaple. Fix it.
Ctrl+/ 18 Enter go to line 18
Ctrl+W exmaple Enter search; the cursor lands on the first letter of the match
Delete (7 times) remove the seven letters of exmaple
example type the correct word
There is no mode to leave: in nano what you type is always text, and the Delete and Backspace keys work as they do everywhere else. The title bar now says Modified.
5. Delete a line
The task: lines 13 and 14 both list app03. Remove the duplicate.
Ctrl+/ 14 Enter go to line 14
Ctrl+K cut the whole line
nano calls it Cut rather than Delete because the line goes into the cutbuffer, from where Ctrl+U can paste it back. Exercise 9 builds on that.
6. Copy a line and change the copy
The task: add a fourth backend, app04, by copying the app03 line instead of typing it.
Ctrl+/ 13 Enter go to the app03 line
Alt+6 copy the line; the cursor moves to the next line
Ctrl+U paste: the copy appears as line 14
Up move onto the copy
Ctrl+W app03 Enter the cursor lands on app03 in this line
Right (4 times) move onto the 3
Delete, then 4 replace the 3 with a 4
Alt+6 copies without removing, Ctrl+K cuts. Both put the text in the same cutbuffer, and Ctrl+U pastes whatever is there, as many times as you like.
7. Search forward, backward and for the next match
The task: find a setting without scrolling for it.
Ctrl+W access_log Enter search forward
Alt+W next match forward
Ctrl+Q TLS Enter search backward (nano 8 and later document Ctrl+B)
There is only one access_log, so Alt+W cannot find another and says so:
[ This is the only occurrence ]
The backward search for TLS starts above the only match, runs off the top of the file and continues from the bottom:
[ Search Wrapped ]
Neither is an error. A search that finds nothing reports it plainly, for example [ "nginx.pid" not found ]. In nano 7, Alt+Q finds the next match backward, the reverse of Alt+W; nano 8 and later document Alt+F and Alt+B for next forward and backward.
8. Replace one occurrence, then replace all
The task, part one: the site moves to port 8443. Change the listen line, but not the four backend lines, which also contain 8080 and must stay on 8080.
Alt+\ go to the top: replace starts from the cursor
Ctrl+\ Replace; the status line asks: Search (to replace):
8080 Enter what to find; the status line asks: Replace with:
8443 Enter what to put instead
Y the first match is the listen line: yes
Ctrl+C stop before touching the backends
At each match nano highlights it and asks:
Replace this instance?
Y Yes A All
N No ^C Cancel
[ Replaced 1 occurrence ]
The task, part two: the domain changes from example.local to corp.local everywhere.
Alt+\ top of the file
Ctrl+\ example.local Enter what to find
corp.local Enter what to put instead
A All: replace this one and every other
[ Replaced 8 occurrences ]
nano treats the dot in example.local as a plain dot. The prompt shows M-R Reg.exp. as a toggle: only when regular expressions are switched on does a dot mean any character, which is the default in vi and the reason the vi walk-through escapes it.
9. Move a block of lines
The task: the team wants the contact list at the top of the file. Move the # Maintenance contacts block, its three lines and the blank line under it, to just below the header.
Ctrl+/ 16 Enter go to the '# Maintenance contacts' line
Ctrl+K (5 times) cut five lines in a row
Ctrl+/ 4 Enter go to line 4, just under the header's blank line
Ctrl+U paste all five
This works because of one rule in the nano manual: “Consecutive strokes of ^K add each cut line to this buffer, but a ^K after any other keystroke overwrites the entire cutbuffer.”
For a region that is not whole lines, set a mark with Alt+A, move the cursor to the other end, and Ctrl+K cuts exactly what is highlighted.
10. Delete everything to the end of the file
The task: the # Deprecated section at the bottom must go before go-live. Remove it, together with the blank line above it.
Ctrl+/ 20 Enter go to the blank line above '# Deprecated'
Alt+T cut from the cursor to the end of the file
Alt+T is in the full help screen, Ctrl+G, but not on the shortcut bar. It saves pressing Ctrl+K four times and counting.
11. Undo and redo
The task: make a mistake on purpose and take it back.
Up move to the last line of text
Ctrl+K cut it, the mistake
Alt+U undo: the line comes back
Alt+E redo: the line is cut again
Alt+U undo again: the line is back, and the file is correct
[ Undid cut ]
[ Redid cut ]
nano names what it undid, so you can see which change each press reverses. It keeps undoing further back with every Alt+U.
12. Save, save a copy, and quit
The task: save your work, keep a copy of it, and leave. This exercise has a trap in it on purpose.
Ctrl+O Enter save practice.conf
[ Wrote 19 lines ]
Now the copy. Ctrl+O again, and at the File Name to Write: prompt type .bak at the end of the name, then Enter. nano checks you meant it:
Save file under DIFFERENT NAME?
Y Yes
Press Y. The file is written, and then look at the title bar: it now says practice.conf.bak. From here on you are editing the copy, and the next Ctrl+O would save to the copy, not to practice.conf. Press Ctrl+X to leave.
cp practice.conf practice.conf.bak first, then edit the original. vi behaves the other way round: :w copy writes the copy and keeps you on the original.
Check your work
This block writes what practice.conf should look like after all twelve exercises and compares it with yours. Paste it into the shell, in the practice folder:
cat > expected.conf <<'EOF'
# web01 site configuration - practice file for vi and nano
# Owner: ops-team Reviewed: 2026-01-15
# Maintenance contacts
contact alice@corp.local;
contact bob@corp.local;
contact carol@corp.local;
server_name web01.corp.local;
listen 8443;
root /var/www/html;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# Backend pool
backend app01.corp.local:8080;
backend app02.corp.local:8080;
backend app03.corp.local:8080;
backend app04.corp.local:8080;
EOF
diff -u expected.conf practice.conf && echo "All twelve exercises done correctly"
All twelve exercises done correctly
diff prints nothing when the two files are identical, and the message only appears when it succeeds. If anything differs, it prints the differing lines instead. A - line is what the answer expects, a + line is what your file has. This is the output when exercise 8 replaced every 8080 instead of only the listen port, which is what pressing A instead of Y at the first prompt does:
--- expected.conf
+++ practice.conf
@@ -13,7 +13,7 @@
error_log /var/log/nginx/error.log;
# Backend pool
-backend app01.corp.local:8080;
-backend app02.corp.local:8080;
-backend app03.corp.local:8080;
-backend app04.corp.local:8080;
+backend app01.corp.local:8443;
+backend app02.corp.local:8443;
+backend app03.corp.local:8443;
+backend app04.corp.local:8443;
Read it as: the backends should still say 8080, yours say 8443. Open the file, fix the four lines, save, and run the diff line again until it prints the message. For a one-line check, the SHA-256 of a correct file is:
sha256sum practice.conf
5416913f3944c95556a29f2fc87acd0c8ba2ec61c168d0783678473bea451343 practice.conf
To practise again from the start, re-run step three of the setup and you have a fresh file.
nano 7 and nano 8: the keys that changed
nano 8.0, released in May 2024, changed two default keys. Its release notes say: “By default ^F is bound to starting a forward search, and ^B to starting a backward search, while M-F and M-B repeat the search in the corresponding direction.”
In nano 7.2, the version Ubuntu 24.04 ships, the built-in help lists the same two keys as ^F Go forward one character and ^B Go back one character. The official cheatsheet on the nano website tracks the latest release and lists Ctrl+F for search, so on a nano 7 system following it moves the cursor one place right and nothing else happens.
| Job | nano 7 | nano 8 and later |
|---|---|---|
| Search forward | Ctrl+W | Ctrl+W or Ctrl+F |
| Search backward | Ctrl+Q | Ctrl+B |
| Next match forward, backward | Alt+W, Alt+Q | Alt+F, Alt+B |
| Go to line | Ctrl+/ or Alt+G | Alt+G |
| Replace | Ctrl+\ or Alt+R | Alt+R |
Ctrl+W is the key to remember: the current manual on the nano website, which describes nano 9.2, still says the search command is ^F or ^W. Exercise 7’s backward search and next-match keys are the nano 7 ones; on nano 8 and later use the right-hand column. nano 8 also has an opt-in --modernbindings option that switches to Windows-style keys such as Ctrl+C to copy and Ctrl+V to paste; it is off unless you ask for it.
Files you are not allowed to write
Real config files live under /etc and belong to root. Open one as a normal user and nano warns you straight away on the status line:
[ File '/etc/nginx/nginx.conf' is unwritable ]
It still lets you edit, which is the trap. The failure only comes when you save:
[ Error writing /etc/nginx/nginx.conf: Permission denied ]
Both messages were produced by opening a root-owned file as an unprivileged user, with the file name changed here to a realistic one. Start with the right permissions instead:
# edits a temporary copy as you, then writes it back as root when you quit
sudoedit /etc/nginx/nginx.conf
# or run the editor itself as root
sudo nano /etc/nginx/nginx.conf
If you are already stuck with unsaved changes, this is where exercise 12’s behaviour helps: Ctrl+O, change the name to /tmp/nginx.conf.new, Enter, Y. Your work is safe in /tmp; then Ctrl+X and copy it into place:
sudo cp /tmp/nginx.conf.new /etc/nginx/nginx.conf
Hidden gems
When Ctrl or Alt shortcuts do not reach nano, use Esc. Some remote consoles and web terminals intercept Alt or Ctrl combinations before nano sees them. The manual: “A control-key sequence is generated by pressing the Esc key twice and then pressing the desired key, and a meta-key sequence by pressing the Esc key once and then pressing the desired key.” So Esc Esc K is Ctrl+K, and Esc U is Alt+U.
Let nano keep a backup for you. Start it with -B and every save first keeps the previous version, “using the current filename suffixed with a tilde”. Editing practice.conf with nano -B leaves practice.conf~ next to it.
Count before and after. Alt+D counts the lines, words and characters of the file, or of the marked region if one is set. It is a quick way to confirm a block move did not lose a line.
The full list is one key away. Ctrl+G opens the complete help, with every function and its alternative keys, on the version you are actually running. When a website and your nano disagree, the help screen is right.
The same twelve tasks in vi
The vi walk-through uses the identical practice file and the identical answer, so you can compare the two editors key for key:
| Task | nano | vi |
|---|---|---|
| Save | Ctrl+O then Enter | :w |
| Quit, discarding changes | Ctrl+X then N | :q! |
| Go to line 18 | Ctrl+/, 18, Enter | 18G |
| Search | Ctrl+W | /text |
| Replace everywhere | Ctrl+\, then A for All | :%s/old/new/g |
| Delete a line | Ctrl+K | dd |
| Copy a line | Alt+6 | yy |
| Paste | Ctrl+U | p |
| Undo, redo | Alt+U, Alt+E | u, Ctrl+R |
| Save a copy | Ctrl+O with a new name, switches to the copy | :w copy, keeps editing the original |
The difference that matters most is modes. In nano every key you type is text unless you hold Ctrl or Alt. In vi most keys are commands until you press i. Learn nano first if you are new to the terminal; learn vi as well, because it is the editor you will often find on minimal systems and on ESXi hosts.
Where this matters
A quick fix on a server you just connected to. sudo nano +42 /etc/ssh/sshd_config, change the line, Ctrl+O, Ctrl+X. The connecting to a Linux server from Windows article covers getting to that prompt from Windows.
The default editor on Ubuntu. On Ubuntu 24.04 the system-wide editor command points to nano, and the sensible-editor helper, when VISUAL and EDITOR are not set, may ask you once to pick an editor and otherwise falls back to editor, nano and finally vi. Commands that open an editor for you can therefore land in nano; exercises 2 and 12 are exactly that workflow. Check yours with update-alternatives --display editor.
Changing a value across a config. A new hostname, port or IP address on every line is exercise 8, part two, and Replace this instance? shows you each change before it happens when you are not sure.
Handing a server to someone who does not know vi. The shortcut bar makes nano usable on the first try, which makes it the safer editor to name in a runbook written for a colleague.
Tips and limitations
- Ctrl+C cancels any question nano is asking. It is the key to press when you are not sure what the status line wants.
- Ctrl+W searches in nano 7 and 8. Ctrl+F only searches from nano 8.0; before that it moves the cursor one character.
- Replace starts at the cursor and wraps around the end. Go to the top with Alt+\ first if the order of the prompts matters.
- Consecutive Ctrl+K presses collect lines in one cutbuffer. Any other key in between starts a new cutbuffer and overwrites the old one.
- Saving under a different name switches nano to the new file. Make backups with
cpbefore you edit, or withnano -B. - nano opens a file you cannot write without complaint beyond a status line note. The error arrives only when you save.
- Line numbers from
-lor Alt+N are display only; they are never written into the file. - If a shortcut does nothing, check Ctrl+G: keys differ between versions, and the help screen shows the ones that are really active.
Official documentation
- The GNU nano text editor: the full manual
- nano(1): command-line options
- Cheatsheet for GNU nano: tracks the latest release
- nano release notes, including the 8.0 key changes
Related tools
- Port Checker: exercise 8 moves a listen port from 8080 to 8443; on a real server the next step is checking that the new port answers.
Related guides
- vi editor tutorial: a hands-on practice walk-through: the same practice file and the same twelve exercises in the editor most often found on minimal systems.
- Connecting to a Linux server from Windows: getting to the prompt where you will actually use nano.
- Linux commands cheat sheet: the index of the Linux cluster, including how to install a missing tool.
- Linux for Windows admins cheat sheet: Windows habits translated, including the package commands that install nano.
Five cheat sheets, one PDF
Subnet masks, PowerShell, Linux commands, HTTP status codes and the ESXi command line - one page each, free to keep. Leave an address and it arrives in a minute.