Editing Files with nano

nano: a simple editor

To change a file you need a text editor. nano is the easiest one in the terminal. Open a file with it (the file is created if it doesn't exist):

nano todo.txt

nano fills the terminal. You simply type, and move around with the arrow keys. The bottom two lines list the shortcuts. In nano's help, ^ means Ctrl and M- means Alt: ^X is Ctrl+X.

The keys you need

KeysWhat it does
Ctrl + OSave ("write Out"). Press Enter to confirm the file name
Ctrl + XExit. If there are unsaved changes, nano asks: press Y to save, N to discard
Ctrl + WSearch ("Where is"). In the browser labs press F6 instead: Ctrl+W would close the browser tab
Ctrl + KCut the current line
Ctrl + UPaste the cut line
Ctrl + GHelp
Alt + UUndo

A complete edit, step by step

  • Type nano todo.txt and press Enter.
  • Type a few lines, pressing Enter at the end of each.
  • Press Ctrl+O, then Enter, to save.
  • Press Ctrl+X to go back to the prompt.
  • Check the result with cat todo.txt.

Tip: In a hurry? Ctrl+X, then Y, then Enter saves and quits in one go.

Common mistake: Changes aren't saved until you save them. If you quit and answer N, your edits are gone.

Remember: nano file, type, Ctrl+O to save, Ctrl+X to exit.

HOME LEARN COMMUNITY DASHBOARD
Practice terminal Starting…