Editing with Nano
On this page
Your reading note says Status: draft, but you have completed the work. Replacing the whole file would also replace its title. You need to change the status and keep the rest.
By the end, you can open a file in Nano, move and search inside it, save an edit, and leave with a verified result.
Before you start
Section titled “Before you start”Finish Following a changing file (B07.2). Keep your existing B04 practice directory and the earlier B07 exercises.
Use only ~/lab/b07/nano. Run this setup once; use Reset this lesson before repeating it.
mkdir -p ~/lab/b07/nanocd ~/lab/b07/nanoprintf 'Reading notes\nStatus: draft\n' > notes.txtThe setup writes a disposable two-line note. Its printf and > pattern is the same one used to prepare files in B04. It does not change your original notes in ~/lab/Documents.
The screenshots use GNU nano 7.2 on the course’s Ubuntu 24.04.4 Desktop VM. Their keyboard steps use the default configuration, without launch options. If your shortcuts differ, read the labels shown in your own editor.
Open the file and read its controls
Section titled “Open the file and read its controls”nano notes.txtNano fills the terminal. While it is open, keys go to Nano rather than Bash. You do not need to start another shell to type file contents.

- The title bar names notes.txt; check that it is the intended file.
- The shortcut rows show ^O Write Out, ^W Where Is, and ^X Exit. The caret means Ctrl.
The title bar identifies the file. The editing area contains its text. The bottom rows show shortcuts for the current context. In those shortcuts, ^ means Ctrl: ^O is Ctrl+O, the letter O rather than zero.
These are the keys used here:
| Key | What it does in this exercise |
|---|---|
| Arrow keys | Move the cursor |
| Ctrl+A / Ctrl+E | Move to the beginning / end of the current line |
| Backspace | Remove the character before the cursor |
| Ctrl+W, text, Enter | Search for text |
| Ctrl+O, Enter | Write the file, accepting the displayed filename |
| Ctrl+X | Exit, asking about unsaved changes when needed |
You saw Ctrl+A and Ctrl+E in Bash’s Readline in B04.2. Nano also uses them for line movement, but these are Nano’s controls while it owns the terminal.
Add text without replacing the note
Section titled “Add text without replacing the note”Move to the first line with the arrow keys if necessary. Press Ctrl+E to reach its end, then type for B07, including the leading space.

- The added text is in Nano’s working copy.
- The asterisk marks unsaved changes.
Predict first: does the asterisk beside the filename mean the saved file already contains your edit?
Run it, then compare with your guess
No. You changed Nano’s buffer, its working copy of the text. The asterisk marks changes that have not been saved. The filename tells you the destination, not that a write has happened.
Do not type cat notes.txt into the editing area to check. Nano would insert those characters into the note. You will read the saved file from Bash after exiting.
Search before changing a value
Section titled “Search before changing a value”Press Ctrl+W. Type Status, then Enter. The search moves the cursor to that word:

- The cursor is at Status after Ctrl+W searches for that word.
Search is useful when a file is longer than the two lines used here. It finds the place to work; it does not replace the matched text.
On the status line, press Ctrl+E. Press Backspace five times to remove draft, leaving Status: . Type ready. The title remains Reading notes for B07; only the chosen value changes on the second line.
Save to the intended filename
Section titled “Save to the intended filename”Press Ctrl+O. Nano’s label Write Out means save the buffer to a file. It asks for a filename:

- File Name to Write asks where to save; notes.txt keeps the same destination.
- The intended status is ready before the save is confirmed.
Read that destination before accepting it. Here it is notes.txt, the disposable file you opened. Press Enter to write it. The prompt is part of Nano, not Bash; typing a shell command there would change the proposed filename.
Press Ctrl+X to exit. Because you saved the changes, Nano returns to Bash without asking you to save again. Check from the shell:
cat notes.txtReading notes for B07Status: ready
- After Nano exits, cat reads both saved lines from notes.txt.
- The shell prompt confirms that input is back with Bash.
This output is captured from the course VM after the edit. The title and status survived reopening through cat: they are in the file, not only on an editor screen.
Recognize the unsaved-exit question
Section titled “Recognize the unsaved-exit question”Reopen the same file:
nano notes.txtPress Ctrl+A on its first line and type TEMPORARY , including the space. Then press Ctrl+X without saving. This is a disposable test change, not part of the note you want to keep.

- Nano asks whether to save the modified buffer.
- N discards these unsaved edits; Ctrl+C cancels exit and returns to editing.
Read the choices. Y starts saving; N leaves without saving these edits; Ctrl+C cancels the exit so you can keep working. Here press N to discard only the temporary change.
cat notes.txtReading notes for B07Status: readyThe earlier saved version remains. Discarding a buffer change does not undo a save you already made. If you save unwanted text, leaving the editor afterward does not restore the old file.
Mistakes to recognize
Section titled “Mistakes to recognize”A misspelled filename can open an empty buffer. Opening an unused name is a normal way to create a file. An empty Nano screen is therefore not proof that your existing note was empty. Check the title and intended path before typing or saving.
Confusing Ctrl+O with Ctrl+0. The shortcut uses the letter O. Read Write Out on the bottom row rather than guessing from the shape of the character.
Assuming exit always saves. The modified-buffer question exists because saving and exiting are separate actions. Choose deliberately; N discards unsaved edits, while Ctrl+C keeps the editor open.
Try it yourself
Section titled “Try it yourself”Goal: Mark a separate handoff as checked while preserving the saved source note.
cp notes.txt handoff.txtnano handoff.txtChange only the handoff’s ready value to checked, using a search to find it. Save and exit, then verify the handoff from Bash. Keep notes.txt as it is.
Expected: The handoff keeps the title and says Status: checked; the source note still says Status: ready.
Hint
Search for ready, move to the end of its line, and remove its five letters. The filename-to-write prompt should name handoff.txt.
Solution
- Ctrl+W, type
ready, Enter. - Ctrl+E, Backspace five times, type
checked. - Ctrl+O, Enter, Ctrl+X.
cat handoff.txtReading notes for B07Status: checkedcat notes.txtReading notes for B07Status: readyYou edited an independent copy. Nothing in those editor steps changed the source path.
Reset this lesson
Section titled “Reset this lesson”Exit Nano first, saving or discarding changes deliberately. Then inspect this lesson’s directory from its parent:
cd ~/lab/b07ls -AR nanoAfter the challenge it contains notes.txt and handoff.txt.
rm -r ~/lab/b07/nanoRerun Before you start to restore the draft note. If the directory is absent, skip removal. Restoring the fixture deliberately replaces this lesson’s saved edits, not your other notes.
- Nano’s bottom rows show shortcuts;
^means Ctrl. - Typing changes the buffer. An asterisk indicates unsaved changes.
- Search locates text; it does not replace it.
- Ctrl+O writes to the chosen filename; Ctrl+X exits. Read the unsaved-exit question before answering.
- After exiting,
catverifies what was saved.
Next, Editing with Vim introduces an editor whose typing keys depend on its mode.
Further reading
Section titled “Further reading”- On your system:
man nanoand Nano’s Ctrl+G help screen. - GNU nano 7.2 manual, especially Editor Basics, Screen Layout, Commands, and Search and Replace.