• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

nano: command not found

by admin

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.

Basic vim commands (cheat sheet)
Basic vi commands (cheat sheet)

Filed Under: Linux

Some more articles you might also be interested in …

  1. flatpak-builder Command Examples in Linux
  2. fsck Command Examples in Linux
  3. conntrack Command Examples in Linux
  4. backlight_control Command Examples in Linux
  5. localectl Command Examples in Linux
  6. cut Command Examples in Linux
  7. “map in use” error while removing multipath device in CentOS/RHEL
  8. Linux OS Service ‘kudzu’
  9. xargs Command Examples in Linux
  10. who: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright