Linux Command Line Syntax: The nano Command

Linux Command Line Syntax: The nano Command
Page content

History

Nano was created in 1999 by Chris Allegretta to be a GPL-released replacement for the non-GPL’d Pico text editor. Nano is a keyboard-centric text editor where all functions are controlled by keys and key combinations. This makes Nano an incredibly efficient editor. Instead of having to reach back for your mouse, your fingers take care of all commands on the keyboard.

Basic Usage

The Nano editor works from the command line (you’ll need a terminal emulator such as aterm, eterm, gnome-terminal, or konsole). You start Nano with the command nano. When Nano is open you will have a nearly empty screen, save for a listing of some of the keyboard commands listed at the bottom.

Nano screenshot

Keyboard Controls

When using the Nano editor, the Ctrl key is your friend. As you can see, in the screenshot above, there are a few of the main commands listed at the bottom. Each of those command letters is preceded by the “^” character which is the Ctrl key. So if you see “^X” that means Ctrl-X together. The other character to remember is the “M” character which represents the Esc key. If you see the combination Md that actually means Esc-d together.The most useful commands for Nano are:

^x - Close Nano (You will be prompted to save.)

^o - Save without quitting

^c - Line number

^k - Cut

^u - Paste

^t - Spellcheck

^c - Cancel

Md - Word count

Mi - Insert a tab at the cursor position

Starting a new file and opening a file

There are a few ways to deal with a file in Nano. Say you know the name and location of a text file to edit (we’ll use fstab as an example.) To open /etc/fstab with nano you would enter the command nano /etc/fstab and the file would open. If you already have Nano open to a blank file you can hit the ^r combination which will prompt you for the file to read into the current buffer. The “read into” ability of Nano is very helpful for appending at the end of a file. If you have multiple text files that you want to combine into one larger file you can open up the first, read the second into the end of the first, and then read the third at the end of the second.

When you open a new (blank) file you can start it by either typing in nano and then, when you close, you can give the file a name. Or you can issue the nano command with the new file name and then when you close and save the file, the name will already be chosen.

Final Thoughts

Although not quite as powerful as the “big two” (emacs and vi), Nano is an amazingly simple editor to use. Once you start using Nano to edit text and configuration files, you will most likely never use another editor again.

This post is part of the series: Linux Command Line

If you ever plan on doing any administration on a Linux machine, you would be well served to get to know the command line interface. In this Bright Hub series you will be introduced to various concepts surrounding one of the most powerful admin tools around.

  1. Linux Command Line: Introduction
  2. Linux Command Line: ls
  3. Linux Command Line: cd
  4. Linux Command Line: mkdir
  5. Linux Command Line: df
  6. Linux Command Line: ln
  7. Linux Command Line: top
  8. Linux Command Line: mount/umount
  9. Linux Command Line: Cron/Crontab
  10. Linux Command Line: chmod
  11. Linux Command Line: wget
  12. Linux Command Line: cat
  13. Linux Command Line: grep
  14. Linux Command Line: dd
  15. Linux Command Line: sudo
  16. Linux Command Line: startx
  17. Linux Command Line: adduser
  18. Linux Command Line: at
  19. Linux Command Line: aterm
  20. Linux Command Line: nano
  21. Linux Command Line: hostname