VMware ESXi and vSphere Cluster Management

Nano Text Editor on Linux

Learn how to use Nano on Linux: open and save files, navigate, search and replace text, edit safely, use shortcuts, and troubleshoot common problems.

Nano is a simple, interactive command-line text editor for Unix-like systems, including Linux. It runs inside a terminal, the text-based interface used to run commands and programs.

Nano is useful for editing configuration files, shell scripts, notes, documentation, and other plain-text documents. Plain text contains characters without rich formatting such as fonts, colors, or embedded page layout.

Nano was created as a free-software-compatible replacement for Pico, an earlier simple editor. It keeps a similar beginner-friendly style and displays common commands at the bottom of the screen. Nano is distributed under the GNU GPL, a free software license.

Starting Nano

Open or create a named file

Give Nano a path as its argument. If the file exists, Nano opens it. If it does not exist, Nano starts an empty document using that name.

nano filename.txt
nano notes/today.txt

When you save a new document, Nano writes it to the filename you supplied, provided the directory is writable.

Start without a filename

You can start Nano without naming a file:

nano

Type your text, then use the write-out command. Nano will ask for an output filename in the status bar. This is useful when you do not yet know the final name or location.

Command-line options

Options change how Nano behaves. For example, -m enables mouse support:

nano -m filename.txt
nano --help

Use nano --help to see options supported by your installed version. Options and features can vary between Nano releases.

Understanding the Nano screen layout

Nano divides the terminal window into several useful areas.

Screen areaLocationPurposeTypical information or interaction
Title barTop of the windowShows editor contextNano version, current filename, and sometimes a modified-file indicator
Editing areaCenter of the windowWhere document text is entered and changedCharacters, lines, cursor position, and selected text
Status barNear the bottomDisplays messages and requests inputSave confirmations, error messages, search terms, filenames, and replacement text
Shortcut/help linesBottom of the windowShows frequently used commandsLabels such as ^O Write Out, ^W Where Is, and ^X Exit

The title bar is especially important before saving: confirm that it shows the file you intend to change. The status bar becomes an input prompt during actions such as saving, searching, and replacing.

Reading Nano keyboard shortcuts

Nano uses compact notation in its footer and help screen:

  • ^ means the Ctrl key. For example, ^O means hold Ctrl and press O.
  • M- means the Meta key, commonly Alt. Depending on the terminal, Meta may work as Alt plus the key or as Esc followed by the key.
  • Read the shortcut label before pressing keys. The displayed footer is contextual guidance, and the exact labels can differ slightly by Nano version or terminal.
TaskShortcut shown by NanoMeaningNotes
Open help^GDisplay built-in helpPress a key such as Page Down to browse, then use the displayed exit command
Save/write out^OWrite the current buffer to a fileConfirm or change the filename at the status-bar prompt
Exit^XLeave NanoIf content changed, Nano asks whether to save
Search^WSearch for textEnter the search term in the status bar
Search againM-WRepeat the previous searchSome versions or terminals may display a different label
Replace^\Search for text and replace itRespond to the search and replacement prompts
Cut text^KCut the current line or selected textCut content goes into Nano's cut buffer
Paste/uncut text^UPaste content from the cut bufferOften called uncut in Nano's help
Set mark^6 or M-ABegin or end a selectionMove the cursor after setting the mark to select text
Go to line^_ or M-GJump to a line and columnEnter the requested line and, when prompted, the column
UndoM-UReverse an editAvailable in modern Nano versions
RedoM-ERestore an undone editAvailable in modern Nano versions

Core file operations

Save the current document

  1. Press Ctrl+O, shown as ^O.
  2. Read the filename in the status-bar prompt.
  3. Press Enter to accept it, or edit the name and path before pressing Enter.
  4. Look for Nano's confirmation message in the status bar.

The write-out prompt also provides Save As behavior: enter a different filename or path to write the current document somewhere else.

Exit safely

Press Ctrl+X. If you have unsaved changes, Nano asks whether to save, discard, or cancel:

  • Choose save to write the changes, then confirm the filename.
  • Choose discard to exit without saving the changes.
  • Choose cancel to remain in Nano and continue editing.

If you are unsure, cancel the exit prompt, save a copy, or inspect the filename before deciding.

Open another file

The simplest way to open another file is to exit Nano and start it again:

nano another-file.txt

Nano also has a read-file operation, commonly shown as ^R, which inserts the contents of another file into the current document. It does not behave like a separate editor window, so use it carefully.

Editing text

Type normally to insert characters at the cursor. Use Backspace or Delete to remove characters. Enter creates a new line, and the arrow keys move through the document. To remove a whole line, place the cursor on it and press Ctrl+K.

Cut, copy, paste, and uncut

Nano calls its temporary text storage the cut buffer. To select a block:

  1. Move the cursor to the beginning of the text.
  2. Set a mark with Ctrl+6 or the Meta shortcut shown by your version.
  3. Move the cursor with the arrow keys. The text between the mark and cursor becomes selected.
  4. Use Ctrl+K to cut the selection, or use Nano's copy shortcut, commonly Alt+6 (M-6).
  5. Move to the destination and press Ctrl+U to paste, also called uncut.

If no selection is active, Ctrl+K usually cuts the current line. Copying leaves the original text in place.

