While learning Linux, we will often need to edit text files, for instance to modify configuration files, write notes, or create scripts. Although graphical editors like GNOME Text Editor are available, there are times when we must work directly in the terminal and require a lightweight, simple editor. nano is the answer. Built into Ubuntu 26.04 LTS and Fedora Workstation 44, it is easy to learn and displays a list of keyboard shortcuts at the bottom of the screen so we do not have to memorize them beforehand. This chapter will guide us in mastering nano as our first text editor in the terminal.
One thing to know from the start: starting with version 8.0 (released May 1, 2024), nano changed several of its default shortcuts to be more beginner-friendly, and the versions bundled with Ubuntu 26.04 LTS and Fedora Workstation 44 already use this new scheme. If the display at the bottom of your installed nano screen differs slightly from what is written in this chapter, run nano --version to check its version. Trust the shortcut list displayed on your screen, as it is the most accurate reference for your current installation.
19.1 Why Do We Need a Text Editor in the Terminal?
When managing a Linux system, many tasks must be performed directly in the terminal, such as repairing broken configurations, editing system files, or writing simple scripts. In these situations, switching to a graphical application can be inconvenient, especially when a Sysadmin is managing a server with no graphical interface at all. A terminal text editor allows us to edit files without leaving the terminal environment.
Among many terminal text editors, nano is the most beginner-friendly choice. Unlike vim, which has a steep learning curve, nano can be used immediately without needing to understand special modes or commands. All essential shortcuts are always displayed at the bottom of the screen, so we always know which keys to press. Developers who need to quickly edit scripts on a remote server over SSH often rely on nano because it comes preinstalled without requiring additional setup.
19.2 Opening and Creating Files with nano
To open a file with nano, run the nano command followed by the filename. If the file already exists, its content will be displayed. If it does not exist, nano will create a new file with that name.
nano notes.txtThe command above opens nano with the file notes.txt. If the file does not exist yet, it will be created when saved. To edit system files that require administrative privileges, such as when a Sysadmin modifies the local hostname configuration, prepend sudo to the command.
sudo nano /etc/hostsWhen nano opens, the screen is divided into two main areas. The upper section displays the file content, while the bottom two lines display keyboard shortcuts and status messages. In this interface, the symbol ^ represents the Ctrl key, and the symbol M- represents the Alt key.
If we already know the exact line number we want to target, there is no need to open the file and scroll manually. Add the line number preceded by a plus sign before the filename, or use a colon after the filename.
nano +45 notes.txt
nano notes.txt:45Both commands above open notes.txt with the cursor placed directly on line 45. This is extremely helpful when following up on error messages that specify a line number, such as output from journalctl or a linter. The filename:line syntax was introduced in nano 8.0; in older versions, only the nano +45 notes.txt format is available.
19.3 Navigation and Text Editing
We can move the cursor using the arrow keys on the keyboard. For faster navigation, use the Page Up and Page Down keys to jump one screen at a time, and Home and End to jump to the beginning or end of a line.
Typing characters will insert them directly at the cursor position. To delete characters, use Backspace for the character to the left of the cursor and Delete for the character to the right. To cut an entire line, press Ctrl+K, and paste it back using Ctrl+U. Ctrl+U can also be pressed repeatedly to duplicate the cut line.
If we only want to copy a line without deleting it from its original location, use Alt+6. The line will be stored in the same cutbuffer and can be pasted using Ctrl+U as usual. To select multiple lines before cutting or copying, press Alt+A to enable mark mode, move the cursor to expand the selection, and then press Ctrl+K (cut) or Alt+6 (copy).
19.4 Saving and Exiting
To save changes, press Ctrl+O. nano will prompt for the filename to write to. If we want to keep the same name, simply press Enter. To exit nano, press Ctrl+X. If there are unsaved changes, nano will ask whether to save them first. Press Y to save, N to discard changes, or Ctrl+C to cancel and resume editing.
While saving, we can also change the destination path or filename by modifying the displayed text before pressing Enter.
To verify that the file was successfully saved, exit nano and run cat notes.txt or ls -l notes.txt. The content and timestamp will reflect the recent changes. If nano displays an error such as Error writing notes.txt: Permission denied when saving, the file requires administrative privileges. Exit with Ctrl+X, then reopen the file using sudo nano.
In addition to Ctrl+O, Ctrl+S is available to save instantly without asking for filename confirmation. This shortcut is useful when we want to save progress quickly without exiting edit mode. Note that on some older terminal emulators or SSH sessions, Ctrl+S might be intercepted by the terminal as a "stop output" signal (XOFF), making the screen appear frozen. If this happens, press Ctrl+Q to resume.
19.5 Searching and Replacing Text
To search for a word or phrase within the file, press Ctrl+F, type the search term, and press Enter. The cursor will jump to the first occurrence. To move to the next occurrence in the search direction, press Alt+F. To search backward, use Ctrl+B, and continue backward with Alt+B.
It is worth noting that the legacy search shortcut Ctrl+W (and Alt+W for the next occurrence) used in older nano versions still functions as an alternative, but since version 8.0, the on-screen help menu prioritizes Ctrl+F/Ctrl+B as the primary shortcuts. Do not be confused if older tutorials mention Ctrl+W for searching. Both are valid because nano retains retro bindings for backwards compatibility.
To replace text, press Alt+R (the legacy shortcut Ctrl+\ also works). You will be prompted to enter the target text, followed by the replacement text. nano will then offer options for each match: Y to replace the current match, A to replace all matches at once, N to skip the match, and Ctrl+C to cancel.
If you mark a region of text with Alt+A before starting a search-and-replace operation, the action will apply only to the selected text. This is useful when modifying a specific block without affecting the rest of the file.
19.6 Essential nano Shortcuts
Below is a summary of the most frequently used nano shortcuts based on the default help screen in Ubuntu 26.04 LTS and Fedora Workstation 44. All ^ combinations are pressed with the Ctrl key, and Alt+ combinations are pressed with the Alt key.
| Shortcut | Function |
|---|---|
Ctrl+O | Save file (prompts for filename before writing) |
Ctrl+S | Quick save without filename confirmation |
Ctrl+X | Exit nano |
Ctrl+F | Search forward (legacy shortcut: Ctrl+W) |
Ctrl+B | Search backward |
Alt+F / Alt+B | Find next / previous occurrence |
Alt+R | Replace text (legacy shortcut: Ctrl+\) |
Ctrl+K | Cut current line (or marked region) |
Alt+6 | Copy line without cutting |
Ctrl+U | Paste cut or copied text |
Alt+A | Mark start of text selection |
Ctrl+A | Move to beginning of line |
Ctrl+E | Move to end of line |
Ctrl+C | Display current cursor position |
Ctrl+G | Open nano help menu |
Alt+U | Undo last action |
Alt+E | Redo last undone action |
For users accustomed to GUI editors who prefer key bindings like Ctrl+C to copy or Ctrl+V to paste, nano provides the --modernbindings option (or short flag nano -/), which remaps most shortcuts to modern application standards. This option is entirely optional, but helpful to know.
nano is a simple yet powerful tool. The ability to edit files directly from the terminal will be essential throughout upcoming chapters, from modifying system configurations to writing scripts. Mastering these basic shortcuts opens the door to deeper Linux system administration. Once comfortable with nano, you can explore more advanced editors like vim in the next chapter.

