Introduction / Why This Is Useful
nano is a simple and convenient command-line text editor for Linux, ideal for beginners. Unlike vi or vim, nano does not require learning complex modes: all commands are displayed at the bottom of the screen, and control is handled using Ctrl key combinations. With this guide, you'll quickly learn how to create, edit, and save text files, as well as perform basic operations—all without unnecessary complexity.
Requirements / Preparation
Before you begin, ensure that:
- You have access to a Linux terminal (Ubuntu, Debian, CentOS, Fedora, and other distributions).
- nano is usually pre-installed on most distributions. If it's missing, install it:
sudo apt install nano # For Debian/Ubuntu sudo yum install nano # For CentOS/RHEL sudo dnf install nano # For Fedora - You have read/write permissions for the files you plan to edit. For system files,
sudomay be required.
Step 1: Launching nano
Open the terminal and run one of the following commands:
nano— creates a new unnamed buffer.nano filename— opens an existing file or creates a new one if it doesn't exist.
Example:
nano notes.txt
If notes.txt does not exist, it will be created in the current directory.
Step 2: The nano Interface
After launching, you will see:
- Menu bar (at the top) — shows available commands (e.g.,
^G Get Help). - Workspace — the main area for editing text.
- Shortcut bar (at the bottom) — displays frequently used key combinations. The symbol
^represents the Ctrl key.
💡 Tip: Press
Ctrl+Gat any time to open the help with a full list of commands.
Step 3: Navigating the File
Move the cursor using:
- Arrow keys (
←→↑↓) — character by character. Ctrl+Home/Ctrl+End— to the beginning or end of the file.Ctrl+PageUp/Ctrl+PageDown— up or down one screen.Ctrl+_(Ctrl+Shift+-) — jump to a specific line (enter the line number).
To quickly search for text, use Ctrl+W (see the FAQ).
Step 4: Editing Text
nano operates in a single mode: just start typing to insert text at the cursor position.
Basic operations:
- Delete a character:
BackspaceorDel. - Select text:
Ctrl+6(set mark), then move the cursor. Selected text can be cut (Ctrl+K) or copied (Alt+6). - Cut an entire line:
Ctrl+K(press once to cut the current line, press again to cut the next line). - Paste:
Ctrl+U(pastes the last cut fragment). - Undo action:
Alt+U(undo the last change).
⚠️ Important: If you accidentally select text and press a key, the selected fragment will be replaced by the typed character. Use
Ctrl+Uto undo.
Step 5: Saving the File
After editing, save your changes:
- Press
Ctrl+O(the letter O, not zero). - A filename prompt appears at the bottom. If the name was already specified when opening, simply press Enter. To save under a different name, enter it and press Enter.
- nano confirms the save with the message
Wrote X bytes.
Example of saving a new file:
^O
Write File: newfile.txt
(Press Enter after entering the name).
Step 6: Exiting nano
To close the editor:
- Press
Ctrl+X. - If there are unsaved changes, nano will ask:
Save modified buffer? (Y)es, (N)o, (C)ancel:Y— save (then specify the filename if needed).N— exit without saving.C— cancel exit and return to editing.
Verifying the Result
- After saving, check the file contents with the command:
cat filename - Ensure your changes are reflected.
- To check permissions (if you edited a system file), run:
ls -l /path/to/file
Common Issues
Issue 1: "Permission denied" when saving
Symptom: When trying to save a file in a protected directory (e.g., /etc), nano returns an access error.
Solution: Launch nano with sudo:
sudo nano /etc/fstab
⚠️ Important: Be careful when editing system files. Mistakes can disrupt system operation.
Issue 2: No syntax highlighting
Symptom: Code or configs are displayed without color highlighting. Solution:
- Launch nano with a language specification:
nano -Y python script.py. - Or enable highlighting globally by adding to
~/.nanorc:
(The path may differ; check for files ininclude "/usr/share/nano/*.nanorc"/usr/share/nano/).
Issue 3: Can't exit nano (freeze)
Symptom: Nothing happens after pressing Ctrl+X.
Solution: Ensure you are pressing Ctrl+X (not just X). If the interface is unresponsive, try Ctrl+C to force exit (without saving).
Issue 4: Accidental text deletion
Symptom: Text disappears after pressing a key.
Solution: Use Alt+U to undo. If undo doesn't work, the text may have been cut (Ctrl+K). Paste it back with Ctrl+U. To prevent this, always check if text is selected (it appears inverted).
Issue 5: Long lines are truncated
Symptom: Text is cut off at the edge of the screen instead of wrapping.
Solution: Enable soft wraps by adding to ~/.nanorc:
set softwrap
Or launch with the flag: nano -w file.