LinuxLow

How to Use nano: Basics of the Text Editor for Linux

This guide will help you master basic operations in nano: opening, editing, saving files, and navigation. Perfect for beginner Linux users.

Updated at February 16, 2026
15-30 min
Easy
FixPedia Team
Применимо к:Linux (Ubuntu, Debian, CentOS, Fedora, etc.)

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:

  1. You have access to a Linux terminal (Ubuntu, Debian, CentOS, Fedora, and other distributions).
  2. 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
    
  3. You have read/write permissions for the files you plan to edit. For system files, sudo may 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:

  1. Menu bar (at the top) — shows available commands (e.g., ^G Get Help).
  2. Workspace — the main area for editing text.
  3. Shortcut bar (at the bottom) — displays frequently used key combinations. The symbol ^ represents the Ctrl key.

💡 Tip: Press Ctrl+G at 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: Backspace or Del.
  • 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+U to undo.

Step 5: Saving the File

After editing, save your changes:

  1. Press Ctrl+O (the letter O, not zero).
  2. 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.
  3. 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:

  1. Press Ctrl+X.
  2. 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

  1. After saving, check the file contents with the command:
    cat filename
    
  2. Ensure your changes are reflected.
  3. 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:
    include "/usr/share/nano/*.nanorc"
    
    (The path may differ; check for files in /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.

F.A.Q.

How do I save a file in nano?
How do I exit nano?
How do I use search in nano?
How do I enable syntax highlighting in nano?

Hints

Launch nano
Familiarize with the interface
Navigate through the file
Edit text
Save changes
Exit the editor
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community