Linux Commands GuideLinux Desktop GuideLinux System AdministrationLinux Tutorials

Master Nano: Complete Guide to the Linux Command Line Text Editor

Nano is the lightweight, user-friendly command line text editor that many Linux users prefer for quick edits, system administration, and scripting tasks. This comprehensive guide covers everything from installing and launching the Nano editor to advanced customization with nanorc, syntax highlighting, and integrating Nano as your default editor. Whether you are a server administrator managing configuration files on Debian, Ubuntu, RHEL or a developer editing remote files over SSH, learning Nano’s core commands, search/replace, cut/copy/paste, and configuration options will streamline your workflow and reduce errors. Throughout this article you will find practical examples, recommended settings, and troubleshooting tips to become productive with the Nano editor on any Linux distribution.

Why choose Nano (overview)

Nano is modeless, meaning you start typing immediately without switching modes like in Vim. It exposes helpful on-screen shortcuts, supports UTF-8, basic syntax highlighting, regular-expression search and replace, multiple buffers, spell checking (with external programs), and configurable behavior through nanorc files. For admins who need a small learning curve and reliable editor for editing /etc configuration files, Nano strikes an excellent balance between simplicity and power.

Install and verify Nano

Many distributions include Nano by default, but if it is missing you can install it via your package manager. Below are example commands to check the version and install Nano on Debian/Ubuntu and Fedora/RHEL systems. Each example shows typical terminal output so you can verify success.

nano --version

GNU nano, version 8.4 (C) 1999-2011, 2013-2024 Free Software Foundation, Inc.
Email: nano@nano-editor.org Web: https://nano-editor.org/

The –version flag prints the build and version info for Nano so you can confirm it is installed and check which features are supported by that release.

sudo apt install nano

Reading package lists... Done
Building dependency tree... Done
The following NEW packages will be installed:
  nano
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 672 kB of archives.
After this operation, 2,048 kB of additional disk space will be used.

On Debian/Ubuntu the apt install command retrieves and installs Nano. The output shows package selection and disk usage. Use sudo to get elevated privileges when modifying system packages.

sudo dnf install nano

Last metadata expiration check: 0:12:34 ago on Tue 2026-03-03 10:00:00 UTC.
Dependencies resolved.
================================================================================
 Package        Arch          Version              Repository             Size
================================================================================
Installing:
 nano           x86_64        5.9-1.fc34          fedora                 316 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 316 k
Installed size: 1.2 M
Is this ok [y/N]:

On Fedora/RHEL-based systems, dnf install performs a similar role. The example shows the package to install, its size, and prompts to continue.

Open and create files with Nano

Starting Nano is straightforward. You can create a new file or open an existing one. Nano supports opening a file at a specific line (and column) so you can jump directly to the context you need. Below are examples showing listing of Nano syntax files (useful for customization) and examples for opening files at a specified line.

ls /usr/share/nano

ansi.nanorc
python.nanorc
sh.nanorc
html.nanorc
perl.nanorc

Listing the /usr/share/nano directory shows available syntax highlighting files. Many distributions include these rules by default and they are typically included by /etc/nanorc.

nano +20,5 example.conf

[opens example.conf in nano and positions cursor at line 20, column 5]

Using the +LINE,COLUMN syntax opens the file and positions the cursor. Nano is interactive; the terminal will switch to the editor UI. The example output here describes the resulting behavior because interactive editors do not produce stdout output when launched.

Basic editing, navigation, and help

Nano is modeless — you can type immediately after opening a file. The bottom-two lines show the most important keybindings (for saving, exiting, searching, etc.). Use arrow keys or Ctrl-based navigation shortcuts to move faster: Ctrl+A and Ctrl+E move to line start/end, Ctrl+W searches, Ctrl+_ jumps to a specific line, and Ctrl+G opens the help screen. Nano displays the help and full list of commands if you press Ctrl+G.

Search and replace