Undo and redo

Modern Nano versions commonly use Alt+U for undo and Alt+E for redo. If those commands are not available, open Nano's help screen and check the manual for your installed version.

Navigation and search

Move around a document

Use the arrow keys for character-by-character movement. Page Up and Page Down move through larger sections. Home and End move within a line; terminal and Nano versions may also provide shortcuts for the beginning or end of the document.

To jump directly to a location, use the go-to-line command shown in the footer, commonly Ctrl+_. Nano asks for a line number and may then ask for a column number. Enter the values at the status-bar prompts.

Search for text

  1. Press Ctrl+W.
  2. Type the search term into the status-bar prompt.
  3. Press Enter to search.
  4. Nano moves to the next matching text, if one exists.

To repeat the search, use the repeat-search shortcut shown by Nano, commonly Alt+W. Searching may wrap around when Nano reaches the end of the document, depending on the version and settings.

Search and replace

  1. Press the replace shortcut, commonly Ctrl+\.
  2. Enter the text to find at the status-bar prompt and press Enter.
  3. Enter the replacement text and press Enter.
  4. Review each proposed replacement and follow Nano's prompt to replace, skip, or handle the remaining matches.

The status bar is not just a message area: it is where Nano requests search terms, replacement text, filenames, and other responses.

Practical examples

Create a notes file

nano meeting-notes.txt
  1. Type several lines of notes in the editing area.
  2. Press Ctrl+O to save.
  3. Confirm meeting-notes.txt at the filename prompt by pressing Enter.
  4. Check the save confirmation in the status bar.
  5. Press Ctrl+X to exit.

Edit a configuration-style file

nano app.conf
  1. Check the filename in the title bar.
  2. Press Ctrl+W and search for the setting name, such as port.
  3. Change the setting without altering unrelated lines.
  4. Press Ctrl+O, confirm the exact path, and save.
  5. Press Ctrl+X to exit.

Replace repeated text

nano document.txt
  1. Press Ctrl+\.
  2. Enter the repeated wording at the search prompt.
  3. Enter the new wording at the replacement prompt.
  4. Review each match and approve or skip replacements as appropriate.
  5. Save only after reviewing the result.

Select and paste a block

  1. Move to the start of a line or block and set a mark.
  2. Move the cursor to the end of the content to select it.
  3. Copy with the copy shortcut, commonly Alt+6, or cut with Ctrl+K.
  4. Move to the new location.
  5. Press Ctrl+U to paste the cut buffer.

Mouse support

Launch Nano with mouse support enabled:

nano -m filename.txt

When supported by the terminal, mouse interaction can place the cursor, select text, and scroll. Behavior varies by terminal emulator, remote connection, multiplexer, and Nano configuration. If clicks do nothing, use keyboard navigation, which is the most portable method.

Safe editing practices

  • Confirm the filename and path in the title bar before saving.
  • Be cautious with system configuration files: a small syntax error can affect a service or the operating system.
  • Make a backup of important files before modifying them.
  • Use elevated privileges only when administrative access is genuinely required:
sudo nano /etc/example.conf

Before using this command, verify the path and intended change. If the file is not writable, save to a writable location when appropriate rather than using elevated privileges automatically.

Getting help

Press Ctrl+G to open Nano's built-in help screen. The footer provides contextual shortcuts for common actions, while the help screen provides more commands and explanations. For complete command-line options and version-specific features, consult the local manual page:

man nano

For a concise list of launch options, use:

nano --help

Troubleshooting Nano

Nano cannot write the file

Possible causes include a file or directory that is not writable, ownership by another user, a read-only filesystem, or a full filesystem. Check the target path and permissions. Save to a writable filename or directory when possible. If the file is intentionally protected, use administrative access only when the change is deliberate. Check disk space and filesystem state if the problem continues.

A shortcut is difficult to remember

Open the built-in help with Ctrl+G. Remember that ^ means Ctrl and M- commonly means Alt or an Esc-then-key sequence. The terminal may interpret Alt differently, so verify the installed version with man nano.

Mouse clicks do not work

Nano may have been started without mouse mode, or the terminal or remote session may handle mouse input differently. Restart with nano -m filename.txt, check terminal or multiplexer mouse settings if applicable, and use keyboard controls as the fallback.

Changes seem lost after exit

The write-out action may not have been completed, the exit prompt may have been answered with discard, or the document may have been saved under a different name or location. Verify the filename at the save prompt, look for the saved-file confirmation in the status bar, and reopen the expected path.

A shortcut appears to do nothing

Check that you used the modifier shown in the footer. Some commands require a selection, a search term, or another context. Features such as undo and redo also depend on the installed Nano version. Use Ctrl+G or man nano to verify the command.

Quick reference

CommandPurposeWhen to use it
nano filename.txtOpen or create a fileWhen you know the file path
nanoStart without a filenameWhen you will choose the name during saving
nano -m filename.txtEnable mouse supportWhen the terminal supports Nano mouse interaction
sudo nano /etc/example.confEdit a protected system fileOnly when administrative access is necessary and the change is intentional
nano --helpDisplay command documentationTo view supported launch options
man nanoOpen the manual pageTo read full, version-specific documentation

For more on this editor, continue with the Nano text editor guide.