nano Basics

You're SSH'd into a server. You need to edit a config file. No VS Code, no GUI. This is where terminal editors shine.

nano is the beginner-friendly choice. It shows you what to do at the bottom of the screen.

Open a File

Terminal
$nano filename.txt
(opens file in nano)

If the file doesn't exist, nano creates it when you save.

Terminal
$nano /etc/hosts
(opens system file - may need sudo)
$sudo nano /etc/hosts
(opens with write permission)

The nano Interface

  GNU nano 6.2                 /etc/hosts

127.0.0.1       localhost
127.0.1.1       mycomputer

# The following lines are desirable for IPv6
::1     ip6-localhost ip6-loopback


^G Help    ^O Write Out ^W Where Is  ^K Cut       ^U Paste
^X Exit    ^R Read File ^\ Replace   ^J Justify   ^T Spell

The bottom two lines show keyboard shortcuts. ^ means Ctrl.

Essential Shortcuts

ShortcutAction
Ctrl+OSave (Write Out)
Ctrl+XExit
Ctrl+KCut line
Ctrl+UPaste
Ctrl+WSearch
Ctrl+GHelp

Save and Exit

Terminal
$# After editing, press:
$Ctrl+O
File Name to Write: filename.txt
$Enter
(confirms filename, saves)
$Ctrl+X
(exits nano)

Or save and exit in one go:

  • Press Ctrl+X
  • nano asks "Save modified buffer?"
  • Press Y (yes)
  • Confirm filename with Enter

Editing Text

Just type. nano works like any normal editor. Arrow keys move the cursor.

Terminal
$# Navigation
$Arrow keys
Move cursor
$Ctrl+A
Beginning of line
$Ctrl+E
End of line
$Ctrl+Y
Page up
$Ctrl+V
Page down

Search and Replace

Terminal
$Ctrl+W
Search:
$# Type search term, press Enter
$Ctrl+W then Enter
(find next occurrence)

Search and Replace

Terminal
$Ctrl+\
Search (to replace):
$# Type search term
$Enter
Replace with:
$# Type replacement
$A
(replace All)

Cut, Copy, Paste

Terminal
$Ctrl+K
(cut current line)
$Ctrl+U
(paste)
$
$# To cut multiple lines:
$Ctrl+K Ctrl+K Ctrl+K
(cut 3 lines)
$Ctrl+U
(paste all 3)

Copy Without Cutting

Terminal
$Alt+6
(copy line)
$Ctrl+U
(paste)

nano Is Always Available

nano is installed on virtually every Linux system. When you can't remember vim commands or the server doesn't have your favorite editor, nano is there.

Go to Line Number

Terminal
$Ctrl+_
Enter line number:
$50
(jumps to line 50)

Or open directly at a line:

Terminal
$nano +50 filename.txt
(opens at line 50)
Knowledge Check

How do you save a file in nano?

Quick Reference

ShortcutAction
Ctrl+OSave
Ctrl+XExit
Ctrl+KCut line
Ctrl+UPaste
Ctrl+WSearch
Ctrl+\Replace
Ctrl+_Go to line
Ctrl+GHelp

Key Takeaways

  • nano shows shortcuts at the bottom (^ = Ctrl)
  • Ctrl+O saves, Ctrl+X exits
  • Ctrl+K cuts, Ctrl+U pastes
  • Ctrl+W searches
  • Perfect for quick edits when you need something simple
  • Available on almost every Linux system

Next: introduction to vim - the powerful (and intimidating) editor.