Nano supports incremental search and an interactive replace operation with optional regular-expression support depending on build. Use search to quickly locate configuration entries and replace to perform single or global substitutions. The Replace workflow prompts for each match, and you can accept, decline, or accept all.

nano --version

GNU nano, version 8.4 (C) 1999-2011, 2013-2024 Free Software Foundation, Inc.

This command is repeated here to remind that features for search/replace depend on the Nano version; newer Nano releases may offer enhanced regex capabilities and smoother replace prompts.

Cut, copy, and paste (marking text)

To select text set a mark at the beginning with Alt+A, move the cursor to expand the selection, then copy with Alt+6 or cut with Ctrl+K. Paste with Ctrl+U. You can cut entire lines quickly with repeated Ctrl+K presses. On some terminals Alt combinations may require Esc as a prefix if the Alt key is intercepted by the terminal emulator.

Saving, writing to protected files, and quitting

Save using Ctrl+O and exit with Ctrl+X. If a file is owned by root or otherwise protected, use sudo to edit it, or use sudoedit which opens the file in your preferred editor with safe privilege escalation. Avoid editing system files as root in a way that might leave incorrect permissions; prefer sudoedit or properly set ownership.

Set Nano as the default editor

To make Nano the default editor for commands like crontab and visudo, set the VISUAL and EDITOR environment variables or use the system alternatives framework. Below is an example of configuring the default via update-alternatives which prints the current selection menu so you can choose Nano.

sudo update-alternatives --config editor

There are 3 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/nano        40        auto mode
  1            /usr/bin/vim.basic   30        manual mode
  2            /usr/bin/nano        40        manual mode
  3            /usr/bin/ed          20        manual mode

Press  to keep the current choice[*], or type selection number:

The –config flag shows interactive choices allowing you to select Nano as the default for the editor alternative. If your distro lacks update-alternatives, set export VISUAL=nano and export EDITOR="$VISUAL" in your shell rc file.

Customize Nano with nanorc and enable syntax highlighting

Nano reads configuration from system-wide /etc/nanorc and user files ~/.config/nano/nanorc and ~/.nanorc. To enable syntax highlighting include the /usr/share/nano/*.nanorc files or copy a single language file into /usr/share/nano. Below is an example snippet you might include in your user nanorc to enable some useful options and line numbers.

cat <<'EOF' > ~/.nanorc

set nowrap
set tabsize 4
set linenumbers
include "/usr/share/nano/*.nanorc"

EOF

The example creates a simple ~/.nanorc file enabling line numbers, setting tab width, disabling hard wrapping, and including the system syntax files. Use your editor or a script to add or tweak these options to match team style guidelines.

Advanced tips for sysadmins

Use Nano for quick edits on remote servers via SSH. If you paste content from your local machine into Nano over SSH, enable softwrap or adjust set tabsize to avoid breaking lines. When editing critical files like sudoers, prefer sudo visudo which validates syntax — configure VISUAL to Nano so visudo opens Nano safely. For automations, avoid using interactive editors in scripts; instead, use sed/awk/ed for unattended changes and reserve Nano for manual corrections.

Troubleshooting common issues

If you see nano: command not found, confirm installation with the version command shown earlier and use your distribution’s package manager to install Nano. If shortcuts don’t behave (Alt combinations), check your terminal emulator keyboard settings or try using the Esc key as a prefix for Alt sequences. If you cannot save due to permission denied, exit and re-open with proper privileges or use sudoedit to preserve ownership and permissions safely.

Conclusion

Nano is a pragmatic, accessible editor ideal for administrators and users who need a fast editor on the command line without the learning curve of modal editors. With a few configuration tweaks in your nanorc file, enabling syntax highlighting, and making Nano the default editor for system commands, you can dramatically improve your daily editing tasks. Keep Nano updated to benefit from new improvements, and pair it with best practices (use sudoedit for privileged files, validate configuration files) to avoid accidental misconfigurations on production systems.

Komentariši

Vaša email adresa neće biti objavljivana. Neophodna polja su označena sa *