nano: command not found

Vim is a powerful text editor and knowing how to use it is an important thing for any system administrator. Nevertheless, there are other text editors that are equally powerful and even easier to use.

This is the case with nano, which is installed by default in Ubuntu and CentOS and can be used right out of the box on both. The default editor is not set up in the .bashrc file by using the $EDITOR variable. However, in Ubuntu, you can check the default editor on your system by using the following command:

$ sudo update-alternatives --config editor

You can invoke the nano editor by using the nano command on both Ubuntu and CentOS. When you type the command, the nano editor will open, with a very straightforward interface.

If you encounter the below error:

nano: command not found

You may try installing the nano package as per your choice of distribution.

Distribution Command
OS X brew install nano
Debian apt-get install nano
Ubuntu apt-get install nano
Alpine apk add nano
Arch Linux pacman -S nano
Kali Linux apt-get install nano
CentOS yum install nano
Fedora dnf install nano
Raspbian apt-get install nano

nano Command Examples

1. Open a new file in nano:

# nano

2. Open a specific file:

# nano path/to/file

3. Open a specific file, positioning the cursor at the specified line and column:

# nano +line,column path/to/file

4. Open a specific file and enable soft wrapping:

# nano --softwrap path/to/file

5. Open a specific file and indent new lines to the previous lines’ indentation:

# nano --autoindent path/to/file

6. Open nano and create a backup file (`file~`) when saving edits:

# nano --backup path/to/file

nano Shortcuts

In GNU nano, the functions you use to work with text files and the editor itself are referred to as shortcuts. You activate most shortcuts by pressing the Ctrl key (represented as ^ in the editor) and then pressing the key that corresponds to the function you’re trying to perform.

The below table lists some of the common nano shortcuts.

Shortcut Used to
Ctrl+G Open nano to help screen
Ctrl+X Exit nano or close currrent buffer
Ctrl+O Save currently open file
Ctrl+J Justify current paragraph
Ctrl+R Insert another file into the current one
Ctrl+W Search the file
Ctrl+K Cut the currently selected line
Ctrl+U Paste the line that was cut
Ctrl+C Dsiplay the cursor positions

Navigation

Like other text editors, you can navigate in nano using the arrow keys, Page Up, Page Down, Home, etc. If you are missing these keys, nano also provides shortcuts for them, e.g., Ctrl+V to navigate to the next page and Ctrl+Y to navigate to the previous page.

Copying Text

Copying parts of the text on a line requires you to “mark” the text you want to copy with the Ctrl+^ shortcut. You then navigate your cursor to highlight the text you want to copy. Pressing Alt+^ copies the marked/highlighted text, and Ctrl+U pastes it.

Related Post