Linux online course

Nano Text Editor for Linux

Learn how to use Nano on Linux: launch the editor, understand its screen layout, save files, search text, use shortcuts, and enable mouse support.

Nano is a simple, interactive text editor used from Unix and Linux terminals. It lets you create and edit plain-text files without leaving the command line. Nano is especially approachable for beginners because it uses direct keyboard commands rather than the modal workflow found in editors such as Vim.

A terminal is a text-based interface for running commands and programs. When you run nano in a terminal, Nano opens an editing screen containing a document, prompts, and shortcut hints.

Nano can open an existing file or create a new file. It is useful for notes, scripts, configuration files, and other text-based documents. Before editing important system files, make sure you understand the file's purpose and have a backup when appropriate.

Nano and Pico

Nano was created as a free-software-compatible replacement, or clone, of the Pico editor. Pico is a historical terminal text editor whose interface and shortcut style influenced Nano. Users familiar with Pico will recognize many of Nano's commands.

The licensing distinction is important: Nano is distributed under the GNU General Public License (GPL), a free software license. Pico's historical licensing situation helped motivate the development of a compatible editor that could be distributed under the GPL.

Starting Nano

Open a terminal and run Nano without a filename to start with an empty editing buffer:

nano

A buffer is the in-memory text currently being edited. The buffer is not necessarily saved to disk until you use Nano's write-out command.

To open an existing file, or begin a new file with a chosen name, provide the filename as an argument:

nano filename.txt

The argument can be a relative or absolute path:

nano /path/to/file

If the named file exists, Nano loads it. If it does not exist, Nano starts a new buffer using that name and can create the file when you save.

Starting Nano with mouse support

Use the -m option to enable Nano's mouse support when launching a file:

nano -m filename.txt

With mouse support enabled, clicking can usually position the cursor, and text selection may be available depending on the Nano version and terminal. Continue to use keyboard shortcuts for reliable saving and exiting. The terminal emulator, remote connection, and system settings can affect how mouse input behaves.

Nano's screen layout

Nano's interface is organized into four main areas. The exact appearance can vary slightly with the terminal size, Nano version, and configuration.

Interface areaLocationWhat it displays or does
Title barTop of the displayShows the Nano version and the current filename.
Editing areaLarge central regionDisplays the document text and accepts typed changes.
Status barNear the bottomDisplays messages and prompts, such as a save filename, search term, or error.
Shortcut/help linesBottom linesShow commonly used Nano commands and their key bindings.

Reading Nano's shortcut notation

Nano commonly uses caret notation for Ctrl-key commands. A caret means the Ctrl key, so ^X means Ctrl+X and ^O means Ctrl+O.

M- commonly represents the Meta key. In many terminals, Meta is mapped to Alt. On some terminals, pressing Esc followed by the key produces the Meta form. For example, a displayed M-W often means Alt+W.

The shortcut lines are a quick reference, not merely decoration. When Nano asks for input, the status bar changes into a prompt. Read that prompt and the available options before pressing another key.

Essential editing workflow

Enter and modify text

  1. Start Nano with nano or with a file path.
  2. Type text directly in the editing area. Nano is a non-modal editor, so you normally do not need to switch between a command mode and an insertion mode.
  3. Use the arrow keys to move through characters and lines.
  4. Use Backspace or Delete to remove text, and type replacement text at the cursor.
  5. Use the available navigation commands to move through longer documents.

Common navigation keys include the arrow keys, Home, End, Page Up, and Page Down. Many Nano versions also support Ctrl+A for the beginning of a line, Ctrl+E for the end of a line, Ctrl+Y to move up one screen, and Ctrl+V to move down one screen. Bindings can vary slightly by version or configuration, so check ^G when uncertain.

Save without exiting

Nano calls saving write out. Writing out stores the current buffer in a file but leaves Nano open:

  1. Press Ctrl+O, shown as ^O.
  2. Read the filename prompt in the status bar.
  3. Accept the displayed filename with Enter, or edit it before pressing Enter.
  4. Wait for Nano's confirmation message that the file was written.

Saving and exiting are separate actions. You can write out the file, continue editing, and write it out again before leaving.

Exit Nano

Press Ctrl+X, shown as ^X, to exit. If the buffer has not changed since the last save, Nano exits immediately. If there are unsaved changes, Nano asks whether to save them. Choose the save option to write the changes, the discard option to leave without saving, or cancel to remain in the editor. The exact letters or wording may differ slightly by Nano version.

Common Nano keyboard shortcuts

