With the Linux command line, one tool will be used more than any other - a text editor. There are quite a few text editors but none as simple to use as Nano. In this entry to the Bright Hub Linux Command Line series you will learn how to use the nano text editor.
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.
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.
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.
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.