Edit files in the terminal with nano

The beginner-friendly terminal editor: open, edit, save and exit a file with on-screen shortcuts.

LinuxFilesnanoTerminaleditLow risk
Run nano /etc/hosts, edit the text, then press Ctrl+O and Enter to save and Ctrl+X to exit — every shortcut is listed at the bottom of the screen.

01Command

Command
$ nano /etc/hosts

02What it does

nano shows its key bindings on screen at all times, which makes it the go-to editor for quick config fixes. Ctrl+K cuts a line and Ctrl+U pastes it, Ctrl+W searches, and Ctrl+_ (or Alt+G) jumps to a line number — handy when a log or compiler error names one. Add -w for files where line wrapping would corrupt the layout, and -l to show line numbers.

03Risk

RiskLow risk
Requirementsnano installed (default editor on most distros).
!Warning: For system files run it with sudo (sudo nano /etc/hosts) or you will edit a copy you cannot save over the original. nano may hard-wrap long lines by default; use -w when editing configs or you may break a single-line directive. If sudoedit is available it is safer than sudo nano for admin files.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • nano(1) - a small, friendly text editor
    Ubuntu Manpages · community · 2026-09-17
    Evidence: nano edits files with on-screen key hints; ^O writes out, ^X exits, -w disables wrapping (important for config files).
  • GNU nano documentation
    nano-editor.org · community · 2026-09-17
    Evidence: Official nano manual covering shortcuts, ^K/^U cut-paste, ^W search and syntax highlighting configuration.

Last verified: 2026-09-18 · Category: Developer

06Related solutions