AI Hints
Home›Linux Tutorial›Writing Files
Linux · Lesson 36 of 120

Editing with nano

A simple terminal editor.

⏱ 2 min read▶ Video at 45:04🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

Echo is fine for one line. But to really edit a file, moving around, fixing typos, adding paragraphs, you need a text editor. The friendliest one in the terminal is called nano.

Editing with nano
From the video: Editing with nano
  • Echo is fine for one line
  • Real editing needs an editor
  • nano is the friendliest

Opening nano

Type nano, followed by a file name. If the file exists, nano opens it. If not, nano starts a new, empty file with that name. The file fills the window, and you can type straight away, just like in any editor. At the bottom, nano lists its shortcuts.

nano notes.txtopen or create
Typeedit straight away
Arrow keysmove the cursor
Bottom barthe shortcuts

Editing a shopping list

Here's notes dot TXT open in nano. We move down with the arrow keys, and fix the second line. Then we add a new item at the end. The caret symbol at the bottom means the control key.

nano notes.txttext
Buy milk
Call Mum and Dad
Learn Linux
Book dentist


^O Write Out   ^X Exit   ^W Where Is   ^K Cut   ^U Paste

The keys you need

You only need a few keys to use nano well. Control O writes out, which means save. Nano asks for the file name, and you press Enter. Control X exits. If there are unsaved changes, it asks if you want to save them. Control W searches. And control K cuts a line, while control U pastes it.

KeysDoes
Ctrl + O, Entersave
Ctrl + Xexit
Ctrl + Wsearch
Ctrl + K / Ctrl + Ucut / paste a line

Summary

Nano edits files in the terminal. Control O saves, control X exits. Next, finding out what kind of file something is.

Key takeaways
  • nano <file>
  • Ctrl+O saves
  • Ctrl+X exits
Next up: file and stat — what is this file?