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.txtWhen 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:
nanoType 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 --helpUse 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 area | Location | Purpose | Typical information or interaction |
|---|---|---|---|
| Title bar | Top of the window | Shows editor context | Nano version, current filename, and sometimes a modified-file indicator |
| Editing area | Center of the window | Where document text is entered and changed | Characters, lines, cursor position, and selected text |
| Status bar | Near the bottom | Displays messages and requests input | Save confirmations, error messages, search terms, filenames, and replacement text |
| Shortcut/help lines | Bottom of the window | Shows frequently used commands | Labels 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,^Omeans 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.
| Task | Shortcut shown by Nano | Meaning | Notes |
|---|---|---|---|
| Open help | ^G | Display built-in help | Press a key such as Page Down to browse, then use the displayed exit command |
| Save/write out | ^O | Write the current buffer to a file | Confirm or change the filename at the status-bar prompt |
| Exit | ^X | Leave Nano | If content changed, Nano asks whether to save |
| Search | ^W | Search for text | Enter the search term in the status bar |
| Search again | M-W | Repeat the previous search | Some versions or terminals may display a different label |
| Replace | ^\ | Search for text and replace it | Respond to the search and replacement prompts |
| Cut text | ^K | Cut the current line or selected text | Cut content goes into Nano's cut buffer |
| Paste/uncut text | ^U | Paste content from the cut buffer | Often called uncut in Nano's help |
| Set mark | ^6 or M-A | Begin or end a selection | Move the cursor after setting the mark to select text |
| Go to line | ^_ or M-G | Jump to a line and column | Enter the requested line and, when prompted, the column |
| Undo | M-U | Reverse an edit | Available in modern Nano versions |
| Redo | M-E | Restore an undone edit | Available in modern Nano versions |
Core file operations
Save the current document
- Press
Ctrl+O, shown as^O. - Read the filename in the status-bar prompt.
- Press Enter to accept it, or edit the name and path before pressing Enter.
- 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.txtNano 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:
- Move the cursor to the beginning of the text.
- Set a mark with
Ctrl+6or the Meta shortcut shown by your version. - Move the cursor with the arrow keys. The text between the mark and cursor becomes selected.
- Use
Ctrl+Kto cut the selection, or use Nano's copy shortcut, commonlyAlt+6(M-6). - Move to the destination and press
Ctrl+Uto 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
- Press
Ctrl+W. - Type the search term into the status-bar prompt.
- Press Enter to search.
- 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
- Press the replace shortcut, commonly
Ctrl+\. - Enter the text to find at the status-bar prompt and press Enter.
- Enter the replacement text and press Enter.
- 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- Type several lines of notes in the editing area.
- Press
Ctrl+Oto save. - Confirm
meeting-notes.txtat the filename prompt by pressing Enter. - Check the save confirmation in the status bar.
- Press
Ctrl+Xto exit.
Edit a configuration-style file
nano app.conf- Check the filename in the title bar.
- Press
Ctrl+Wand search for the setting name, such asport. - Change the setting without altering unrelated lines.
- Press
Ctrl+O, confirm the exact path, and save. - Press
Ctrl+Xto exit.
Replace repeated text
nano document.txt- Press
Ctrl+\. - Enter the repeated wording at the search prompt.
- Enter the new wording at the replacement prompt.
- Review each match and approve or skip replacements as appropriate.
- Save only after reviewing the result.
Select and paste a block
- Move to the start of a line or block and set a mark.
- Move the cursor to the end of the content to select it.
- Copy with the copy shortcut, commonly
Alt+6, or cut withCtrl+K. - Move to the new location.
- Press
Ctrl+Uto paste the cut buffer.
Mouse support
Launch Nano with mouse support enabled:
nano -m filename.txtWhen 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.confBefore 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 nanoFor a concise list of launch options, use:
nano --helpTroubleshooting 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
| Command | Purpose | When to use it |
|---|---|---|
nano filename.txt | Open or create a file | When you know the file path |
nano | Start without a filename | When you will choose the name during saving |
nano -m filename.txt | Enable mouse support | When the terminal supports Nano mouse interaction |
sudo nano /etc/example.conf | Edit a protected system file | Only when administrative access is necessary and the change is intentional |
nano --help | Display command documentation | To view supported launch options |
man nano | Open the manual page | To read full, version-specific documentation |
For more on this editor, continue with the Nano text editor guide.