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.txtnano 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
| Keys | What it does |
|---|---|
| Ctrl + O | Save ("write Out"). Press Enter to confirm the file name |
| Ctrl + X | Exit. If there are unsaved changes, nano asks: press Y to save, N to discard |
| Ctrl + W | Search ("Where is"). In the browser labs press F6 instead: Ctrl+W would close the browser tab |
| Ctrl + K | Cut the current line |
| Ctrl + U | Paste the cut line |
| Ctrl + G | Help |
| Alt + U | Undo |
A complete edit, step by step
- Type
nano todo.txtand 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.