ShortcutCommandPurpose
^GHelpOpens Nano's help screen, including more commands and explanations.
^XExitLeaves Nano and prompts about unsaved changes when necessary.
^OWrite out / saveSaves the current buffer to the displayed or supplied filename.
^WSearchOpens the search prompt for finding text in the current buffer.
^KCut textRemoves the current line or selected text and stores it in Nano's cut buffer.
^UUncut / paste textInserts text previously removed with the cut command.
^RRead a fileReads another file into the current buffer at the cursor position.
^\Search and replaceFinds text and prompts for replacement text.
^CCurrent cursor positionDisplays information such as the current line and column.

Key bindings can vary slightly by Nano version, terminal configuration, or customization. If the bottom shortcut lines do not show a command you need, press Ctrl+G for the full help screen.

Searching within a file

  1. Open a file in Nano.
  2. Press Ctrl+W to open the search command.
  3. Enter the search phrase at the prompt in the status bar.
  4. Press Enter to search. Nano moves the cursor to a matching occurrence when one is found.
  5. Use the search command again to continue looking for another occurrence. In many versions, repeating the search prompt and accepting the existing term continues to the next match.

If Nano does not find expected text, check the spelling, capitalization, spaces, and punctuation. Retry with the exact text from the document and review the search options shown by your installed version.

Search and replace

For a basic replacement operation, press Ctrl+\. Nano asks for the text to find, then the replacement text, using the status bar for each prompt. Review each match carefully before confirming replacement, especially in configuration files or source code.

Practical example: create a new text file

  1. Open a terminal.
  2. Start Nano with a new filename:
nano notes.txt
  1. Type several lines in the editing area, for example a task list or short note.
  2. Press Ctrl+O to write out the buffer.
  3. Confirm notes.txt as the filename by pressing Enter.
  4. After Nano reports that the file was written, press Ctrl+X to exit.

The file is now stored in the directory from which you launched Nano, unless you supplied a different path.

Practical example: modify an existing file

  1. Start Nano with the target path:
nano /path/to/notes.txt
  1. Use the arrow keys, line navigation, or search to reach the line you want to change.
  2. Edit the contents directly in the editing area.
  3. Press Ctrl+O and confirm the existing filename.
  4. Check Nano's status message to confirm that the save completed.
  5. Press Ctrl+X to exit.

If the file is a system configuration file, avoid changing unrelated lines. A syntax error can prevent a service or application from working correctly.

Practical example: read another file into the buffer

Place the cursor where the additional content should appear and press Ctrl+R. Enter the path of the file at the status-bar prompt and confirm it. Nano inserts the file's contents into the current buffer; it does not automatically save the combined document. Use Ctrl+O afterward if you want to preserve the result.

Practical example: use mouse support

  1. Launch Nano with mouse support:
nano -m notes.txt
  1. Click in the text to position the cursor.
  2. Use the keyboard to type, search, and edit.
  3. Use Ctrl+O to save and Ctrl+X to exit.

If clicking does not behave as expected, confirm that Nano was started with -m. A terminal emulator may intercept mouse events, and remote sessions can have additional mouse settings.

Troubleshooting Nano

“What do ^X and ^O mean?”

The caret means Ctrl. Therefore, ^X is Ctrl+X, and ^O is Ctrl+O. The bottom shortcut lines use this compact notation to fit several commands on the screen.

Nano asks whether to save when exiting

This normally means the buffer has unsaved modifications. Choose the save option if you want to keep the changes, the discard option if you do not, or cancel the exit operation if you need to continue editing.

Nano cannot save to the requested path

Verify that the filename and directory path are correct. The directory may not exist, or the current user may not have permission to write there. Use a writable location or correct the file permissions when appropriate. Use elevated privileges only when they are justified, and understand that editing as an administrator can create ownership or security problems.

For background on ownership and permissions, see managing file ownership on Linux.

Mouse actions do not work

Start Nano with -m and check the terminal emulator's mouse settings. If you are connected through a remote session, that session may intercept or limit mouse input.

A search finds no expected match

Compare the search phrase with the document exactly. Differences in case, spelling, spacing, or punctuation can prevent a match. Search again with a shorter distinctive phrase, then inspect the available options in the help screen for your Nano version.

Exam-relevant notes

  • Nano is a terminal-based text editor for Unix-like systems.
  • Nano can open existing files and create new files when given a filename.
  • Pico influenced Nano's interface and shortcut conventions.
  • Nano is distributed under the GNU General Public License.
  • The title bar is at the top; the editing area occupies the center; the status bar is near the bottom; and shortcut/help lines are at the bottom.
  • ^ means Ctrl in Nano's shortcut display, while M- commonly means Meta or Alt.
  • Ctrl+O writes out or saves the buffer; Ctrl+X exits.
  • Ctrl+W starts a search, and the search term is entered at the status-bar prompt.
  • Saving a file and exiting Nano are separate operations.

For related command-line skills, review Linux fundamentals, the Linux file structure, and Bash.