How to Use Nano Editor in Linux: Simple Guide
Use the
nano command followed by a filename to open or create a file in the nano text editor. Inside nano, type your text, then press Ctrl + O to save and Ctrl + X to exit.Syntax
The basic syntax to open or create a file with nano is:
nano filename: Opens the file namedfilenameor creates it if it doesn't exist.Ctrl + O: Saves the current file.Ctrl + X: Exits nano.Ctrl + K: Cuts the current line.Ctrl + U: Pastes the cut line.
bash
nano filename
Example
This example shows how to create a file named example.txt, write text, save it, and exit nano.
bash
nano example.txt
Output
The nano editor opens with a blank screen or the contents of example.txt if it exists.
Common Pitfalls
Beginners often forget to save changes before exiting, losing their work. Remember to press Ctrl + O to save, then Enter to confirm the filename, before pressing Ctrl + X to exit.
Another mistake is typing nano without a filename, which opens a blank buffer that won't save unless you specify a filename when saving.
bash
Wrong way: nano # Type text and press Ctrl + X without saving Right way: nano myfile.txt # Type text, press Ctrl + O, Enter to save, then Ctrl + X to exit
Quick Reference
| Shortcut | Action |
|---|---|
| Ctrl + O | Save the current file |
| Ctrl + X | Exit nano |
| Ctrl + K | Cut the current line |
| Ctrl + U | Paste the cut line |
| Ctrl + W | Search text |
| Ctrl + G | Show help |
Key Takeaways
Use
nano filename to open or create a file in nano.Press
Ctrl + O to save your work before exiting.Exit nano safely with
Ctrl + X after saving.Remember common shortcuts like
Ctrl + K to cut and Ctrl + U to paste lines.Always confirm the filename when saving to avoid losing data.