How to edit files with nano

Overview

Nano is a terminal text editor installed by default on many Ubuntu and Debian systems. Its shortcut reminders appear at the bottom; ^ means the Ctrl key.

Open, edit, and save

Open a file, type normally, then save with Ctrl+O. Confirm the filename with Enter and exit with Ctrl+X.

nano notes.txt
nano +25 notes.txt

Useful shortcuts

  • Ctrl+W searches
  • Alt+W repeats the search
  • Ctrl+K cuts a line
  • Ctrl+U pastes
  • Ctrl+G opens help
  • Ctrl+C shows cursor position

Tips and safety

Nano asks whether to save modified text when you exit. Read the prompt rather than pressing keys quickly.

Avoid running sudo nano on files in your home directory. For system configuration, make a backup and understand the specific change first.