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 area | Location | What it displays or does |
|---|---|---|
| Title bar | Top of the display | Shows the Nano version and the current filename. |
| Editing area | Large central region | Displays the document text and accepts typed changes. |
| Status bar | Near the bottom | Displays messages and prompts, such as a save filename, search term, or error. |
| Shortcut/help lines | Bottom lines | Show 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
- Start Nano with
nanoor with a file path. - 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.
- Use the arrow keys to move through characters and lines.
- Use
BackspaceorDeleteto remove text, and type replacement text at the cursor. - 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:
- Press
Ctrl+O, shown as^O. - Read the filename prompt in the status bar.
- Accept the displayed filename with
Enter, or edit it before pressingEnter. - 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
| Shortcut | Command | Purpose |
|---|---|---|
^G | Help | Opens Nano's help screen, including more commands and explanations. |
^X | Exit | Leaves Nano and prompts about unsaved changes when necessary. |
^O | Write out / save | Saves the current buffer to the displayed or supplied filename. |
^W | Search | Opens the search prompt for finding text in the current buffer. |
^K | Cut text | Removes the current line or selected text and stores it in Nano's cut buffer. |
^U | Uncut / paste text | Inserts text previously removed with the cut command. |
^R | Read a file | Reads another file into the current buffer at the cursor position. |
^\ | Search and replace | Finds text and prompts for replacement text. |
^C | Current cursor position | Displays 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
- Open a file in Nano.
- Press
Ctrl+Wto open the search command. - Enter the search phrase at the prompt in the status bar.
- Press
Enterto search. Nano moves the cursor to a matching occurrence when one is found. - 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
- Open a terminal.
- Start Nano with a new filename:
nano notes.txt
- Type several lines in the editing area, for example a task list or short note.
- Press
Ctrl+Oto write out the buffer. - Confirm
notes.txtas the filename by pressingEnter. - After Nano reports that the file was written, press
Ctrl+Xto 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
- Start Nano with the target path:
nano /path/to/notes.txt
- Use the arrow keys, line navigation, or search to reach the line you want to change.
- Edit the contents directly in the editing area.
- Press
Ctrl+Oand confirm the existing filename. - Check Nano's status message to confirm that the save completed.
- Press
Ctrl+Xto 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
- Launch Nano with mouse support:
nano -m notes.txt
- Click in the text to position the cursor.
- Use the keyboard to type, search, and edit.
- Use
Ctrl+Oto save andCtrl+Xto 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, whileM-commonly means Meta or Alt.Ctrl+Owrites out or saves the buffer;Ctrl+Xexits.Ctrl+Wstarts 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.