nano is a command-line text editor, simple and fast. It is already installed on Debian and Ubuntu, but missing from a minimal AlmaLinux 10 installation. It lets you edit a file with no configuration and no steep learning curve: the shortcuts are shown on screen, and you can use it straight away. It is a good tool for a quick edit, locally or remotely over SSH.
Note: for more complex tasks or intensive development environments, learning vi or
vimcan prove more powerful and productive in the long run thanks to its advanced features.
What you will learn
- Open, edit and save a file with nano
- Use the essential keyboard shortcuts (copy, paste, search)
- Customise nano through the
~/.nanorcfile - Avoid mistakes when editing system files
How do you open, create, save and exit a file?
One of the great strengths of nano is its simplicity: you can open, create, edit and save a file in a few keystrokes, without knowing any complex commands.
Edit or create a file
To start nano, simply type the command followed by the file name in your terminal:
nano file_name.txt- If the file already exists, it opens in the editor.
- If the file does not exist, nano opens an empty buffer, that is, a
text held in memory under that name. Nothing is written to disk until you
write it out (
Ctrl + O): exiting without saving creates no file.
Tip: use the
Tabkey to complete the file name.
Save a file
When your changes are done, press:
Ctrl + ONano asks you to confirm the file name to write. Press
Enter to confirm.
A message appears at the bottom of the screen to confirm that the file was saved.
Exit nano
To leave the editor, use:
Ctrl + XThree cases can occur:
- If no change was made: nano exits straight away.
- If changes were made: nano asks whether you want to save.
- Type
Y(Yes) to save, thenEnter - Type
N(No) to exit without saving - Type
Ctrl + Cto cancel and go back to editing
- Type
Reminder: every shortcut is shown at the bottom of the screen while you use nano, so there is no need to learn them all by heart!
Which keyboard shortcuts should you know?
One of the great strengths of nano is that everything is done from the keyboard, with shortcuts that are easy to remember. What is more, the main shortcuts are shown at the bottom of the screen, which makes it easy to find your way, even for a beginner.
Here are the most useful shortcuts to feel at ease in nano day to day:
Basic navigation
These shortcuts save you from hammering the arrow keys on a file of several
hundred lines. The most rewarding one day to day is Ctrl + _: when
systemctl or a compiler reports an error "line 148", you jump straight to it
instead of scrolling. Note that Ctrl + Y and Ctrl + V move by a whole
screen, not by a line: the size of the jump therefore depends on the height
of your terminal.
| Action | Shortcut |
|---|---|
| Start of line | Ctrl + A |
| End of line | Ctrl + E |
| Go to a specific line | Ctrl + _ then the number |
| Previous page | Ctrl + Y |
| Next page | Ctrl + V |
| Move character by character | Arrow keys |
Editing text
The right-hand column uses the notation nano itself shows. Two traps to
remember: Ctrl + K cuts the whole line (it goes into the internal
clipboard, called the cutbuffer), and Ctrl + U pastes that cutbuffer,
not your graphical system's clipboard. Chaining several Ctrl + K
accumulates lines in the cutbuffer, which lets you move a block in one go.
Undo is Alt + U, and it can be repeated.
| Action | Shortcut |
|---|---|
| Save the file | Ctrl + O |
| Exit nano | Ctrl + X |
| Cut the current line | Ctrl + K |
| Copy the line/selection | Alt + 6 |
| Paste | Ctrl + U |
| Justify a paragraph | Ctrl + J |
| Undo the last operation | Alt + U |
| Redo | Alt + E |
Search and replace
Nano's search works through a prompt: Ctrl + W opens an input line at
the bottom, Enter confirms, and Alt + W repeats the same search forwards
without retyping the pattern. To go back up the file, use Ctrl + Q, which
searches upwards. Watch out for replacement with Ctrl + \: nano asks
for the text to find, then the replacement text, then confirms each
occurrence one by one; answering A (All) applies the replacement
everywhere at once, with no way back other than Alt + U.
| Action | Shortcut |
|---|---|
| Search for a word (forwards) | Ctrl + W |
| Search backwards | Ctrl + Q |
| Next / previous match | Alt + W / Alt + Q |
| Search and replace | Ctrl + \ |
Other handy shortcuts
These toggles change the display or the behaviour for the current
session only; nothing is written to the file or to your configuration.
Tell the two kinds of wrapping apart: Alt + S enables soft wrapping,
which folds the display without touching the contents, whereas Alt + L
enables hard wrapping, which inserts real line breaks into the file. On a
configuration file, Alt + S is the one you want.
| Action | Shortcut |
|---|---|
| Toggle soft wrapping | Alt + S |
| Toggle hard wrapping | Alt + L |
| Toggle line numbers | Alt + N |
| Toggle auto-indentation | Alt + I |
| Open the built-in help | Ctrl + G |
| Run a function or an external command | Ctrl + T |
Tip:
Altis often writtenM-in nano's help (M = Meta). Example:M-U=Alt + U.
Advice: practise step by step
There is no point in learning everything at once. Start with:
Ctrl + O(save)Ctrl + X(exit)Ctrl + W(search)Ctrl + K / U(cut / paste)
Then add the others as you need them.
How do you configure and customise nano?
nano is a minimalist editor by default, but it can be widely customised to make it more comfortable. Whether on the command line or through a dedicated configuration file, nano adapts easily to your preferences.
Customising on the command line
Nano accepts several options at launch, which change its behaviour temporarily for a given session:
nano --linenumbers --softwrap my_file.txt| Option | Description |
|---|---|
--linenumbers (-l) | Shows line numbers in the left margin |
--softwrap (-S) | Visually folds lines that are too long |
--mouse (-m) | Allows using the mouse to move around |
--ignorercfiles (-I) | Ignores the .nanorc configuration files |
--view (-v) | Opens read-only, writing is blocked |
These options are very useful for one-off use, without changing the global configuration.
Configuration file: ~/.nanorc
To customise nano permanently, you can create or edit the ~/.nanorc
file. It lets you define your personal preferences, which are loaded every
time nano starts.
Example configuration
Each line of the file takes the form set <option>, where <option> has the
same name as the long command-line option, without the two dashes. An
unknown option name is not silently ignored: nano shows
[ Mistakes in '/home/you/.nanorc' ] at startup, which gives an immediate
signal in case of a typo. Here is a sound base for editing system
configuration files:
set linenumbersset softwrapset tabsize 4set autoindentset mouse| Directive | Effect |
|---|---|
set linenumbers | Shows line numbers |
set softwrap | Wraps long lines automatically |
set tabsize 4 | Sets the tab size to 4 spaces |
set autoindent | Keeps the indentation from one line to the next |
set mouse | Enables the mouse (click to move the cursor) |
To apply the changes, save the
.nanorcfile and restart nano.
Loading global .nanorc files
Some systems have a global configuration file, usually located in
/etc/nanorc. It lets system administrators define a default configuration
for every user. You can read this file for inspiration.
Good practices
A ~/.nanorc that is too loaded backfires the day you have to troubleshoot a
server: your reflexes no longer work, because the remote machine does not have
your configuration. So keep a portable base and memorise the keyboard
toggles (Alt + N, Alt + S) to get the same comfort everywhere, without
depending on a missing file.
- Keep a backup copy of your
.nanorcin case of conflict. - Test your changes on a temporary file before generalising them.
- Avoid overloading your configuration: stick to the essentials to keep the editor fast and clear.
Troubleshooting
A block with nano almost never comes from the editor itself: it comes from the
permissions on the file or on its parent directory. The typical case is a
system file opened without sudo. Read the status bar first, at the bottom
of the screen: nano usually writes the reason for the refusal there, when you
open the file or when you save it. The table below starts from that message and
works back to the cause.
| Symptom | Likely cause | Fix |
|---|---|---|
A File '...' is unwritable message on opening, or Error writing ...: Permission denied on saving, on a system file (/etc/hosts) | You opened a file owned by root without sudo | Exit with Ctrl + X then N, and reopen with sudo nano /etc/hosts (or sudoedit /etc/hosts) |
Ctrl + O does nothing | The file is open read-only (-v): nano blocks writing | Read the status bar message, then relaunch with nano file without -v, or with sudo for a system file |
Nano shows [ Directory '...' is not writable ] on opening (a message only issued when --locking is enabled), or Error writing ...: Permission denied when creating a new file | Your account cannot write to the file's parent directory | Check with ls -ld /path/to/folder/, then relaunch with sudo nano or sudoedit. Do not change the permissions of a system directory with chmod to get around the refusal |
| Pasted text is indented like a staircase | Auto-indentation applies to pasted lines, on a terminal without bracketed paste | Disable indentation during the paste with Alt + I, then enable it again |
| Impossible to exit nano | The file was changed and nano is waiting for a confirmation | Press Ctrl + X, then N to exit without saving |
| Syntax highlighting does not work | The highlighting .nanorc files are not loaded | Add include "/usr/share/nano/*.nanorc" to ~/.nanorc |
sudo nano or sudoedit?
Two commands fit to edit a system file. The command sudo nano /etc/hosts
runs the whole of nano with root rights. The command sudoedit /etc/hosts
works differently: it copies the file to a temporary file, opens that copy with
your own account, then rewrites the original as administrator when you exit.
The editor therefore never has root rights, which limits the damage of a
wrong move.
The editor opened by sudoedit is the one named by the SUDO_EDITOR, VISUAL
or EDITOR variables, or else the one that the sudo configuration names (the
editor option of sudoers). To be sure to get nano, type
SUDO_EDITOR=nano sudoedit /etc/hosts. In both cases, never make a system
directory writable by everyone to avoid sudo.
Where does nano come from?
The nano editor was born out of a simple need: to offer a free,
easy to use and more intuitive alternative to complex editors such as
vi or emacs, while respecting the standards of free software.
Nano was first born in 1999 under the name TIP (TIP Isn't Pico), a
play on words to say that it was not pico, but very similar.
picowas the text editor included in the Pine mail client, developed at the University of Washington.- The problem: pico was not free and could not be redistributed freely, which was an issue in the open source world.
To work around this problem, Chris Allegretta decided to create a free
editor, under the GPL licence, offering the same simplicity as pico,
with improvements.
The project was then renamed nano in 2000, to respect a UNIX rule:
avoid two programs having the same name (tip already existed).
Today, nano is actively maintained by the GNU community and keeps receiving regular updates.
Key points
- nano is installed by default on Debian 13 (
importantpriority) and on Ubuntu (standardpriority on Ubuntu 24.04 and Ubuntu 26.04), but not on a minimal AlmaLinux 10, whosecoregroup only bringsvim-minimal: install it withsudo dnf install nano, or troubleshoot with vi, the only editor guaranteed everywhere. - The essential shortcuts are
Ctrl + O(save),Ctrl + X(exit),Ctrl + W(search) andCtrl + K/Ctrl + U(cut/paste). - The
~/.nanorcfile customises nano permanently (line numbers, indentation, tab size). - For a system file, open it with
sudo nano /path/fileorsudoedit /path/file. Never change the permissions of a system directory withchmodto avoidsudo. - nano is ideal for quick changes; for intensive development, move on to vi or vim.
Knowledge check
Check that the essentials of this guide stuck. The questions cover only what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Vi on Linux: modes, essential commands and how to exit
A new full quiz with random questions
Work again only on the questions you missed