How to Use Nano, the Linux Command Line Text Editor

When working on the command line, quite often you will need to create or edit text files. Two of the most powerful and popular command-line editors are Vim and Emacs. Both have a steep learning curve that can be intimidating to new users. For those who need a simple editor, there is nano.
GNU nano is an easy-to-use command line text editor for Unix and Linux operating systems. It includes all the basic functionality you expect from a regular text editor, like syntax highlighting, multiple buffers, search and replace with regular expression support, spellchecking, UTF-8 encoding, and more.
This guide explains the basic usage of the nano editor, including how to create and open a file, edit a file, save a file, search and replace text, cut and paste text, and more.
Quick Reference
For a printable quick reference, see the Nano cheatsheet .
| Task | Shortcut / Command |
|---|---|
| Open file | nano filename |
| Save file | Ctrl+s |
| Write out or save as | Ctrl+o |
| Exit nano | Ctrl+x |
| Search text | Ctrl+w (or Ctrl+f on nano 8.0+) |
| Search next match | Alt+w (or Alt+f on nano 8.0+) |
| Replace text | Ctrl+\ |
| Select text | Alt+a |
| Copy selected text | Alt+6 |
| Cut current line | Ctrl+k |
| Paste text | Ctrl+u |
| Show help | Ctrl+g |
| Go to line/column | Ctrl+_ |
| Toggle line numbers | Alt+n |
Installing Nano
GNU nano is installed by default on many Linux distributions. To check whether it is available on your system, type:
nano --versionThe output will look something like this:
GNU nano, version 8.7.1
(C) 2026 the Free Software Foundation and various contributors
Compiled options: --disable-libmagic --enable-utf8The first line shows the installed version. Ubuntu 26.04 ships nano 8.7.1, while Ubuntu 24.04 and Debian 12 ship nano 7.2.
If you do not have nano installed on your system, you can install it using your distribution’s package manager.
Install Nano on Ubuntu, Debian, and Derivatives
sudo apt install nanoInstall Nano on Fedora, RHEL, and Derivatives
sudo dnf install nanoOpening and Creating Files
The general syntax for starting nano is:
nano [OPTIONS] [FILE]To open an existing file or to create a new file, type nano followed by the file name:
nano filename
This opens a new editor window, and you can start editing the file.
At the bottom of the window, there is a list of the most basic command shortcuts to use with the nano editor.
All commands are prefixed with either ^ or M characters. The caret symbol (^) represents the Ctrl key. For example, the ^J command means to press the Ctrl and J keys at the same time. The letter M represents the Meta key, which is Alt on most keyboards. If an Alt shortcut does not work in your terminal, press and release Esc, then press the key.
You can get a list of all commands by typing Ctrl+g.
To open a file, you must have read permissions to the file.
If you want to open a file with the cursor on a specific line and character, use the following syntax:
nano +line_number,character_number filenameFor example, nano +20 filename opens the file at line 20, and nano +20,5 filename opens at line 20, column 5. If you omit the column number, the cursor will be positioned on the first character.
Editing System Files with sudo nano
To edit files that require root permissions, such as system configuration files, prefix the command with sudo:
sudo nano /etc/hostsYou will be prompted for your password. Nano will open the file with elevated privileges, allowing you to make changes.
Editing Files
Unlike vi, nano is a modeless editor, which means that you can start typing and editing the text immediately after opening the file.
To move the cursor to a specific line and character number, use the Ctrl+_ command. The menu at the bottom of the screen will change. Enter the number(s) in the “Enter line number, column number:” field and hit Enter.
Displaying Line Numbers
To show line numbers, start nano with the -l (or --linenumbers) option:
nano -l filenameYou can toggle line numbers on and off while editing by pressing Alt+n. To turn them on permanently, add set linenumbers to your nano configuration file.
Searching and Replacing
To search for text, press Ctrl+w, type the search term, and press Enter. The cursor will move to the first match. To move to the next match, press Alt+w.
Nano 8.0 and newer also bind Ctrl+f to a forward search and Ctrl+b to a backward search. In these versions, Alt+f and Alt+b jump to the next and previous match. On nano 7.2 and older, Ctrl+f moves the cursor one character to the right. Ctrl+w and Alt+w work in every version.
If you want to search and replace, press Ctrl+\. Enter the search term and the text to be replaced with. The editor will move to the first match and ask you whether to replace it. After hitting Y or N, it will move to the next match. Pressing A will replace all matches.
Copying, Cutting, and Pasting
To select text, move the cursor to the beginning of the text and press Alt+a. This will set a selection mark. Move the cursor to the end of the text you want to select using the arrow keys. The selected text will be highlighted. Ctrl+6 also toggles the mark. You can use it to start a selection or to cancel one.
Copy the selected text using the Alt+6 command (nano also accepts Alt+^). Ctrl+k will cut the selected text.
Nano keeps copied and cut text in its own cut buffer, not in the system clipboard. To copy text into another application, select it with the mouse and use your terminal’s copy shortcut.
If you want to cut whole lines, move the cursor to the line and press Ctrl+k. You can cut multiple lines by hitting Ctrl+k several times.
To paste the text, move the cursor to where you want to put the text and press Ctrl+u.
Saving and Exiting
To save the changes you have made to the file, press Ctrl+s. You can also press Ctrl+o to open the Write Out prompt, then press Enter to save with the same file name. If the file does not exist, it will be created once you save it.
To exit nano
, press Ctrl+x. If there are unsaved changes, you will be asked whether you want to save the changes.
To save the file, you must have write permissions to the file. If you are creating a new file , you need to have write permission to the directory where the file is created.
Customizing Nano (nanorc)
When nano is launched, it reads its configuration parameters from the system-wide configuration file /etc/nanorc. It then reads the first user-specific file it finds: ~/.nanorc, $XDG_CONFIG_HOME/nano/nanorc, or ~/.config/nano/nanorc.
Options specified in the user files take precedence over the global options.
Visit the nanorc page for a complete list of all available options.
Syntax Highlighting
Nano ships with syntax highlighting rules for most popular file types. On most Linux systems, the syntax files are stored in the /usr/share/nano directory and included by default in the /etc/nanorc configuration file.
include "/usr/share/nano/*.nanorc"Files in /usr/share/nano belong to the nano package and are replaced on upgrades. To enable highlighting for a new file type, save the file containing the syntax highlighting rules in your own directory, such as ~/.nano/, and include it from your user configuration file:
include "~/.nano/*.nanorc"Set Nano as the Default Text Editor
On Ubuntu and Debian, the system-wide editor alternative normally points to nano. Commands such as visudo can use this default. However, crontab -e
chooses an editor through sensible-editor, which checks environment variables such as VISUAL and EDITOR and your saved select-editor choice before the system-wide alternative.
Fedora also ships nano as its default editor. On RHEL, its derivatives, and many other distributions, these commands fall back to vi.
To use nano as the default text editor, you need to change the VISUAL and EDITOR environment variables
.
Bash users can export the variables in the ~/.bashrc file:
export VISUAL=nano
export EDITOR="$VISUAL"On Ubuntu and Debian, you can also change the system-wide default editor:
sudo update-alternatives --config editorThe command lists the installed editors. Type the selection number next to nano and press Enter.
Troubleshooting
nano: command not found
Install nano with your package manager, then run nano --version to confirm it is available.
Cannot save file due to permission denied
Open the file with the correct permissions or use sudo when editing system files.
Ctrl+f moves the cursor instead of searching
You are running nano 7.2 or older. In these versions, Ctrl+f moves the cursor one character to the right. Use Ctrl+w to search and Alt+w to jump to the next match.
Alt shortcuts do not work
Some terminals, including macOS Terminal and iTerm2 with default settings, do not send the Option key as Meta. Press Esc and then the key instead, for example Esc followed by 6 to copy. In macOS Terminal, you can also turn on “Use Option as Meta key” in the profile’s Keyboard settings.
FAQ
Is nano easier than Vim?
For most new users, yes. Nano is modeless, so you can start typing immediately without switching modes.
Conclusion
You now know how to create, edit, search, and save files with nano, set it as your default editor, and customize its behavior through nanorc. For more options, see the official nano documentation , or keep the Nano cheatsheet nearby as a quick reference.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page